Skip to content

Commit

Permalink
boostrapper: compact blocks before iterating them (#2997)
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Sloane <andy@a1k0n.net>
  • Loading branch information
a1k0n committed May 13, 2024
1 parent c4c9800 commit 4ac6138
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions snow/engine/snowman/bootstrap/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const (
batchWritePeriod = 64
iteratorReleasePeriod = 1024
logPeriod = 5 * time.Second
minBlocksToCompact = 5000
)

// getMissingBlockIDs returns the ID of the blocks that should be fetched to
Expand Down Expand Up @@ -133,6 +134,15 @@ func execute(
tree *interval.Tree,
lastAcceptedHeight uint64,
) error {
totalNumberToProcess := tree.Len()
if totalNumberToProcess > minBlocksToCompact {
log("compacting database before executing blocks...")
if err := db.Compact(nil, nil); err != nil {
// Not a fatal error, log and move on.
log("failed to compact bootstrap database before executing blocks", zap.Error(err))
}
}

var (
batch = db.NewBatch()
processedSinceBatchWrite uint
Expand All @@ -152,9 +162,8 @@ func execute(
iterator = interval.GetBlockIterator(db)
processedSinceIteratorRelease uint

startTime = time.Now()
timeOfNextLog = startTime.Add(logPeriod)
totalNumberToProcess = tree.Len()
startTime = time.Now()
timeOfNextLog = startTime.Add(logPeriod)
)
defer func() {
iterator.Release()
Expand Down

0 comments on commit 4ac6138

Please sign in to comment.