Skip to content

Commit

Permalink
tests: debug logging for TestVotersReloadFromDiskAfterOneStateProofCo…
Browse files Browse the repository at this point in the history
…mmitted (#6088)
  • Loading branch information
algorandskiy authored Jul 31, 2024
1 parent 578684e commit 8eca278
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
14 changes: 13 additions & 1 deletion ledger/acctupdates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,18 @@ func makeMockLedgerForTrackerWithLogger(t testing.TB, inMemory bool, initialBloc
Totals: totals,
}
}
return &mockLedgerForTracker{dbs: dbs, log: l, filename: fileName, inMemory: inMemory, blocks: blocks, deltas: deltas, consensusParams: config.Consensus[consensusVersion], consensusVersion: consensusVersion, accts: accts[0]}
ml := &mockLedgerForTracker{
dbs: dbs,
log: l,
filename: fileName,
inMemory: inMemory,
blocks: blocks,
deltas: deltas, consensusParams: config.Consensus[consensusVersion],
consensusVersion: consensusVersion,
accts: accts[0],
trackers: trackerRegistry{log: l},
}
return ml

}

Expand Down Expand Up @@ -160,6 +171,7 @@ func (ml *mockLedgerForTracker) fork(t testing.TB) *mockLedgerForTracker {
filename: fn,
consensusParams: ml.consensusParams,
consensusVersion: ml.consensusVersion,
trackers: trackerRegistry{log: dblogger},
}
for k, v := range ml.accts {
newLedgerTracker.accts[k] = v
Expand Down
1 change: 1 addition & 0 deletions ledger/blockqueue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func TestBlockQueueSyncerDeletion(t *testing.T) {
l := &Ledger{
log: log,
blockDBs: blockDBs,
trackers: trackerRegistry{log: log},
}
if test.tracker != nil {
l.trackers.trackers = append(l.trackers.trackers, test.tracker)
Expand Down
7 changes: 5 additions & 2 deletions ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,11 @@ func (l *Ledger) reloadLedger() error {
blockListeners := make([]ledgercore.BlockListener, 0, len(l.notifier.listeners))
blockListeners = append(blockListeners, l.notifier.listeners...)

// close the trackers.
l.trackers.close()
// close the trackers if the registry was already initialized: opening a new ledger calls reloadLedger
// and there is nothing to close. Registry's logger is not initialized yet so close cannot log.
if l.trackers.trackers != nil {
l.trackers.close()
}

// init block queue
var err error
Expand Down
1 change: 1 addition & 0 deletions ledger/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3415,6 +3415,7 @@ func TestLedgerRetainMinOffCatchpointInterval(t *testing.T) {
l := &Ledger{}
l.cfg = cfg
l.archival = cfg.Archival
l.trackers.log = logging.TestingLog(t)

for i := 1; i <= blocksToMake; i++ {
minBlockToKeep := l.notifyCommit(basics.Round(i))
Expand Down
9 changes: 9 additions & 0 deletions ledger/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ func (tr *trackerRegistry) scheduleCommit(blockqRound, maxLookback basics.Round)
// Dropping this dcc allows the blockqueue syncer to continue persisting other blocks
// and ledger reads to proceed without being blocked by trackerMu lock.
tr.accountsWriting.Done()
tr.log.Debugf("trackerRegistry.scheduleCommit: deferredCommits channel is full, skipping commit for (%d-%d)", dcc.oldBase, dcc.oldBase+basics.Round(dcc.offset))
}
}
}
Expand All @@ -491,22 +492,27 @@ func (tr *trackerRegistry) isBehindCommittingDeltas(latest basics.Round) bool {
}

func (tr *trackerRegistry) close() {
tr.log.Debugf("trackerRegistry is closing")
if tr.ctxCancel != nil {
tr.ctxCancel()
}

// close() is called from reloadLedger() when and trackerRegistry is not initialized yet
if tr.commitSyncerClosed != nil {
tr.log.Debugf("trackerRegistry is waiting for accounts writing to complete")
tr.waitAccountsWriting()
// this would block until the commitSyncerClosed channel get closed.
<-tr.commitSyncerClosed
tr.log.Debugf("trackerRegistry done waiting for accounts writing")
}

tr.log.Debugf("trackerRegistry is closing trackers")
for _, lt := range tr.trackers {
lt.close()
}
tr.trackers = nil
tr.accts = nil
tr.log.Debugf("trackerRegistry has closed")
}

// commitSyncer is the syncer go-routine function which perform the database updates. Internally, it dequeues deferredCommits and
Expand All @@ -525,11 +531,13 @@ func (tr *trackerRegistry) commitSyncer(deferredCommits chan *deferredCommitCont
}
case <-tr.ctx.Done():
// drain the pending commits queue:
tr.log.Debugf("commitSyncer is closing, draining the pending commits queue")
drained := false
for !drained {
select {
case <-deferredCommits:
tr.accountsWriting.Done()
tr.log.Debugf("commitSyncer drained a pending commit")
default:
drained = true
}
Expand Down Expand Up @@ -648,6 +656,7 @@ func (tr *trackerRegistry) commitRound(dcc *deferredCommitContext) error {
lt.postCommitUnlocked(tr.ctx, dcc)
}

tr.log.Debugf("commitRound completed for (%d-%d)", dbRound, dbRound+basics.Round(offset))
return nil
}

Expand Down

0 comments on commit 8eca278

Please sign in to comment.