From b6ea8b3b24a8d71a6fa600ee9c1dd3362d328a7c Mon Sep 17 00:00:00 2001 From: istae <14264581+istae@users.noreply.github.com> Date: Tue, 24 Oct 2023 21:57:13 +0300 Subject: [PATCH] fix(worker): evicts batch only once (#4421) --- pkg/storer/reserve.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/storer/reserve.go b/pkg/storer/reserve.go index 088e404331b..d1abdbfd10b 100644 --- a/pkg/storer/reserve.go +++ b/pkg/storer/reserve.go @@ -154,6 +154,9 @@ func (db *DB) reserveSizeWithinRadiusWorker(ctx context.Context) { count := 0 missing := 0 radius := db.StorageRadius() + + evictBatches := make(map[string]bool) + err := db.reserve.IterateChunksItems(db.repo, 0, func(ci reserve.ChunkItem) (bool, error) { if ci.Bin >= radius { count++ @@ -163,12 +166,9 @@ func (db *DB) reserveSizeWithinRadiusWorker(ctx context.Context) { return false, nil } - if exists, _ := db.batchstore.Exists(ci.BatchID); !exists { + if exists, err := db.batchstore.Exists(ci.BatchID); err == nil && !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) - } + evictBatches[string(ci.BatchID)] = true } return false, nil }) @@ -176,6 +176,13 @@ func (db *DB) reserveSizeWithinRadiusWorker(ctx context.Context) { db.logger.Error(err, "reserve count within radius") } + for batch := range evictBatches { + db.logger.Debug("reserve size worker, invalid batch id", "batch_id", hex.EncodeToString([]byte(batch))) + if err := db.EvictBatch(ctx, []byte(batch)); err != nil { + db.logger.Warning("reserve size worker, batch eviction", "batch_id", hex.EncodeToString([]byte(batch)), "error", err) + } + } + db.metrics.ReserveSizeWithinRadius.Set(float64(count)) if !skipInvalidCheck { db.metrics.ReserveMissingBatch.Set(float64(missing))