@@ -21,6 +21,7 @@ import (
21
21
"reflect"
22
22
23
23
"github.com/hyperledger/fabric/core/ledger/kvledger/txmgmt"
24
+ logging "github.com/op/go-logging"
24
25
)
25
26
26
27
type kvReadCache struct {
@@ -61,19 +62,42 @@ func (s *LockBasedTxSimulator) GetState(ns string, key string) ([]byte, error) {
61
62
// check if it was written
62
63
kvWrite , ok := nsRWs .writeMap [key ]
63
64
if ok {
64
- logger .Debugf ("Returing value for key=[%s:%s] from write set" , ns , key , kvWrite .Value )
65
+ // trace the first 500 bytes of value only, in case it is huge
66
+ if logger .IsEnabledFor (logging .DEBUG ) {
67
+ if len (kvWrite .Value ) < 500 {
68
+ logger .Debugf ("Returing value for key=[%s:%s] from write set" , ns , key , kvWrite .Value )
69
+ } else {
70
+ logger .Debugf ("Returing value for key=[%s:%s] from write set" , ns , key , kvWrite .Value [0 :500 ])
71
+ }
72
+ }
65
73
return kvWrite .Value , nil
66
74
}
67
75
// check if it was read
68
76
readCache , ok := nsRWs .readMap [key ]
69
77
if ok {
70
- logger .Debugf ("Returing value for key=[%s:%s] from read set" , ns , key , readCache .cachedValue )
78
+ // trace the first 500 bytes of value only, in case it is huge
79
+ if logger .IsEnabledFor (logging .DEBUG ) {
80
+ if len (readCache .cachedValue ) < 500 {
81
+ logger .Debugf ("Returing value for key=[%s:%s] from read set" , ns , key , readCache .cachedValue )
82
+ } else {
83
+ logger .Debugf ("Returing value for key=[%s:%s] from read set" , ns , key , readCache .cachedValue [0 :500 ])
84
+ }
85
+ }
71
86
return readCache .cachedValue , nil
72
87
}
73
88
74
89
// read from storage
75
90
value , version , err := s .txmgr .getCommittedValueAndVersion (ns , key )
76
- logger .Debugf ("Read state from storage key=[%s:%s], value=[%#v], version=[%d]" , ns , key , value , version )
91
+
92
+ // trace the first 500 bytes of value only, in case it is huge
93
+ if logger .IsEnabledFor (logging .DEBUG ) {
94
+ if len (value ) < 500 {
95
+ logger .Debugf ("Read state from storage key=[%s:%s], value=[%#v], version=[%d]" , ns , key , value , version )
96
+ } else {
97
+ logger .Debugf ("Read state from storage key=[%s:%s], value=[%#v...], version=[%d]" , ns , key , value [0 :500 ], version )
98
+ }
99
+ }
100
+
77
101
if err != nil {
78
102
return nil , err
79
103
}
@@ -129,7 +153,17 @@ func (s *LockBasedTxSimulator) getTxReadWriteSet() *txmgmt.TxReadWriteSet {
129
153
nsRWs := & txmgmt.NsReadWriteSet {NameSpace : ns , Reads : reads , Writes : writes }
130
154
txRWSet .NsRWs = append (txRWSet .NsRWs , nsRWs )
131
155
}
132
- logger .Debugf ("txRWSet = [%s]" , txRWSet )
156
+
157
+ // trace the first 2000 characters of RWSet only, in case it is huge
158
+ if logger .IsEnabledFor (logging .DEBUG ) {
159
+ txRWSetString := txRWSet .String ()
160
+ if len (txRWSetString ) < 2000 {
161
+ logger .Debugf ("txRWSet = [%s]" , txRWSetString )
162
+ } else {
163
+ logger .Debugf ("txRWSet = [%s...]" , txRWSetString [0 :2000 ])
164
+ }
165
+ }
166
+
133
167
return txRWSet
134
168
}
135
169
@@ -145,6 +179,7 @@ func getSortedKeys(m interface{}) []string {
145
179
146
180
// GetTxSimulationResults implements method in interface `ledger.TxSimulator`
147
181
func (s * LockBasedTxSimulator ) GetTxSimulationResults () ([]byte , error ) {
182
+ logger .Debugf ("Simulation completed, getting simulation results" )
148
183
return s .getTxReadWriteSet ().Marshal ()
149
184
}
150
185
0 commit comments