From b755c43d12f323a16e792cc8126c5ef7f6ef437b Mon Sep 17 00:00:00 2001 From: Chlins Zhang Date: Wed, 12 Apr 2023 14:17:42 +0800 Subject: [PATCH] fix: clean the redis if the execution is not found (#18517) Delete the execution outdated status key in the redis when the execution is not found. Fixes: #18511 Signed-off-by: chlins --- src/pkg/task/dao/execution.go | 8 ++++++++ src/pkg/task/sweep_manager.go | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pkg/task/dao/execution.go b/src/pkg/task/dao/execution.go index b302533747..611dca1fce 100644 --- a/src/pkg/task/dao/execution.go +++ b/src/pkg/task/dao/execution.go @@ -476,6 +476,14 @@ func scanAndRefreshOutdateStatus(ctx context.Context) { statusChanged, currentStatus, err := ExecDAO.RefreshStatus(ctx, execID) if err != nil { + // no need to refresh and should clean cache if the execution is not found + if errors.IsNotFoundErr(err) { + if err = cache.Default().Delete(ctx, key); err != nil { + log.Errorf("failed to delete the key %s in cache, error: %v", key, err) + } + succeed++ + continue + } log.Errorf("failed to refresh the status of execution %d, error: %v", execID, err) failed++ continue diff --git a/src/pkg/task/sweep_manager.go b/src/pkg/task/sweep_manager.go index 9e387072e3..95c96b8041 100644 --- a/src/pkg/task/sweep_manager.go +++ b/src/pkg/task/sweep_manager.go @@ -139,7 +139,7 @@ func (sm *sweepManager) ListCandidates(ctx context.Context, vendorType string, r n = n + 1 } - sql = `SELECT id FROM execution WHERE vendor_type = ? AND vendor_id = ? AND start_time < ? AND status IN (?,?,?)` + sql = `SELECT id FROM execution WHERE vendor_type = ? AND vendor_id = ? AND start_time < ? AND status IN (?,?,?) ORDER BY id` // default page size is 100000 q2 := &q.Query{PageSize: int64(defaultPageSize)} for i := n; i >= 1; i-- {