From 1382bdcdcc066ad0dac9bca718394fff1db2ae9c Mon Sep 17 00:00:00 2001 From: Andrew Gillis Date: Sat, 11 Nov 2023 04:07:48 -0800 Subject: [PATCH] Limit time spent removing old data-transfer records (#2384) * Limit time spent removing old data-transfer records --- command/daemon.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/command/daemon.go b/command/daemon.go index fce08db6e..85a475732 100644 --- a/command/daemon.go +++ b/command/daemon.go @@ -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 }