Skip to content

Commit

Permalink
GC : fix issue of delete range could not be executed again if the cle…
Browse files Browse the repository at this point in the history
…aning rules failed (pingcap#53368)

ref pingcap#53369
  • Loading branch information
ystaticy authored Jun 6, 2024
1 parent b8c0865 commit a865c86
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
20 changes: 10 additions & 10 deletions pkg/store/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -845,16 +845,6 @@ func (w *GCWorker) deleteRanges(ctx context.Context, safePoint uint64, concurren
continue
}

err = util.CompleteDeleteRange(se, r, !v2)
if err != nil {
logutil.Logger(ctx).Error("failed to mark delete range task done", zap.String("category", "gc worker"),
zap.String("uuid", w.uuid),
zap.Stringer("startKey", startKey),
zap.Stringer("endKey", endKey),
zap.Error(err))
metrics.GCUnsafeDestroyRangeFailuresCounterVec.WithLabelValues("save").Inc()
}

if err := w.doGCPlacementRules(se, safePoint, r, gcPlacementRuleCache); err != nil {
logutil.Logger(ctx).Error("gc placement rules failed on range", zap.String("category", "gc worker"),
zap.String("uuid", w.uuid),
Expand All @@ -871,6 +861,16 @@ func (w *GCWorker) deleteRanges(ctx context.Context, safePoint uint64, concurren
zap.Error(err))
continue
}

err = util.CompleteDeleteRange(se, r, !v2)
if err != nil {
logutil.Logger(ctx).Error("failed to mark delete range task done", zap.String("category", "gc worker"),
zap.String("uuid", w.uuid),
zap.Stringer("startKey", startKey),
zap.Stringer("endKey", endKey),
zap.Error(err))
metrics.GCUnsafeDestroyRangeFailuresCounterVec.WithLabelValues("save").Inc()
}
}
logutil.Logger(ctx).Info("finish delete ranges", zap.String("category", "gc worker"),
zap.String("uuid", w.uuid),
Expand Down
15 changes: 15 additions & 0 deletions pkg/store/gcworker/gc_worker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ func TestDeleteRangesFailure(t *testing.T) {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJobForGC"))
}()

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJob", "return(\"schema/d1/t1\")"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJob"))
}()

// Put some delete range tasks.
se := createSession(s.gcWorker.store)
defer se.Close()
Expand Down Expand Up @@ -813,6 +818,16 @@ Loop:
func TestUnsafeDestroyRangeForRaftkv2(t *testing.T) {
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/ddl/util/IsRaftKv2", "return(true)"))

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJobForGC", "return(1)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJobForGC"))
}()

require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJob", "return(\"schema/d1/t1\")"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/store/gcworker/mockHistoryJob"))
}()

s := createGCWorkerSuite(t)
// Put some delete range tasks.
se := createSession(s.gcWorker.store)
Expand Down

0 comments on commit a865c86

Please sign in to comment.