diff --git a/pkg/domain/infosync/info.go b/pkg/domain/infosync/info.go index 908d84df8aced..59c2e5a003cba 100644 --- a/pkg/domain/infosync/info.go +++ b/pkg/domain/infosync/info.go @@ -1155,14 +1155,20 @@ func SetTiFlashPlacementRule(ctx context.Context, rule pdhttp.Rule) error { return is.tiflashReplicaManager.SetPlacementRule(ctx, &rule) } -// DeleteTiFlashPlacementRule is to delete placement rule for certain group. -func DeleteTiFlashPlacementRule(ctx context.Context, group string, ruleID string) error { +// DeleteTiFlashPlacementRules is a helper function to delete TiFlash placement rules of given physical table IDs. +func DeleteTiFlashPlacementRules(ctx context.Context, physicalTableIDs []int64) error { is, err := getGlobalInfoSyncer() if err != nil { return errors.Trace(err) } - logutil.BgLogger().Info("DeleteTiFlashPlacementRule", zap.String("ruleID", ruleID)) - return is.tiflashReplicaManager.DeletePlacementRule(ctx, group, ruleID) + logutil.BgLogger().Info("DeleteTiFlashPlacementRules", zap.Int64s("physicalTableIDs", physicalTableIDs)) + rules := make([]*pdhttp.Rule, 0, len(physicalTableIDs)) + for _, id := range physicalTableIDs { + // make a rule with count 0 to delete the rule + rule := MakeNewRule(id, 0, nil) + rules = append(rules, &rule) + } + return is.tiflashReplicaManager.SetPlacementRuleBatch(ctx, rules) } // GetTiFlashGroupRules to get all placement rule in a certain group. diff --git a/pkg/domain/infosync/info_test.go b/pkg/domain/infosync/info_test.go index 7896e6e582251..b0f4bca164e90 100644 --- a/pkg/domain/infosync/info_test.go +++ b/pkg/domain/infosync/info_test.go @@ -242,8 +242,8 @@ func TestTiFlashManager(t *testing.T) { require.NoError(t, err) require.Equal(t, 1, stats.Count) - // DeleteTiFlashPlacementRule - require.NoError(t, DeleteTiFlashPlacementRule(ctx, "tiflash", rule.ID)) + // DeleteTiFlashPlacementRules + require.NoError(t, DeleteTiFlashPlacementRules(ctx, []int64{1})) rules, err = GetTiFlashGroupRules(ctx, "tiflash") require.NoError(t, err) require.Equal(t, 0, len(rules)) diff --git a/pkg/store/gcworker/gc_worker.go b/pkg/store/gcworker/gc_worker.go index e05099726701b..3f5c1d3d166b3 100644 --- a/pkg/store/gcworker/gc_worker.go +++ b/pkg/store/gcworker/gc_worker.go @@ -932,7 +932,7 @@ func (w *GCWorker) redoDeleteRanges(ctx context.Context, safePoint uint64, concu return nil } -func (w *GCWorker) doUnsafeDestroyRangeRequest(ctx context.Context, startKey []byte, endKey []byte, concurrency int) error { +func (w *GCWorker) doUnsafeDestroyRangeRequest(ctx context.Context, startKey []byte, endKey []byte, _ int) error { // Get all stores every time deleting a region. So the store list is less probably to be stale. stores, err := w.getStoresForGC(ctx) if err != nil { @@ -1489,7 +1489,7 @@ func (w *GCWorker) saveValueToSysTable(key, value string) error { // GC placement rules when the partitions are removed by the GC worker. // Placement rules cannot be removed immediately after drop table / truncate table, // because the tables can be flashed back or recovered. -func (w *GCWorker) doGCPlacementRules(se sessiontypes.Session, safePoint uint64, dr util.DelRangeTask, gcPlacementRuleCache map[int64]any) (err error) { +func (w *GCWorker) doGCPlacementRules(se sessiontypes.Session, _ uint64, dr util.DelRangeTask, gcPlacementRuleCache map[int64]any) (err error) { // Get the job from the job history var historyJob *model.Job failpoint.Inject("mockHistoryJobForGC", func(v failpoint.Value) { @@ -1544,16 +1544,8 @@ func (w *GCWorker) doGCPlacementRules(se sessiontypes.Session, safePoint uint64, return } - for _, id := range physicalTableIDs { - // Delete pd rule - failpoint.Inject("gcDeletePlacementRuleCounter", func() {}) - logutil.BgLogger().Info("try delete TiFlash pd rule", - zap.Int64("tableID", id), zap.String("endKey", string(dr.EndKey)), zap.Uint64("safePoint", safePoint)) - ruleID := infosync.MakeRuleID(id) - if err := infosync.DeleteTiFlashPlacementRule(context.Background(), "tiflash", ruleID); err != nil { - logutil.BgLogger().Error("delete TiFlash pd rule failed when gc", - zap.Error(err), zap.String("ruleID", ruleID), zap.Uint64("safePoint", safePoint)) - } + if err := infosync.DeleteTiFlashPlacementRules(context.Background(), physicalTableIDs); err != nil { + logutil.BgLogger().Error("delete placement rules failed", zap.Error(err), zap.Int64s("tableIDs", physicalTableIDs)) } bundles := make([]*placement.Bundle, 0, len(physicalTableIDs)) for _, id := range physicalTableIDs {