Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gc: delete TiFlash placement rules in batch (#54071) #54408

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions domain/infosync/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -1235,14 +1235,20 @@ func SetTiFlashPlacementRule(ctx context.Context, rule placement.TiFlashRule) er
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([]placement.TiFlashRule, 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.
Expand Down
4 changes: 2 additions & 2 deletions domain/infosync/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,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))
Expand Down
14 changes: 3 additions & 11 deletions store/gcworker/gc_worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@
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 {
Expand Down Expand Up @@ -1970,16 +1970,8 @@
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))

Check warning on line 1974 in store/gcworker/gc_worker.go

View check run for this annotation

Codecov / codecov/patch

store/gcworker/gc_worker.go#L1974

Added line #L1974 was not covered by tests
}
bundles := make([]*placement.Bundle, 0, len(physicalTableIDs))
for _, id := range physicalTableIDs {
Expand Down