Skip to content

Commit 847817f

Browse files
authored
gc: delete TiFlash placement rules in batch (#54071) (#54408)
close #54068
1 parent ba0d06e commit 847817f

File tree

3 files changed

+15
-17
lines changed

3 files changed

+15
-17
lines changed

domain/infosync/info.go

+10-4
Original file line numberDiff line numberDiff line change
@@ -1235,14 +1235,20 @@ func SetTiFlashPlacementRule(ctx context.Context, rule placement.TiFlashRule) er
12351235
return is.tiflashReplicaManager.SetPlacementRule(ctx, rule)
12361236
}
12371237

1238-
// DeleteTiFlashPlacementRule is to delete placement rule for certain group.
1239-
func DeleteTiFlashPlacementRule(ctx context.Context, group string, ruleID string) error {
1238+
// DeleteTiFlashPlacementRules is a helper function to delete TiFlash placement rules of given physical table IDs.
1239+
func DeleteTiFlashPlacementRules(ctx context.Context, physicalTableIDs []int64) error {
12401240
is, err := getGlobalInfoSyncer()
12411241
if err != nil {
12421242
return errors.Trace(err)
12431243
}
1244-
logutil.BgLogger().Info("DeleteTiFlashPlacementRule", zap.String("ruleID", ruleID))
1245-
return is.tiflashReplicaManager.DeletePlacementRule(ctx, group, ruleID)
1244+
logutil.BgLogger().Info("DeleteTiFlashPlacementRules", zap.Int64s("physicalTableIDs", physicalTableIDs))
1245+
rules := make([]placement.TiFlashRule, 0, len(physicalTableIDs))
1246+
for _, id := range physicalTableIDs {
1247+
// make a rule with count 0 to delete the rule
1248+
rule := MakeNewRule(id, 0, nil)
1249+
rules = append(rules, rule)
1250+
}
1251+
return is.tiflashReplicaManager.SetPlacementRuleBatch(ctx, rules)
12461252
}
12471253

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

domain/infosync/info_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ func TestTiFlashManager(t *testing.T) {
246246
require.NoError(t, err)
247247
require.Equal(t, 1, stats.Count)
248248

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

store/gcworker/gc_worker.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,7 @@ func (w *GCWorker) redoDeleteRanges(ctx context.Context, safePoint uint64, concu
979979
return nil
980980
}
981981

982-
func (w *GCWorker) doUnsafeDestroyRangeRequest(ctx context.Context, startKey []byte, endKey []byte, concurrency int) error {
982+
func (w *GCWorker) doUnsafeDestroyRangeRequest(ctx context.Context, startKey []byte, endKey []byte, _ int) error {
983983
// Get all stores every time deleting a region. So the store list is less probably to be stale.
984984
stores, err := w.getStoresForGC(ctx)
985985
if err != nil {
@@ -1970,16 +1970,8 @@ func (w *GCWorker) doGCPlacementRules(se session.Session, safePoint uint64, dr u
19701970
return
19711971
}
19721972

1973-
for _, id := range physicalTableIDs {
1974-
// Delete pd rule
1975-
failpoint.Inject("gcDeletePlacementRuleCounter", func() {})
1976-
logutil.BgLogger().Info("try delete TiFlash pd rule",
1977-
zap.Int64("tableID", id), zap.String("endKey", string(dr.EndKey)), zap.Uint64("safePoint", safePoint))
1978-
ruleID := infosync.MakeRuleID(id)
1979-
if err := infosync.DeleteTiFlashPlacementRule(context.Background(), "tiflash", ruleID); err != nil {
1980-
logutil.BgLogger().Error("delete TiFlash pd rule failed when gc",
1981-
zap.Error(err), zap.String("ruleID", ruleID), zap.Uint64("safePoint", safePoint))
1982-
}
1973+
if err := infosync.DeleteTiFlashPlacementRules(context.Background(), physicalTableIDs); err != nil {
1974+
logutil.BgLogger().Error("delete placement rules failed", zap.Error(err), zap.Int64s("tableIDs", physicalTableIDs))
19831975
}
19841976
bundles := make([]*placement.Bundle, 0, len(physicalTableIDs))
19851977
for _, id := range physicalTableIDs {

0 commit comments

Comments
 (0)