From 20f06973930dea9eecbd94ef48863af8c297580d Mon Sep 17 00:00:00 2001 From: Senthil Nathan N Date: Tue, 8 Sep 2020 08:24:28 +0530 Subject: [PATCH] reset leveldb batch after the commit While committing data to leveldb in iteration, it is necessary to reset the batch. Otherwise, we would be appending entries and rewriting written entries in the previous iteration. Signed-off-by: Senthil Nathan N --- core/ledger/pvtdatastorage/store.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/ledger/pvtdatastorage/store.go b/core/ledger/pvtdatastorage/store.go index 4bde7bf2aa4..6fde1ac4faa 100644 --- a/core/ledger/pvtdatastorage/store.go +++ b/core/ledger/pvtdatastorage/store.go @@ -777,6 +777,7 @@ func (s *Store) purgeExpiredData(minBlkNum, maxBlkNum uint64) error { batch.Delete(encodeMissingDataKey(missingDataKey)) } s.db.WriteBatch(batch, false) + batch.Reset() } logger.Infof("[%s] - [%d] Entries purged from private data storage till block number [%d]", s.ledgerid, len(expiryEntries), maxBlkNum) return nil @@ -870,7 +871,7 @@ func (s *Store) processCollElgEvents() error { collEntriesConverted++ if batch.Len() > s.maxBatchSize { s.db.WriteBatch(batch, true) - batch = s.db.NewUpdateBatch() + batch.Reset() sleepTime := time.Duration(s.batchesInterval) logger.Infof("Going to sleep for %d milliseconds between batches. Entries for [ns=%s, coll=%s] converted so far = %d", sleepTime, ns, coll, collEntriesConverted)