Skip to content

Commit

Permalink
tests: fix TestVotersReloadFromDiskAfterOneStateProofCommitted (#6024)
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy authored Jun 11, 2024
1 parent f06a86e commit 88b0ca5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 8 deletions.
32 changes: 25 additions & 7 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2931,14 +2931,31 @@ func testVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T, cfg confi
require.NoError(t, err)
}

triggerDeleteVoters(t, l, genesisInitState)
l.acctsOnline.voters.votersMu.Lock()
vtSnapshot := l.acctsOnline.voters.votersForRoundCache
// wait all pending commits to finish
l.trackers.accountsWriting.Wait()

// verifying that the tree for round 512 is still in the cache, but the tree for round 256 is evicted.
require.Contains(t, vtSnapshot, basics.Round(496))
require.NotContains(t, vtSnapshot, basics.Round(240))
l.acctsOnline.voters.votersMu.Unlock()
// quit the commitSyncer goroutine
l.trackers.ctxCancel()
l.trackers.ctxCancel = nil
<-l.trackers.commitSyncerClosed
l.trackers.commitSyncerClosed = nil

// flush one final time
triggerTrackerFlush(t, l)

var vtSnapshot map[basics.Round]*ledgercore.VotersForRound
func() {
// grab internal lock in order to access the voters tracker
// since the assert below might fail, use a nested scope to ensure the lock is released
l.acctsOnline.voters.votersMu.Lock()
defer l.acctsOnline.voters.votersMu.Unlock()

vtSnapshot = l.acctsOnline.voters.votersForRoundCache

// verifying that the tree for round 512 is still in the cache, but the tree for round 256 is evicted.
require.Contains(t, vtSnapshot, basics.Round(496))
require.NotContains(t, vtSnapshot, basics.Round(240))
}()

err = l.reloadLedger()
require.NoError(t, err)
Expand All @@ -2953,6 +2970,7 @@ func TestVotersReloadFromDiskAfterOneStateProofCommitted(t *testing.T) {
cfg := config.GetDefaultLocal()
cfg.Archival = false
cfg.MaxAcctLookback = proto.StateProofInterval - proto.StateProofVotersLookback - 10
cfg.CatchpointInterval = 0 // no need catchpoint for this test

ledgertesting.WithAndWithoutLRUCache(t, cfg, testVotersReloadFromDiskAfterOneStateProofCommitted)
}
Expand Down
3 changes: 3 additions & 0 deletions ledger/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ func (tr *trackerRegistry) commitRound(dcc *deferredCommitContext) error {
offset := dcc.offset
dbRound := dcc.oldBase

tr.log.Debugf("commitRound called for (%d-%d)", dbRound, dbRound+basics.Round(offset))

// we can exit right away, as this is the result of mis-ordered call to committedUpTo.
if tr.dbRound < dbRound || offset < uint64(tr.dbRound-dbRound) {
tr.log.Warnf("out of order deferred commit: offset %d, dbRound %d but current tracker DB round is %d", offset, dbRound, tr.dbRound)
Expand Down Expand Up @@ -574,6 +576,7 @@ func (tr *trackerRegistry) commitRound(dcc *deferredCommitContext) error {
dcc.offset = offset
dcc.oldBase = dbRound
dcc.flushTime = time.Now()
tr.log.Debugf("commitRound advancing tracker db snapshot (%d-%d)", dbRound, dbRound+basics.Round(offset))

var err error
for _, lt := range tr.trackers {
Expand Down
2 changes: 1 addition & 1 deletion ledger/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ func (st *commitRoundStallingTracker) commitRound(context.Context, trackerdb.Tra
// 3. Set a block in prepareCommit, and initiate the commit
// 4. Set a block in produceCommittingTask, add a new block and resume the commit
// 5. Resume produceCommittingTask
// 6. The data race and panic happens in block queue syncher thread
// 6. The data race and panic happens in block queue syncer thread
func TestTrackers_DbRoundDataRace(t *testing.T) {
partitiontest.PartitionTest(t)

Expand Down

0 comments on commit 88b0ca5

Please sign in to comment.