Skip to content

Commit

Permalink
Limit time spent removing old data-transfer records (#2384)
Browse files Browse the repository at this point in the history
* Limit time spent removing old data-transfer records
  • Loading branch information
gammazero authored Nov 11, 2023
1 parent 075f136 commit 1382bdc
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions command/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -698,12 +698,20 @@ func createDatastore(ctx context.Context, dir, dsType string) (datastore.Batchin
}

func cleanupTempData(ctx context.Context, ds datastore.Batching) error {
count, err := deletePrefix(ctx, ds, "/data-transfer-v2")
const dtCleanupTimeout = 10 * time.Minute
const dtPrefix = "/data-transfer-v2"

ctx, cancel := context.WithTimeout(ctx, dtCleanupTimeout)
defer cancel()

count, err := deletePrefix(ctx, ds, dtPrefix)
if err != nil {
if errors.Is(err, context.DeadlineExceeded) {
log.Info("Not enough time to finish data-transfer state cleanup")
return ds.Sync(context.Background(), datastore.NewKey(dtPrefix))
}
return err
}
if count != 0 {
log.Infow("Removed old temporary data-transfer fsm records", "count", count)
}
log.Infow("Removed old temporary data-transfer fsm records", "count", count)
return nil
}

0 comments on commit 1382bdc

Please sign in to comment.