Skip to content

Commit c3871bb

Browse files
committed
Index sync up fix: skip first block if already indexed
https://jira.hyperledger.org/browse/FAB-2054 Starting block storage after a crash may kick off indexing the blocks that may have been committed to storage but left out from indexing. The first block can be skipped as this is the block we get reference to from index itself (hence already indexed). Change-Id: Ic96bf581e05e395ab19ec80bfe131071fb6ecc67 Signed-off-by: manish <[email protected]>
1 parent 4978313 commit c3871bb

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

common/ledger/blkstorage/fsblkstorage/blockfile_mgr.go

+12
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ func (mgr *blockfileMgr) syncIndex() error {
320320
startFileNum := 0
321321
startOffset := 0
322322
blockNum := uint64(1)
323+
skipFirstBlock := false
323324
//get the last file that blocks were added to using the checkpoint info
324325
endFileNum := mgr.cpInfo.latestFileChunkSuffixNum
325326
//if the index stored in the db has value, update the index information with those values
@@ -331,6 +332,7 @@ func (mgr *blockfileMgr) syncIndex() error {
331332
startFileNum = flp.fileSuffixNum
332333
startOffset = flp.locPointer.offset
333334
blockNum = lastBlockIndexed
335+
skipFirstBlock = true
334336
}
335337

336338
//open a blockstream to the file location that was stored in the index
@@ -341,6 +343,16 @@ func (mgr *blockfileMgr) syncIndex() error {
341343
var blockBytes []byte
342344
var blockPlacementInfo *blockPlacementInfo
343345

346+
if skipFirstBlock {
347+
if blockBytes, _, err = stream.nextBlockBytesAndPlacementInfo(); err != nil {
348+
return err
349+
}
350+
if blockBytes == nil {
351+
return fmt.Errorf("block bytes for block num = [%d] should not be nil here. The indexes for the block are already present",
352+
lastBlockIndexed)
353+
}
354+
}
355+
344356
//Should be at the last block, but go ahead and loop looking for next blockBytes
345357
//If there is another block, add it to the index
346358
for {

0 commit comments

Comments
 (0)