Skip to content

Commit

Permalink
Address comments from Manish
Browse files Browse the repository at this point in the history
Signed-off-by: Yacov Manevich <yacov.manevich@ibm.com>
  • Loading branch information
yacovm authored and manish-sethi committed Sep 2, 2023
1 parent 45cefb2 commit 8a33e5f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion common/ledger/blkstorage/blockfile_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func newBlockfileMgr(id string, conf *Conf, indexConfig *IndexConfig, indexStore
if err != nil {
panic(fmt.Sprintf("Error creating block storage root dir [%s]: %s", rootDir, err))
}
mgr := &blockfileMgr{rootDir: rootDir, conf: conf, db: indexStore, cache: newCache(defaultMaxBlockfileSize)}
mgr := &blockfileMgr{rootDir: rootDir, conf: conf, db: indexStore, cache: newCache(defaultBlockCacheSizeBytes)}

blockfilesInfo, err := mgr.loadBlkfilesInfo()
if err != nil {
Expand Down
17 changes: 8 additions & 9 deletions common/ledger/blkstorage/blocks_itr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ type blocksItr struct {
stream *blockStream
closeMarker bool
closeMarkerLock *sync.Mutex
cachedPrev bool
}

func newBlockItr(mgr *blockfileMgr, startBlockNum uint64) *blocksItr {
mgr.blkfilesInfoCond.L.Lock()
defer mgr.blkfilesInfoCond.L.Unlock()
return &blocksItr{mgr, mgr.blockfilesInfo.lastPersistedBlock, startBlockNum, nil, false, &sync.Mutex{}, false}
return &blocksItr{mgr, mgr.blockfilesInfo.lastPersistedBlock, startBlockNum, nil, false, &sync.Mutex{}}
}

func (itr *blocksItr) waitForBlock(blockNum uint64) uint64 {
Expand Down Expand Up @@ -72,18 +71,18 @@ func (itr *blocksItr) Next() (ledger.QueryResult, error) {

cachedBlock, existsInCache := itr.mgr.cache.get(itr.blockNumToRetrieve)
if existsInCache {
logger.Debugf("Retrieved block %d from ledger in-memory cache", itr.blockNumToRetrieve)
itr.cachedPrev = true
itr.blockNumToRetrieve++
return cachedBlock, nil
}

if itr.cachedPrev {
itr.cachedPrev = false
// Close the stream if applicable, because since we're fetching from
// the cache, the file stream is no longer in sync with the block number to retrieve.
// Hopefully the next iteration will also be a cache hit.
if itr.stream != nil {
itr.stream.close()
itr.stream = nil
}

logger.Debugf("Retrieved block %d from ledger in-memory cache", itr.blockNumToRetrieve)
itr.blockNumToRetrieve++
return cachedBlock, nil
}

if itr.stream == nil {
Expand Down
3 changes: 2 additions & 1 deletion common/ledger/blkstorage/storage.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a33e5f

Please sign in to comment.