Skip to content

Commit

Permalink
Introduce cachedDbRound into catchpoint tracker
Browse files Browse the repository at this point in the history
* catchpoint's crash recovery needs to be protocol versions aware
* protocol is obtained from a block header so this tracker must
  maintain min round it can recover from similarly to acct updates
  and online accounts

This was caught by TestArchival test
  • Loading branch information
algorandskiy committed Oct 24, 2023
1 parent 7085841 commit f899cda
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions ledger/catchpointtracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,13 @@ type catchpointTracker struct {
// catchpoint files even before the protocol upgrade took place.
forceCatchpointFileWriting bool

// catchpointsMu protects `roundDigest`, `reenableCatchpointsRound` and
// catchpointsMu protects roundDigest, reenableCatchpointsRound, cachedDBRound and
// `lastCatchpointLabel`.
catchpointsMu deadlock.RWMutex

// cachedDBRound is always exactly tracker DB round (and therefore, accountsRound()),
// cached to use in lookup functions
cachedDBRound basics.Round
}

// initialize initializes the catchpointTracker structure
Expand Down Expand Up @@ -350,6 +354,7 @@ func (ct *catchpointTracker) loadFromDisk(l ledgerForTracker, dbRound basics.Rou
return err
}

ct.cachedDBRound = dbRound
ct.roundDigest = nil
ct.consensusVersion = nil
ct.catchpointDataWriting.Store(0)
Expand Down Expand Up @@ -402,7 +407,10 @@ func (ct *catchpointTracker) newBlock(blk bookkeeping.Block, delta ledgercore.St
// number that can be removed from the blocks database as well as the lookback that this
// tracker maintains.
func (ct *catchpointTracker) committedUpTo(rnd basics.Round) (retRound, lookback basics.Round) {
return rnd, basics.Round(0)
ct.catchpointsMu.RLock()
defer ct.catchpointsMu.RUnlock()
retRound = ct.cachedDBRound
return retRound, basics.Round(0)
}

// Calculate whether we have intermediate first stage catchpoint rounds and the
Expand Down Expand Up @@ -610,6 +618,7 @@ func (ct *catchpointTracker) postCommit(ctx context.Context, dcc *deferredCommit
ct.catchpointsMu.Lock()
ct.roundDigest = ct.roundDigest[dcc.offset:]
ct.consensusVersion = ct.consensusVersion[dcc.offset:]
ct.cachedDBRound = dcc.newBase()
ct.catchpointsMu.Unlock()

dcc.updatingBalancesDuration = time.Since(dcc.flushTime)
Expand Down

0 comments on commit f899cda

Please sign in to comment.