diff options
Diffstat (limited to 'ledger/blockqueue.go')
-rw-r--r-- | ledger/blockqueue.go | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/ledger/blockqueue.go b/ledger/blockqueue.go index a72c1d8cb..7c1728101 100644 --- a/ledger/blockqueue.go +++ b/ledger/blockqueue.go @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2023 Algorand, Inc. +// Copyright (C) 2019-2024 Algorand, Inc. // This file is part of go-algorand // // go-algorand is free software: you can redistribute it and/or modify @@ -111,6 +111,8 @@ func (bq *blockQueue) stop() { } } +const maxDeletionBatchSize = 10_000 + func (bq *blockQueue) syncer() { bq.mu.Lock() for { @@ -164,6 +166,21 @@ func (bq *blockQueue) syncer() { bq.mu.Unlock() minToSave := bq.l.notifyCommit(committed) + var earliest basics.Round + err = bq.l.blockDBs.Rdb.Atomic(func(ctx context.Context, tx *sql.Tx) error { + var err0 error + earliest, err0 = blockdb.BlockEarliest(tx) + if err0 != nil { + bq.l.log.Warnf("blockQueue.syncer: BlockEarliest(): %v", err0) + } + return err0 + }) + if err == nil { + if basics.SubSaturate(minToSave, earliest) > maxDeletionBatchSize { + minToSave = basics.AddSaturate(earliest, maxDeletionBatchSize) + } + } + bfstart := time.Now() ledgerSyncBlockforgetCount.Inc(nil) err = bq.l.blockDBs.Wdb.Atomic(func(ctx context.Context, tx *sql.Tx) error { |