From 5d006520be79a9906c784326df01893b993e81d2 Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Wed, 11 Oct 2023 17:10:21 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20remove=20expired=20batches=20in=20the=20?= =?UTF-8?q?worker=20and=20added=20sleep=20after=20to=20com=E2=80=A6=20(#43?= =?UTF-8?q?91)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cmd/bee/cmd/db.go | 7 +++++++ pkg/storer/reserve.go | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/bee/cmd/db.go b/cmd/bee/cmd/db.go index ffb17771172..496239d98d7 100644 --- a/cmd/bee/cmd/db.go +++ b/cmd/bee/cmd/db.go @@ -117,6 +117,12 @@ func dbCompactCmd(cmd *cobra.Command) { return fmt.Errorf("new logger: %w", err) } + d, err := cmd.Flags().GetDuration(optionNameSleepAfter) + if err != nil { + logger.Error(err, "getting sleep value failed") + } + defer func() { time.Sleep(d) }() + dataDir, err := cmd.Flags().GetString(optionNameDataDir) if err != nil { return fmt.Errorf("get data-dir: %w", err) @@ -155,6 +161,7 @@ func dbCompactCmd(cmd *cobra.Command) { c.Flags().String(optionNameDataDir, "", "data directory") c.Flags().String(optionNameVerbosity, "info", "verbosity level") c.Flags().Bool(optionNameValidation, false, "run chunk validation checks before and after the compaction") + c.Flags().Duration(optionNameSleepAfter, time.Duration(0), "time to sleep after the operation finished") cmd.AddCommand(c) } diff --git a/pkg/storer/reserve.go b/pkg/storer/reserve.go index 8535bbe1dd8..7d332d6ec07 100644 --- a/pkg/storer/reserve.go +++ b/pkg/storer/reserve.go @@ -135,6 +135,9 @@ func (db *DB) reserveSizeWithinRadiusWorker(ctx context.Context) { if exists, _ := db.batchstore.Exists(ci.BatchID); !exists { missing++ db.logger.Debug("reserve size worker, item with invalid batch id", "batch_id", hex.EncodeToString(ci.BatchID), "chunk_address", ci.ChunkAddress) + if err := db.EvictBatch(ctx, ci.BatchID); err != nil { + db.logger.Warning("reserve size worker, batch eviction", "batch_id", hex.EncodeToString(ci.BatchID), "chunk_address", ci.ChunkAddress, "error", err) + } } return false, nil }) @@ -210,7 +213,7 @@ func (db *DB) evictionWorker(ctx context.Context) { err := db.evictExpiredBatches(ctx) if err != nil { - db.logger.Error(err, "eviction worker expired batche") + db.logger.Warning("eviction worker expired batches", "error", err) continue }