From 0521f49b032ddab6ae8eb9802c35d5fda1b3a713 Mon Sep 17 00:00:00 2001 From: Antony Denyer Date: Wed, 22 Jun 2022 11:59:19 +0100 Subject: [PATCH] Add backoff to retry --- core/rawdb/freezer.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/rawdb/freezer.go b/core/rawdb/freezer.go index dd984deb52..8a65acda46 100644 --- a/core/rawdb/freezer.go +++ b/core/rawdb/freezer.go @@ -259,13 +259,13 @@ func (f *freezer) TruncateAncients(items uint64) error { // Sync flushes all data tables to disk. func (f *freezer) Sync() error { - return f.SyncRetry(1) + return f.SyncRetry(1, 1*time.Second) } // SyncRetry // Quorum // add retry to sync -func (f *freezer) SyncRetry(retry int8) error { +func (f *freezer) SyncRetry(retry uint8, delay time.Duration) error { var errs []error for _, table := range f.tables { if err := table.Sync(); err != nil { @@ -273,9 +273,11 @@ func (f *freezer) SyncRetry(retry int8) error { } } hasError := len(errs) > 0 - if hasError && retry < 10 { + if hasError && retry < 5 { log.Info("sync", "retry", retry, "errors", errs) - return f.SyncRetry(retry + 1) + time.Sleep(delay) + delay *= 2 + return f.SyncRetry(retry+1, delay) } else if hasError { return fmt.Errorf("%v", errs) }