Skip to content

Commit 9659a53

Browse files
committed
[FAB-7548] Improve debug for pvt data p2
Improve debug messages for private data. Grepping debug log for "private" will now return very useful information. Change-Id: If4fa0b54e44db1ecf24f857c89c401b6e39b2113 Signed-off-by: David Enyeart <enyeart@us.ibm.com>
1 parent 6af9661 commit 9659a53

File tree

3 files changed

+29
-13
lines changed

3 files changed

+29
-13
lines changed

core/ledger/pvtdatastorage/store_impl.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,15 +84,15 @@ func (s *store) Prepare(blockNum uint64, pvtData []*ledger.TxPvtData) error {
8484
if value, err = encodePvtRwSet(txPvtData.WriteSet); err != nil {
8585
return err
8686
}
87-
logger.Debugf("Adding private data to batch blockNum=%d, tranNum=%d", blockNum, txPvtData.SeqInBlock)
87+
logger.Debugf("Adding private data to LevelDB batch for block [%d], tran [%d]", blockNum, txPvtData.SeqInBlock)
8888
batch.Put(key, value)
8989
}
9090
batch.Put(pendingCommitKey, emptyValue)
9191
if err := s.db.WriteBatch(batch, true); err != nil {
9292
return err
9393
}
9494
s.batchPending = true
95-
logger.Debugf("Saved private data for block [%d]", blockNum)
95+
logger.Debugf("Saved %d private data write sets for block [%d]", len(pvtData), blockNum)
9696
return nil
9797
}
9898

@@ -102,7 +102,7 @@ func (s *store) Commit() error {
102102
return &ErrIllegalCall{"No pending batch to commit"}
103103
}
104104
committingBlockNum := s.nextBlockNum()
105-
logger.Debugf("Committing pvt data for block = %d", committingBlockNum)
105+
logger.Debugf("Committing private data for block [%d]", committingBlockNum)
106106
batch := leveldbhelper.NewUpdateBatch()
107107
batch.Delete(pendingCommitKey)
108108
batch.Put(lastCommittedBlkkey, encodeBlockNum(committingBlockNum))
@@ -112,7 +112,7 @@ func (s *store) Commit() error {
112112
s.batchPending = false
113113
s.isEmpty = false
114114
s.lastCommittedBlock = committingBlockNum
115-
logger.Debugf("Committed pvt data for block = %d", committingBlockNum)
115+
logger.Debugf("Committed private data for block [%d]", committingBlockNum)
116116
return nil
117117
}
118118

@@ -124,7 +124,7 @@ func (s *store) Rollback() error {
124124
return &ErrIllegalCall{"No pending batch to rollback"}
125125
}
126126
rollingbackBlockNum := s.nextBlockNum()
127-
logger.Debugf("Rolling back pvt data for block = %d", rollingbackBlockNum)
127+
logger.Debugf("Rolling back private data for block [%d]", rollingbackBlockNum)
128128

129129
if pendingBatchKeys, err = s.retrievePendingBatchKeys(); err != nil {
130130
return err
@@ -138,15 +138,15 @@ func (s *store) Rollback() error {
138138
return err
139139
}
140140
s.batchPending = false
141-
logger.Debugf("Rolled back pvt data for block = %d", rollingbackBlockNum)
141+
logger.Debugf("Rolled back private data for block [%d]", rollingbackBlockNum)
142142
return nil
143143
}
144144

145145
// GetPvtDataByBlockNum implements the function in the interface `Store`.
146146
// If the store is empty or the last committed block number is smaller then the
147147
// requested block number, an 'ErrOutOfRange' is thrown
148148
func (s *store) GetPvtDataByBlockNum(blockNum uint64, filter ledger.PvtNsCollFilter) ([]*ledger.TxPvtData, error) {
149-
logger.Debugf("GetPvtDataByBlockNum(): blockNum=%d, filter=%#v", blockNum, filter)
149+
logger.Debugf("Get private data for block [%d], filter=%#v", blockNum, filter)
150150
if s.isEmpty {
151151
return nil, &ErrOutOfRange{"The store is empty"}
152152
}
@@ -156,7 +156,7 @@ func (s *store) GetPvtDataByBlockNum(blockNum uint64, filter ledger.PvtNsCollFil
156156
}
157157
var pvtData []*ledger.TxPvtData
158158
startKey, endKey := getKeysForRangeScanByBlockNum(blockNum)
159-
logger.Debugf("GetPvtDataByBlockNum(): startKey=%#v, endKey=%#v", startKey, endKey)
159+
logger.Debugf("Querying private data storage for write sets using startKey=%#v, endKey=%#v", startKey, endKey)
160160
itr := s.db.GetIterator(startKey, endKey)
161161
defer itr.Release()
162162

@@ -167,7 +167,7 @@ func (s *store) GetPvtDataByBlockNum(blockNum uint64, filter ledger.PvtNsCollFil
167167
if pvtWSet, err = decodePvtRwSet(itr.Value()); err != nil {
168168
return nil, err
169169
}
170-
logger.Debugf("Retrieving pvtdata for bNum=%d, tNum=%d", bNum, tNum)
170+
logger.Debugf("Retrieved private data write set for block [%d] tran [%d]", bNum, tNum)
171171
filteredWSet := TrimPvtWSet(pvtWSet, filter)
172172
pvtData = append(pvtData, &ledger.TxPvtData{SeqInBlock: tNum, WriteSet: filteredWSet})
173173
}
@@ -177,7 +177,7 @@ func (s *store) GetPvtDataByBlockNum(blockNum uint64, filter ledger.PvtNsCollFil
177177
// InitLastCommittedBlock implements the function in the interface `Store`
178178
func (s *store) InitLastCommittedBlock(blockNum uint64) error {
179179
if !(s.isEmpty && !s.batchPending) {
180-
return &ErrIllegalCall{"The pvtdata store is not empty. InitLastCommittedBlock() function call is not allowed"}
180+
return &ErrIllegalCall{"The private data store is not empty. InitLastCommittedBlock() function call is not allowed"}
181181
}
182182
batch := leveldbhelper.NewUpdateBatch()
183183
batch.Put(lastCommittedBlkkey, encodeBlockNum(blockNum))
@@ -186,7 +186,7 @@ func (s *store) InitLastCommittedBlock(blockNum uint64) error {
186186
}
187187
s.isEmpty = false
188188
s.lastCommittedBlock = blockNum
189-
logger.Debugf("InitLastCommittedBlock set to = %d", blockNum)
189+
logger.Debugf("InitLastCommittedBlock set to block [%d]", blockNum)
190190
return nil
191191
}
192192

core/transientstore/store.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ import (
1212
"github.com/golang/protobuf/proto"
1313
"github.com/hyperledger/fabric/protos/ledger/rwset"
1414

15+
"github.com/hyperledger/fabric/common/flogging"
1516
"github.com/hyperledger/fabric/common/ledger/util/leveldbhelper"
1617
"github.com/hyperledger/fabric/common/util"
1718
"github.com/hyperledger/fabric/core/ledger"
1819
"github.com/hyperledger/fabric/core/ledger/pvtdatastorage"
1920
"github.com/syndtr/goleveldb/leveldb/iterator"
2021
)
2122

23+
var logger = flogging.MustGetLogger("transientstore")
24+
2225
var emptyValue = []byte{}
2326

2427
// ErrStoreEmpty is used to indicate that there are no entries in transient store
@@ -119,6 +122,9 @@ func (provider *storeProvider) Close() {
119122
// based on txid and the block height the private data was received at
120123
func (s *store) Persist(txid string, blockHeight uint64,
121124
privateSimulationResults *rwset.TxPvtReadWriteSet) error {
125+
126+
logger.Debugf("Persisting private data to transient store for txid = %s", txid)
127+
122128
dbBatch := leveldbhelper.NewUpdateBatch()
123129

124130
// Create compositeKey with appropriate prefix, txid, uuid and blockHeight
@@ -161,6 +167,9 @@ func (s *store) Persist(txid string, blockHeight uint64,
161167
// GetTxPvtRWSetByTxid returns an iterator due to the fact that the txid may have multiple private
162168
// write sets persisted from different endorsers.
163169
func (s *store) GetTxPvtRWSetByTxid(txid string, filter ledger.PvtNsCollFilter) (RWSetScanner, error) {
170+
171+
logger.Debugf("Getting private data from transient store for transaction %s", txid)
172+
164173
// Construct startKey and endKey to do an range query
165174
startKey := createTxidRangeStartKey(txid)
166175
endKey := createTxidRangeEndKey(txid)
@@ -173,6 +182,9 @@ func (s *store) GetTxPvtRWSetByTxid(txid string, filter ledger.PvtNsCollFilter)
173182
// transient store. PurgeByTxids() is expected to be called by coordinator after
174183
// committing a block to ledger.
175184
func (s *store) PurgeByTxids(txids []string) error {
185+
186+
logger.Debug("Purging private data from transient store for committed txids")
187+
176188
dbBatch := leveldbhelper.NewUpdateBatch()
177189

178190
for _, txid := range txids {
@@ -216,6 +228,9 @@ func (s *store) PurgeByTxids(txids []string) error {
216228
// after successful block commit, PurgeByHeight() is still required to remove orphan entries (as
217229
// transaction that gets endorsed may not be submitted by the client for commit)
218230
func (s *store) PurgeByHeight(maxBlockNumToRetain uint64) error {
231+
232+
logger.Debugf("Purging orphaned private data from transient store received prior to block [%d]", maxBlockNumToRetain)
233+
219234
// Do a range query with 0 as startKey and maxBlockNumToRetain-1 as endKey
220235
startKey := createPurgeIndexByHeightRangeStartKey(0)
221236
endKey := createPurgeIndexByHeightRangeEndKey(maxBlockNumToRetain - 1)

gossip/privdata/coordinator.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (c *coordinator) StoreBlock(block *common.Block, privateDataSets util.PvtDa
150150
}
151151
logger.Infof("Received block [%d]", block.Header.Number)
152152

153-
logger.Debug("Validating block", block.Header.Number)
153+
logger.Debugf("Validating block [%d]", block.Header.Number)
154154
err := c.Validator.Validate(block)
155155
if err != nil {
156156
return errors.WithMessage(err, "Validation failed")
@@ -179,6 +179,7 @@ func (c *coordinator) StoreBlock(block *common.Block, privateDataSets util.PvtDa
179179
logger.Debug("No missing collection private write sets to fetch from remote peers")
180180
} else {
181181
bFetchFromPeers = true
182+
logger.Debug("Could not find all collection private write sets in local peer transient store.")
182183
logger.Debug("Fetching", len(privateInfo.missingKeys), "collection private write sets from remote peers for a maximum duration of", retryThresh)
183184
}
184185
start := time.Now()
@@ -200,7 +201,7 @@ func (c *coordinator) StoreBlock(block *common.Block, privateDataSets util.PvtDa
200201
// populate the private RWSets passed to the ledger
201202
for seqInBlock, nsRWS := range ownedRWsets.bySeqsInBlock() {
202203
rwsets := nsRWS.toRWSet()
203-
logger.Debug("Added", len(rwsets.NsPvtRwset), "namespace private write sets to transaction", seqInBlock, "for block", block.Header.Number)
204+
logger.Debugf("Added %d namespace private write sets for block [%d], tran [%d]", len(rwsets.NsPvtRwset), block.Header.Number, seqInBlock)
204205
blockAndPvtData.BlockPvtData[seqInBlock] = &ledger.TxPvtData{
205206
SeqInBlock: seqInBlock,
206207
WriteSet: rwsets,

0 commit comments

Comments
 (0)