Skip to content

Commit

Permalink
indexer: hotfix ReindexBlocks
Browse files Browse the repository at this point in the history
 * defer call, to avoid races with startDB init stuff

 * add idx.blockTx.Commit every 10000 blocks and after finishing

 * add some progress log every 10000 blocks
  • Loading branch information
altergui committed Sep 10, 2024
1 parent 7f53ca4 commit ae74b55
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion vochain/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (idx *Indexer) startDB() error {

if gooseMigrationsPending(idx.readWriteDB, "migrations") {
log.Info("indexer db needs migration, scheduling a reindex after sync")
go idx.ReindexBlocks(false)
defer func() { go idx.ReindexBlocks(false) }()
}

if err := goose.Up(idx.readWriteDB, "migrations"); err != nil {
Expand Down Expand Up @@ -459,6 +459,15 @@ func (idx *Indexer) ReindexBlocks(inTest bool) {
// Blocks
func() {
idxBlock, err := idx.readOnlyQuery.GetBlockByHeight(context.TODO(), b.Height)
if height%10000 == 1 {
log.Infof("reindexing height %d, updating values (%s, %x, %x, %x) on current row %+v",
height, b.ChainID, b.Hash(), b.ProposerAddress, b.LastBlockID.Hash, idxBlock)
if err := idx.blockTx.Commit(); err != nil {
log.Errorw(err, "could not commit tx")
}
idx.blockTx = nil
queries = idx.blockTxQueries()
}
if err == nil && idxBlock.Time != b.Time {
log.Errorf("while reindexing blocks, block %d timestamp in db (%s) differs from blockstore (%s), leaving untouched", height, idxBlock.Time, b.Time)
return
Expand Down Expand Up @@ -497,6 +506,11 @@ func (idx *Indexer) ReindexBlocks(inTest bool) {
}
}

if err := idx.blockTx.Commit(); err != nil {
log.Errorw(err, "could not commit tx")
}
idx.blockTx = nil

log.Infow("finished reindexing",
"blockStoreBase", idx.App.Node.BlockStore().Base(),
"blockStoreHeight", idx.App.Node.BlockStore().Height(),
Expand Down

0 comments on commit ae74b55

Please sign in to comment.