Skip to content

Commit e6eb7ef

Browse files
committed
Improve debug trace for state database
Improvements to debug trace for end to end testing of state database. Change-Id: I9d3a491db08c52ee574b38778987d3b2e8d0426d Signed-off-by: denyeart <[email protected]>
1 parent 216ae65 commit e6eb7ef

File tree

4 files changed

+38
-68
lines changed

4 files changed

+38
-68
lines changed

core/ledger/kvledger/txmgmt/couchdbtxmgmt/couchdb_tx_simulator.go

+13-17
Original file line numberDiff line numberDiff line change
@@ -63,25 +63,25 @@ func (s *CouchDBTxSimulator) GetState(ns string, key string) ([]byte, error) {
6363
// check if it was written
6464
kvWrite, ok := nsRWs.writeMap[key]
6565
if ok {
66-
// trace the first 500 bytes of value only, in case it is huge
66+
// trace the first 200 bytes of value only, in case it is huge
6767
if logger.IsEnabledFor(logging.DEBUG) {
68-
if len(kvWrite.Value) < 500 {
68+
if len(kvWrite.Value) < 200 {
6969
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value)
7070
} else {
71-
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:500])
71+
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:200])
7272
}
7373
}
7474
return kvWrite.Value, nil
7575
}
7676
// check if it was read
7777
readCache, ok := nsRWs.readMap[key]
7878
if ok {
79-
// trace the first 500 bytes of value only, in case it is huge
79+
// trace the first 200 bytes of value only, in case it is huge
8080
if logger.IsEnabledFor(logging.DEBUG) {
81-
if len(readCache.cachedValue) < 500 {
81+
if len(readCache.cachedValue) < 200 {
8282
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue)
8383
} else {
84-
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:500])
84+
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:200])
8585
}
8686
}
8787
return readCache.cachedValue, nil
@@ -90,21 +90,17 @@ func (s *CouchDBTxSimulator) GetState(ns string, key string) ([]byte, error) {
9090
// read from storage
9191
value, version, err := s.txmgr.getCommittedValueAndVersion(ns, key)
9292

93-
// trace the first 500 bytes of value only, in case it is huge
94-
if logger.IsEnabledFor(logging.DEBUG) {
95-
if len(value) < 500 {
96-
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v], version=[%d]", ns, key, value, version)
97-
} else {
98-
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:500], version)
99-
}
100-
}
10193
if err != nil {
10294
return nil, err
10395
}
10496

105-
if value != nil {
106-
jsonString := string(value[:])
107-
logger.Debugf("===COUCHDB=== GetState() Read jsonString from storage:\n%s\n", jsonString)
97+
// trace the first 200 bytes of value only, in case it is huge
98+
if value != nil && logger.IsEnabledFor(logging.DEBUG) {
99+
if len(value) < 200 {
100+
logger.Debugf("===Read state from storage key=[%s:%s], value=[%#v], version=[%d]", ns, key, value, version)
101+
} else {
102+
logger.Debugf("===Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:200], version)
103+
}
108104
}
109105

110106
nsRWs.readMap[key] = &kvReadCache{txmgmt.NewKVRead(key, version), value}

core/ledger/kvledger/txmgmt/couchdbtxmgmt/couchdb_txmgr.go

+10-27
Original file line numberDiff line numberDiff line change
@@ -197,16 +197,6 @@ func (txmgr *CouchDBTxMgr) Shutdown() {
197197

198198
func (txmgr *CouchDBTxMgr) validateTx(txRWSet *txmgmt.TxReadWriteSet) (bool, error) {
199199

200-
// trace the first 2000 characters of RWSet only, in case it is huge
201-
if logger.IsEnabledFor(logging.DEBUG) {
202-
txRWSetString := txRWSet.String()
203-
if len(txRWSetString) < 2000 {
204-
logger.Debugf("Validating txRWSet:%s", txRWSetString)
205-
} else {
206-
logger.Debugf("Validating txRWSet:%s...", txRWSetString[0:2000])
207-
}
208-
}
209-
210200
var err error
211201
var currentVersion uint64
212202

@@ -328,27 +318,20 @@ func (txmgr *CouchDBTxMgr) getCommitedVersion(ns string, key string) (uint64, er
328318
func (txmgr *CouchDBTxMgr) getCommittedValueAndVersion(ns string, key string) ([]byte, uint64, error) {
329319

330320
compositeKey := constructCompositeKey(ns, key)
331-
/* Don't get from RocksDB since we are using CouchDB here
332-
var encodedValue []byte
333-
var err error
334-
if encodedValue, err = txmgr.db.Get(txmgr.stateIndexCF, compositeKey); err != nil {
335-
return nil, 0, err
336-
}
337-
if encodedValue == nil {
338-
return nil, 0, nil
339-
}
340-
value, version := decodeValue(encodedValue)
341-
*/
342321

343-
jsonBytes, _, _ := txmgr.couchDB.ReadDoc(string(compositeKey)) // TODO add error handling
322+
docBytes, _, _ := txmgr.couchDB.ReadDoc(string(compositeKey)) // TODO add error handling
344323

345-
if jsonBytes != nil {
346-
jsonString := string(jsonBytes[:])
347-
logger.Debugf("===COUCHDB=== getCommittedValueAndVersion() Read jsonString:\n %s", jsonString)
324+
// trace the first 200 bytes of value only, in case it is huge
325+
if docBytes != nil && logger.IsEnabledFor(logging.DEBUG) {
326+
if len(docBytes) < 200 {
327+
logger.Debugf("===COUCHDB=== getCommittedValueAndVersion() Read docBytes %s", docBytes)
328+
} else {
329+
logger.Debugf("===COUCHDB=== getCommittedValueAndVersion() Read docBytes %s...", docBytes[0:200])
330+
}
348331
}
349-
value := jsonBytes
332+
350333
var version uint64 = 1 //TODO - version hardcoded to 1 is a temporary value for the prototype
351-
return value, version, nil
334+
return docBytes, version, nil
352335
}
353336

354337
func encodeValue(value []byte, version uint64) []byte {

core/ledger/kvledger/txmgmt/lockbasedtxmgmt/lockbased_tx_simulator.go

+15-14
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ func (s *LockBasedTxSimulator) GetState(ns string, key string) ([]byte, error) {
6262
// check if it was written
6363
kvWrite, ok := nsRWs.writeMap[key]
6464
if ok {
65-
// trace the first 500 bytes of value only, in case it is huge
65+
// trace the first 200 bytes of value only, in case it is huge
6666
if logger.IsEnabledFor(logging.DEBUG) {
67-
if len(kvWrite.Value) < 500 {
67+
if len(kvWrite.Value) < 200 {
6868
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value)
6969
} else {
70-
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:500])
70+
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:200])
7171
}
7272
}
7373
return kvWrite.Value, nil
7474
}
7575
// check if it was read
7676
readCache, ok := nsRWs.readMap[key]
7777
if ok {
78-
// trace the first 500 bytes of value only, in case it is huge
78+
// trace the first 200 bytes of value only, in case it is huge
7979
if logger.IsEnabledFor(logging.DEBUG) {
80-
if len(readCache.cachedValue) < 500 {
80+
if len(readCache.cachedValue) < 200 {
8181
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue)
8282
} else {
83-
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:500])
83+
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:200])
8484
}
8585
}
8686
return readCache.cachedValue, nil
@@ -89,18 +89,19 @@ func (s *LockBasedTxSimulator) GetState(ns string, key string) ([]byte, error) {
8989
// read from storage
9090
value, version, err := s.txmgr.getCommittedValueAndVersion(ns, key)
9191

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)
92+
if err != nil {
93+
return nil, err
94+
}
95+
96+
// trace the first 200 bytes of value only, in case it is huge
97+
if value != nil && logger.IsEnabledFor(logging.DEBUG) {
98+
if len(value) < 200 {
99+
logger.Debugf("===Read state from storage key=[%s:%s], value=[%#v], version=[%d]", ns, key, value, version)
96100
} else {
97-
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:500], version)
101+
logger.Debugf("===Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:200], version)
98102
}
99103
}
100104

101-
if err != nil {
102-
return nil, err
103-
}
104105
nsRWs.readMap[key] = &kvReadCache{txmgmt.NewKVRead(key, version), value}
105106
return value, nil
106107
}

core/ledger/kvledger/txmgmt/lockbasedtxmgmt/lockbased_txmgr.go

-10
Original file line numberDiff line numberDiff line change
@@ -165,16 +165,6 @@ func (txmgr *LockBasedTxMgr) Shutdown() {
165165

166166
func (txmgr *LockBasedTxMgr) validateTx(txRWSet *txmgmt.TxReadWriteSet) (bool, error) {
167167

168-
// trace the first 2000 characters of RWSet only, in case it is huge
169-
if logger.IsEnabledFor(logging.DEBUG) {
170-
txRWSetString := txRWSet.String()
171-
if len(txRWSetString) < 2000 {
172-
logger.Debugf("Validating txRWSet:%s", txRWSetString)
173-
} else {
174-
logger.Debugf("Validating txRWSet:%s...", txRWSetString[0:2000])
175-
}
176-
}
177-
178168
var err error
179169
var currentVersion uint64
180170

0 commit comments

Comments
 (0)