Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

indexer: hotfix ReindexBlocks #1386

Merged
merged 1 commit into from
Sep 10, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading