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 Aug 2, 2023
1 parent 7fc4e56 commit 616c71c
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 @@ -149,9 +149,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 @@ -367,6 +371,7 @@ func (ct *catchpointTracker) loadFromDisk(l ledgerForTracker, dbRound basics.Rou
return err
}

ct.cachedDBRound = dbRound
ct.roundDigest = nil
ct.consensusVersion = nil
ct.catchpointDataWriting = 0
Expand Down Expand Up @@ -419,7 +424,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 @@ -627,6 +635,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 616c71c

Please sign in to comment.