Commit c3871bb8 authored by manish's avatar manish
Browse files

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: default avatarmanish <manish.sethi@gmail.com>
parent 49783133
......@@ -320,6 +320,7 @@ func (mgr *blockfileMgr) syncIndex() error {
startFileNum := 0
startOffset := 0
blockNum := uint64(1)
skipFirstBlock := false
//get the last file that blocks were added to using the checkpoint info
endFileNum := mgr.cpInfo.latestFileChunkSuffixNum
//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 {
startFileNum = flp.fileSuffixNum
startOffset = flp.locPointer.offset
blockNum = lastBlockIndexed
skipFirstBlock = true
}
//open a blockstream to the file location that was stored in the index
......@@ -341,6 +343,16 @@ func (mgr *blockfileMgr) syncIndex() error {
var blockBytes []byte
var blockPlacementInfo *blockPlacementInfo
if skipFirstBlock {
if blockBytes, _, err = stream.nextBlockBytesAndPlacementInfo(); err != nil {
return err
}
if blockBytes == nil {
return fmt.Errorf("block bytes for block num = [%d] should not be nil here. The indexes for the block are already present",
lastBlockIndexed)
}
}
//Should be at the last block, but go ahead and loop looking for next blockBytes
//If there is another block, add it to the index
for {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment