Skip to content

Commit

Permalink
vochain/indexer: clear votePool in Commit
Browse files Browse the repository at this point in the history
Otherwise the map just keeps increasing in size forever,
meaning that we do more and more busy work over time.
It's surprising that we hadn't caught this bug for a long time.

While here, initialize and clear both "by process ID" maps consistently.
  • Loading branch information
mvdan authored and p4u committed Oct 31, 2023
1 parent 04ac531 commit 125bc51
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions vochain/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ func NewIndexer(dataDir string, app *vochain.BaseApplication, countLiveResults b
App: app,
ignoreLiveResults: !countLiveResults,

votePool: make(map[string]map[string]*state.Vote),
blockUpdateProcs: make(map[string]bool),
}
log.Infow("indexer initialization", "dataDir", dataDir, "liveResults", countLiveResults)
Expand Down Expand Up @@ -405,6 +406,7 @@ func (idx *Indexer) Commit(height uint32) error {
}
}()
}
clear(idx.votePool)

if err := idx.blockTx.Commit(); err != nil {
log.Errorw(err, "could not commit tx")
Expand All @@ -424,14 +426,14 @@ func (idx *Indexer) Commit(height uint32) error {
func (idx *Indexer) Rollback() {
idx.blockMu.Lock()
defer idx.blockMu.Unlock()
idx.votePool = make(map[string]map[string]*state.Vote)
clear(idx.votePool)
clear(idx.blockUpdateProcs)
if idx.blockTx != nil {
if err := idx.blockTx.Rollback(); err != nil {
log.Errorw(err, "could not rollback tx")
}
idx.blockTx = nil
}
clear(idx.blockUpdateProcs)
}

// OnProcess indexer stores the processID
Expand Down

0 comments on commit 125bc51

Please sign in to comment.