From ba0ca6a4abb2023e0ac9d3d94430d87ed0dfd230 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 13 Jan 2025 23:37:42 +0300 Subject: [PATCH] core: perform synchronized persist if GC took some time The intention here is to reduce the amount of in-flight changes and prevent OOM. It doesn't matter what we're doing, persisting or collecting garbage, what matters is that we're behind the schedule of regular persist cycle. Refs. #3783. Signed-off-by: Roman Khimov --- pkg/core/blockchain.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pkg/core/blockchain.go b/pkg/core/blockchain.go index adfbc3ef2..438bc3070 100644 --- a/pkg/core/blockchain.go +++ b/pkg/core/blockchain.go @@ -1119,7 +1119,6 @@ func (bc *Blockchain) Run() { return case <-persistTimer.C: var oldPersisted uint32 - var gcDur time.Duration if bc.config.Ledger.RemoveUntraceableBlocks { oldPersisted = atomic.LoadUint32(&bc.persistedHeight) @@ -1129,10 +1128,10 @@ func (bc *Blockchain) Run() { bc.log.Warn("failed to persist blockchain", zap.Error(err)) } if bc.config.Ledger.RemoveUntraceableBlocks { - gcDur = bc.tryRunGC(oldPersisted) + dur += bc.tryRunGC(oldPersisted) } nextSync = dur > persistInterval*2 - interval := persistInterval - dur - gcDur + interval := persistInterval - dur interval = max(interval, time.Microsecond) // Reset doesn't work with zero or negative value. persistTimer.Reset(interval) }