Skip to content

Commit 2c71fbb

Browse files
authored
gc: delete TiFlash placement rules in batch (#54071) (#54409)
close #54068
1 parent 718cb69 commit 2c71fbb

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

domain/infosync/info.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,14 +1127,20 @@ func SetTiFlashPlacementRule(ctx context.Context, rule placement.TiFlashRule) er
11271127
return is.tiflashReplicaManager.SetPlacementRule(ctx, rule)
11281128
}
11291129

1130-
// DeleteTiFlashPlacementRule is to delete placement rule for certain group.
1131-
func DeleteTiFlashPlacementRule(ctx context.Context, group string, ruleID string) error {
1130+
// DeleteTiFlashPlacementRules is a helper function to delete TiFlash placement rules of given physical table IDs.
1131+
func DeleteTiFlashPlacementRules(ctx context.Context, physicalTableIDs []int64) error {
11321132
is, err := getGlobalInfoSyncer()
11331133
if err != nil {
11341134
return errors.Trace(err)
11351135
}
1136-
logutil.BgLogger().Info("DeleteTiFlashPlacementRule", zap.String("ruleID", ruleID))
1137-
return is.tiflashReplicaManager.DeletePlacementRule(ctx, group, ruleID)
1136+
logutil.BgLogger().Info("DeleteTiFlashPlacementRules", zap.Int64s("physicalTableIDs", physicalTableIDs))
1137+
rules := make([]*placement.TiFlashRule, 0, len(physicalTableIDs))
1138+
for _, id := range physicalTableIDs {
1139+
// make a rule with count 0 to delete the rule
1140+
rule := MakeNewRule(id, 0, nil)
1141+
rules = append(rules, rule)
1142+
}
1143+
return is.tiflashReplicaManager.SetPlacementRuleBatch(ctx, rules)
11381144
}
11391145

11401146
// GetTiFlashGroupRules to get all placement rule in a certain group.

domain/infosync/info_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ func TestTiFlashManager(t *testing.T) {
245245
require.NoError(t, err)
246246
require.Equal(t, 1, stats.Count)
247247

248-
// DeleteTiFlashPlacementRule
249-
require.NoError(t, DeleteTiFlashPlacementRule(ctx, "tiflash", rule.ID))
248+
// DeleteTiFlashPlacementRules
249+
require.NoError(t, DeleteTiFlashPlacementRules(ctx, []int64{1}))
250250
rules, err = GetTiFlashGroupRules(ctx, "tiflash")
251251
require.NoError(t, err)
252252
require.Equal(t, 0, len(rules))

store/gcworker/gc_worker.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,7 @@ func (w *GCWorker) redoDeleteRanges(ctx context.Context, safePoint uint64, concu
806806
return nil
807807
}
808808

809-
func (w *GCWorker) doUnsafeDestroyRangeRequest(ctx context.Context, startKey []byte, endKey []byte, concurrency int) error {
809+
func (w *GCWorker) doUnsafeDestroyRangeRequest(ctx context.Context, startKey []byte, endKey []byte, _ int) error {
810810
// Get all stores every time deleting a region. So the store list is less probably to be stale.
811811
stores, err := w.getStoresForGC(ctx)
812812
if err != nil {
@@ -1789,16 +1789,8 @@ func (w *GCWorker) doGCPlacementRules(se session.Session, safePoint uint64, dr u
17891789
return
17901790
}
17911791

1792-
for _, id := range physicalTableIDs {
1793-
// Delete pd rule
1794-
failpoint.Inject("gcDeletePlacementRuleCounter", func() {})
1795-
logutil.BgLogger().Info("try delete TiFlash pd rule",
1796-
zap.Int64("tableID", id), zap.String("endKey", string(dr.EndKey)), zap.Uint64("safePoint", safePoint))
1797-
ruleID := fmt.Sprintf("table-%v-r", id)
1798-
if err := infosync.DeleteTiFlashPlacementRule(context.Background(), "tiflash", ruleID); err != nil {
1799-
logutil.BgLogger().Error("delete TiFlash pd rule failed when gc",
1800-
zap.Error(err), zap.String("ruleID", ruleID), zap.Uint64("safePoint", safePoint))
1801-
}
1792+
if err := infosync.DeleteTiFlashPlacementRules(context.Background(), physicalTableIDs); err != nil {
1793+
logutil.BgLogger().Error("delete placement rules failed", zap.Error(err), zap.Int64s("tableIDs", physicalTableIDs))
18021794
}
18031795
bundles := make([]*placement.Bundle, 0, len(physicalTableIDs))
18041796
for _, id := range physicalTableIDs {

0 commit comments

Comments
 (0)