Skip to content

Commit

Permalink
fix: remove expired batches in the worker and added sleep after to co…
Browse files Browse the repository at this point in the history
…m… (#4391)
  • Loading branch information
istae authored Oct 11, 2023
1 parent fbf482b commit 5d00652
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 7 additions & 0 deletions cmd/bee/cmd/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/storer/reserve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 5d00652

Please sign in to comment.