Skip to content

Commit

Permalink
Improve debug trace for state database
Browse files Browse the repository at this point in the history
Improvements to debug trace for end to end testing
of state database.

Change-Id: I9d3a491db08c52ee574b38778987d3b2e8d0426d
Signed-off-by: denyeart <enyeart@us.ibm.com>
  • Loading branch information
denyeart committed Nov 8, 2016
1 parent 216ae65 commit e6eb7ef
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 68 deletions.
30 changes: 13 additions & 17 deletions core/ledger/kvledger/txmgmt/couchdbtxmgmt/couchdb_tx_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,25 @@ func (s *CouchDBTxSimulator) GetState(ns string, key string) ([]byte, error) {
// check if it was written
kvWrite, ok := nsRWs.writeMap[key]
if ok {
// trace the first 500 bytes of value only, in case it is huge
// trace the first 200 bytes of value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
if len(kvWrite.Value) < 500 {
if len(kvWrite.Value) < 200 {
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value)
} else {
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:500])
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:200])
}
}
return kvWrite.Value, nil
}
// check if it was read
readCache, ok := nsRWs.readMap[key]
if ok {
// trace the first 500 bytes of value only, in case it is huge
// trace the first 200 bytes of value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
if len(readCache.cachedValue) < 500 {
if len(readCache.cachedValue) < 200 {
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue)
} else {
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:500])
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:200])
}
}
return readCache.cachedValue, nil
Expand All @@ -90,21 +90,17 @@ func (s *CouchDBTxSimulator) GetState(ns string, key string) ([]byte, error) {
// read from storage
value, version, err := s.txmgr.getCommittedValueAndVersion(ns, key)

// trace the first 500 bytes of value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
if len(value) < 500 {
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v], version=[%d]", ns, key, value, version)
} else {
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:500], version)
}
}
if err != nil {
return nil, err
}

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

nsRWs.readMap[key] = &kvReadCache{txmgmt.NewKVRead(key, version), value}
Expand Down
37 changes: 10 additions & 27 deletions core/ledger/kvledger/txmgmt/couchdbtxmgmt/couchdb_txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,16 +197,6 @@ func (txmgr *CouchDBTxMgr) Shutdown() {

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

// trace the first 2000 characters of RWSet only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
txRWSetString := txRWSet.String()
if len(txRWSetString) < 2000 {
logger.Debugf("Validating txRWSet:%s", txRWSetString)
} else {
logger.Debugf("Validating txRWSet:%s...", txRWSetString[0:2000])
}
}

var err error
var currentVersion uint64

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

compositeKey := constructCompositeKey(ns, key)
/* Don't get from RocksDB since we are using CouchDB here
var encodedValue []byte
var err error
if encodedValue, err = txmgr.db.Get(txmgr.stateIndexCF, compositeKey); err != nil {
return nil, 0, err
}
if encodedValue == nil {
return nil, 0, nil
}
value, version := decodeValue(encodedValue)
*/

jsonBytes, _, _ := txmgr.couchDB.ReadDoc(string(compositeKey)) // TODO add error handling
docBytes, _, _ := txmgr.couchDB.ReadDoc(string(compositeKey)) // TODO add error handling

if jsonBytes != nil {
jsonString := string(jsonBytes[:])
logger.Debugf("===COUCHDB=== getCommittedValueAndVersion() Read jsonString:\n %s", jsonString)
// trace the first 200 bytes of value only, in case it is huge
if docBytes != nil && logger.IsEnabledFor(logging.DEBUG) {
if len(docBytes) < 200 {
logger.Debugf("===COUCHDB=== getCommittedValueAndVersion() Read docBytes %s", docBytes)
} else {
logger.Debugf("===COUCHDB=== getCommittedValueAndVersion() Read docBytes %s...", docBytes[0:200])
}
}
value := jsonBytes

var version uint64 = 1 //TODO - version hardcoded to 1 is a temporary value for the prototype
return value, version, nil
return docBytes, version, nil
}

func encodeValue(value []byte, version uint64) []byte {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ func (s *LockBasedTxSimulator) GetState(ns string, key string) ([]byte, error) {
// check if it was written
kvWrite, ok := nsRWs.writeMap[key]
if ok {
// trace the first 500 bytes of value only, in case it is huge
// trace the first 200 bytes of value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
if len(kvWrite.Value) < 500 {
if len(kvWrite.Value) < 200 {
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value)
} else {
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:500])
logger.Debugf("Returing value for key=[%s:%s] from write set", ns, key, kvWrite.Value[0:200])
}
}
return kvWrite.Value, nil
}
// check if it was read
readCache, ok := nsRWs.readMap[key]
if ok {
// trace the first 500 bytes of value only, in case it is huge
// trace the first 200 bytes of value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
if len(readCache.cachedValue) < 500 {
if len(readCache.cachedValue) < 200 {
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue)
} else {
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:500])
logger.Debugf("Returing value for key=[%s:%s] from read set", ns, key, readCache.cachedValue[0:200])
}
}
return readCache.cachedValue, nil
Expand All @@ -89,18 +89,19 @@ func (s *LockBasedTxSimulator) GetState(ns string, key string) ([]byte, error) {
// read from storage
value, version, err := s.txmgr.getCommittedValueAndVersion(ns, key)

// trace the first 500 bytes of value only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
if len(value) < 500 {
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v], version=[%d]", ns, key, value, version)
if err != nil {
return nil, err
}

// trace the first 200 bytes of value only, in case it is huge
if value != nil && logger.IsEnabledFor(logging.DEBUG) {
if len(value) < 200 {
logger.Debugf("===Read state from storage key=[%s:%s], value=[%#v], version=[%d]", ns, key, value, version)
} else {
logger.Debugf("Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:500], version)
logger.Debugf("===Read state from storage key=[%s:%s], value=[%#v...], version=[%d]", ns, key, value[0:200], version)
}
}

if err != nil {
return nil, err
}
nsRWs.readMap[key] = &kvReadCache{txmgmt.NewKVRead(key, version), value}
return value, nil
}
Expand Down
10 changes: 0 additions & 10 deletions core/ledger/kvledger/txmgmt/lockbasedtxmgmt/lockbased_txmgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,6 @@ func (txmgr *LockBasedTxMgr) Shutdown() {

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

// trace the first 2000 characters of RWSet only, in case it is huge
if logger.IsEnabledFor(logging.DEBUG) {
txRWSetString := txRWSet.String()
if len(txRWSetString) < 2000 {
logger.Debugf("Validating txRWSet:%s", txRWSetString)
} else {
logger.Debugf("Validating txRWSet:%s...", txRWSetString[0:2000])
}
}

var err error
var currentVersion uint64

Expand Down

0 comments on commit e6eb7ef

Please sign in to comment.