Commit 8a22a9f1 authored by manish's avatar manish Committed by David Enyeart
Browse files

[FAB-6853] Fix block storage startup messages



This CR fixes some of the messages that the block storgae prints
during startup.

Change-Id: Iaecb2c721c3c49205e4a774947bee0995ddb2e1f
Signed-off-by: default avatarmanish <manish.sethi@gmail.com>
parent decb95f8
...@@ -38,12 +38,12 @@ func constructCheckpointInfoFromBlockFiles(rootDir string) (*checkpointInfo, err ...@@ -38,12 +38,12 @@ func constructCheckpointInfoFromBlockFiles(rootDir string) (*checkpointInfo, err
if lastFileNum == -1 { if lastFileNum == -1 {
cpInfo := &checkpointInfo{0, 0, true, 0} cpInfo := &checkpointInfo{0, 0, true, 0}
logger.Info("No block file found") logger.Debugf("No block file found")
return cpInfo, nil return cpInfo, nil
} }
fileInfo := getFileInfoOrPanic(rootDir, lastFileNum) fileInfo := getFileInfoOrPanic(rootDir, lastFileNum)
logger.Infof("Last Block file info: FileName=[%s], FileSize=[%d]", fileInfo.Name(), fileInfo.Size()) logger.Debugf("Last Block file info: FileName=[%s], FileSize=[%d]", fileInfo.Name(), fileInfo.Size())
if lastBlockBytes, endOffsetLastBlock, numBlocksInFile, err = scanForLastCompleteBlock(rootDir, lastFileNum, 0); err != nil { if lastBlockBytes, endOffsetLastBlock, numBlocksInFile, err = scanForLastCompleteBlock(rootDir, lastFileNum, 0); err != nil {
logger.Errorf("Error while scanning last file [file num=%d]: %s", lastFileNum, err) logger.Errorf("Error while scanning last file [file num=%d]: %s", lastFileNum, err)
return nil, err return nil, err
...@@ -52,7 +52,7 @@ func constructCheckpointInfoFromBlockFiles(rootDir string) (*checkpointInfo, err ...@@ -52,7 +52,7 @@ func constructCheckpointInfoFromBlockFiles(rootDir string) (*checkpointInfo, err
if numBlocksInFile == 0 && lastFileNum > 0 { if numBlocksInFile == 0 && lastFileNum > 0 {
secondLastFileNum := lastFileNum - 1 secondLastFileNum := lastFileNum - 1
fileInfo := getFileInfoOrPanic(rootDir, secondLastFileNum) fileInfo := getFileInfoOrPanic(rootDir, secondLastFileNum)
logger.Infof("Second last Block file info: FileName=[%s], FileSize=[%d]", fileInfo.Name(), fileInfo.Size()) logger.Debugf("Second last Block file info: FileName=[%s], FileSize=[%d]", fileInfo.Name(), fileInfo.Size())
if lastBlockBytes, _, _, err = scanForLastCompleteBlock(rootDir, secondLastFileNum, 0); err != nil { if lastBlockBytes, _, _, err = scanForLastCompleteBlock(rootDir, secondLastFileNum, 0); err != nil {
logger.Errorf("Error while scanning second last file [file num=%d]: %s", secondLastFileNum, err) logger.Errorf("Error while scanning second last file [file num=%d]: %s", secondLastFileNum, err)
return nil, err return nil, err
......
...@@ -115,15 +115,13 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig, ...@@ -115,15 +115,13 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
panic(fmt.Sprintf("Could not get block file info for current block file from db: %s", err)) panic(fmt.Sprintf("Could not get block file info for current block file from db: %s", err))
} }
if cpInfo == nil { if cpInfo == nil {
logger.Info(`No info about blocks file found in the db. logger.Info(`Getting block information from block storage`)
This could happen if this is the first time the ledger is constructed or the index is dropped.
Scanning blocks dir for the latest info`)
if cpInfo, err = constructCheckpointInfoFromBlockFiles(rootDir); err != nil { if cpInfo, err = constructCheckpointInfoFromBlockFiles(rootDir); err != nil {
panic(fmt.Sprintf("Could not build checkpoint info from block files: %s", err)) panic(fmt.Sprintf("Could not build checkpoint info from block files: %s", err))
} }
logger.Infof("Info constructed by scanning the blocks dir = %s", spew.Sdump(cpInfo)) logger.Debugf("Info constructed by scanning the blocks dir = %s", spew.Sdump(cpInfo))
} else { } else {
logger.Info(`Synching the info about block files`) logger.Debug(`Synching block information from block storage (if needed)`)
syncCPInfoFromFS(rootDir, cpInfo) syncCPInfoFromFS(rootDir, cpInfo)
} }
err = mgr.saveCurrentInfo(cpInfo, true) err = mgr.saveCurrentInfo(cpInfo, true)
...@@ -153,18 +151,15 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig, ...@@ -153,18 +151,15 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
// or announcing the occurrence of an event. // or announcing the occurrence of an event.
mgr.cpInfoCond = sync.NewCond(&sync.Mutex{}) mgr.cpInfoCond = sync.NewCond(&sync.Mutex{})
// Verify that the index stored in db is accurate with what is actually stored in block file system
// If not the same, sync the index and the file system
mgr.syncIndex()
// init BlockchainInfo for external API's // init BlockchainInfo for external API's
bcInfo := &common.BlockchainInfo{ bcInfo := &common.BlockchainInfo{
Height: 0, Height: 0,
CurrentBlockHash: nil, CurrentBlockHash: nil,
PreviousBlockHash: nil} PreviousBlockHash: nil}
//If start up is a restart of an existing storage, update BlockchainInfo for external API's
if !cpInfo.isChainEmpty { if !cpInfo.isChainEmpty {
//If start up is a restart of an existing storage, sync the index from block storage and update BlockchainInfo for external API's
mgr.syncIndex()
lastBlockHeader, err := mgr.retrieveBlockHeaderByNumber(cpInfo.lastBlockNumber) lastBlockHeader, err := mgr.retrieveBlockHeaderByNumber(cpInfo.lastBlockNumber)
if err != nil { if err != nil {
panic(fmt.Sprintf("Could not retrieve header of the last block form file: %s", err)) panic(fmt.Sprintf("Could not retrieve header of the last block form file: %s", err))
...@@ -177,7 +172,6 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig, ...@@ -177,7 +172,6 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *blkstorage.IndexConfig,
PreviousBlockHash: previousBlockHash} PreviousBlockHash: previousBlockHash}
} }
mgr.bcInfo.Store(bcInfo) mgr.bcInfo.Store(bcInfo)
//return the new manager (blockfileMgr)
return mgr return mgr
} }
...@@ -346,10 +340,10 @@ func (mgr *blockfileMgr) syncIndex() error { ...@@ -346,10 +340,10 @@ func (mgr *blockfileMgr) syncIndex() error {
//if the index stored in the db has value, update the index information with those values //if the index stored in the db has value, update the index information with those values
if !indexEmpty { if !indexEmpty {
if lastBlockIndexed == mgr.cpInfo.lastBlockNumber { if lastBlockIndexed == mgr.cpInfo.lastBlockNumber {
logger.Infof("Both the block files and indices are in sync.") logger.Debug("Both the block files and indices are in sync.")
return nil return nil
} }
logger.Infof("Last block indexed [%d], Last block present in block files=[%d]", lastBlockIndexed, mgr.cpInfo.lastBlockNumber) logger.Debugf("Last block indexed [%d], Last block present in block files [%d]", lastBlockIndexed, mgr.cpInfo.lastBlockNumber)
var flp *fileLocPointer var flp *fileLocPointer
if flp, err = mgr.index.getBlockLocByBlockNum(lastBlockIndexed); err != nil { if flp, err = mgr.index.getBlockLocByBlockNum(lastBlockIndexed); err != nil {
return err return err
...@@ -359,10 +353,10 @@ func (mgr *blockfileMgr) syncIndex() error { ...@@ -359,10 +353,10 @@ func (mgr *blockfileMgr) syncIndex() error {
skipFirstBlock = true skipFirstBlock = true
startingBlockNum = lastBlockIndexed + 1 startingBlockNum = lastBlockIndexed + 1
} else { } else {
logger.Infof("No block indexed, Last block present in block files=[%d]", mgr.cpInfo.lastBlockNumber) logger.Debugf("No block indexed, Last block present in block files=[%d]", mgr.cpInfo.lastBlockNumber)
} }
logger.Infof("Start building index from block [%d]", startingBlockNum) logger.Infof("Start building index from block [%d] to last block [%d]", startingBlockNum, mgr.cpInfo.lastBlockNumber)
//open a blockstream to the file location that was stored in the index //open a blockstream to the file location that was stored in the index
var stream *blockStream var stream *blockStream
......
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