Skip to content

Commit 8f340f8

Browse files
authored
pitr: Revert "pitr: add ingest recorder to repair indexes (#41670) (#46418)" (#46785)
ref #38045, close #41668
1 parent f096450 commit 8f340f8

14 files changed

+37
-788
lines changed

br/pkg/glue/progressing.go

+10-37
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ import (
1616
"golang.org/x/term"
1717
)
1818

19-
const OnlyOneTask int = -1
20-
21-
var spinnerText []string = []string{".", "..", "..."}
22-
2319
type pbProgress struct {
2420
bar *mpb.Bar
2521
progress *mpb.Progress
@@ -117,30 +113,8 @@ func (ops ConsoleOperations) startProgressBarOverDummy(title string, total int,
117113

118114
func (ops ConsoleOperations) startProgressBarOverTTY(title string, total int, extraFields ...ExtraField) ProgressWaiter {
119115
pb := mpb.New(mpb.WithOutput(ops.Out()), mpb.WithRefreshRate(400*time.Millisecond))
120-
bar := adjustTotal(pb, title, total, extraFields...)
121-
122-
// If total is zero, finish right now.
123-
if total == 0 {
124-
bar.SetTotal(0, true)
125-
}
126-
127-
return pbProgress{
128-
bar: bar,
129-
ops: ops,
130-
progress: pb,
131-
}
132-
}
133-
134-
func adjustTotal(pb *mpb.Progress, title string, total int, extraFields ...ExtraField) *mpb.Bar {
135-
if total == OnlyOneTask {
136-
return buildOneTaskBar(pb, title, 1)
137-
}
138-
return buildProgressBar(pb, title, total, extraFields...)
139-
}
140-
141-
func buildProgressBar(pb *mpb.Progress, title string, total int, extraFields ...ExtraField) *mpb.Bar {
142116
greenTitle := color.GreenString(title)
143-
return pb.New(int64(total),
117+
bar := pb.New(int64(total),
144118
// Play as if the old BR style.
145119
mpb.BarStyle().Lbound("<").Filler("-").Padding(".").Rbound(">").Tip("-", "\\", "|", "/", "-").TipOnComplete("-"),
146120
mpb.BarFillerMiddleware(func(bf mpb.BarFiller) mpb.BarFiller {
@@ -154,16 +128,15 @@ func buildProgressBar(pb *mpb.Progress, title string, total int, extraFields ...
154128
mpb.PrependDecorators(decor.OnAbort(decor.OnComplete(decor.Name(greenTitle), fmt.Sprintf("%s ::", title)), fmt.Sprintf("%s ::", title))),
155129
mpb.AppendDecorators(decor.OnAbort(decor.Any(cbOnComplete(decor.NewPercentage("%02.2f"), printFinalMessage(extraFields))), color.RedString("ABORTED"))),
156130
)
157-
}
158131

159-
var (
160-
spinnerDoneText string = fmt.Sprintf("... %s", color.GreenString("DONE"))
161-
)
132+
// If total is zero, finish right now.
133+
if total == 0 {
134+
bar.SetTotal(0, true)
135+
}
162136

163-
func buildOneTaskBar(pb *mpb.Progress, title string, total int) *mpb.Bar {
164-
return pb.New(int64(total),
165-
mpb.NopStyle(),
166-
mpb.PrependDecorators(decor.Name(title)),
167-
mpb.AppendDecorators(decor.OnAbort(decor.OnComplete(decor.Spinner(spinnerText), spinnerDoneText), color.RedString("ABORTED"))),
168-
)
137+
return pbProgress{
138+
bar: bar,
139+
ops: ops,
140+
progress: pb,
141+
}
169142
}

br/pkg/restore/BUILD.bazel

-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ go_library(
3434
"//br/pkg/metautil",
3535
"//br/pkg/pdutil",
3636
"//br/pkg/redact",
37-
"//br/pkg/restore/ingestrec",
3837
"//br/pkg/restore/prealloc_table_id",
3938
"//br/pkg/restore/split",
4039
"//br/pkg/restore/tiflashrec",

br/pkg/restore/client.go

-106
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import (
3131
"github.com/pingcap/tidb/br/pkg/metautil"
3232
"github.com/pingcap/tidb/br/pkg/pdutil"
3333
"github.com/pingcap/tidb/br/pkg/redact"
34-
"github.com/pingcap/tidb/br/pkg/restore/ingestrec"
3534
tidalloc "github.com/pingcap/tidb/br/pkg/restore/prealloc_table_id"
3635
"github.com/pingcap/tidb/br/pkg/restore/split"
3736
"github.com/pingcap/tidb/br/pkg/restore/tiflashrec"
@@ -2618,78 +2617,6 @@ func (rc *Client) UpdateSchemaVersion(ctx context.Context) error {
26182617
return nil
26192618
}
26202619

2621-
const (
2622-
alterTableDropIndexSQL = "ALTER TABLE %n.%n DROP INDEX %n"
2623-
alterTableAddIndexFormat = "ALTER TABLE %%n.%%n ADD INDEX %%n(%s)"
2624-
alterTableAddUniqueIndexFormat = "ALTER TABLE %%n.%%n ADD UNIQUE KEY %%n(%s)"
2625-
alterTableAddPrimaryFormat = "ALTER TABLE %%n.%%n ADD PRIMARY KEY (%s) NONCLUSTERED"
2626-
)
2627-
2628-
// RepairIngestIndex drops the indexes from IngestRecorder and re-add them.
2629-
func (rc *Client) RepairIngestIndex(ctx context.Context, ingestRecorder *ingestrec.IngestRecorder, g glue.Glue, storage kv.Storage) error {
2630-
dom, err := g.GetDomain(storage)
2631-
if err != nil {
2632-
return errors.Trace(err)
2633-
}
2634-
info := dom.InfoSchema()
2635-
allSchema := info.AllSchemas()
2636-
ingestRecorder.UpdateIndexInfo(allSchema)
2637-
console := glue.GetConsole(g)
2638-
err = ingestRecorder.Iterate(func(_, _ int64, info *ingestrec.IngestIndexInfo) error {
2639-
var (
2640-
addSQL strings.Builder
2641-
addArgs []interface{} = make([]interface{}, 0, 5+len(info.ColumnArgs))
2642-
progressTitle string = fmt.Sprintf("repair ingest index %s for table %s.%s", info.IndexInfo.Name.O, info.SchemaName, info.TableName)
2643-
)
2644-
w := console.StartProgressBar(progressTitle, glue.OnlyOneTask)
2645-
if info.IsPrimary {
2646-
addSQL.WriteString(fmt.Sprintf(alterTableAddPrimaryFormat, info.ColumnList))
2647-
addArgs = append(addArgs, info.SchemaName, info.TableName)
2648-
addArgs = append(addArgs, info.ColumnArgs...)
2649-
} else if info.IndexInfo.Unique {
2650-
addSQL.WriteString(fmt.Sprintf(alterTableAddUniqueIndexFormat, info.ColumnList))
2651-
addArgs = append(addArgs, info.SchemaName, info.TableName, info.IndexInfo.Name.O)
2652-
addArgs = append(addArgs, info.ColumnArgs...)
2653-
} else {
2654-
addSQL.WriteString(fmt.Sprintf(alterTableAddIndexFormat, info.ColumnList))
2655-
addArgs = append(addArgs, info.SchemaName, info.TableName, info.IndexInfo.Name.O)
2656-
addArgs = append(addArgs, info.ColumnArgs...)
2657-
}
2658-
// USING BTREE/HASH/RTREE
2659-
indexTypeStr := info.IndexInfo.Tp.String()
2660-
if len(indexTypeStr) > 0 {
2661-
addSQL.WriteString(" USING ")
2662-
addSQL.WriteString(indexTypeStr)
2663-
}
2664-
2665-
// COMMENT [...]
2666-
if len(info.IndexInfo.Comment) > 0 {
2667-
addSQL.WriteString(" COMMENT %?")
2668-
addArgs = append(addArgs, info.IndexInfo.Comment)
2669-
}
2670-
2671-
if info.IndexInfo.Invisible {
2672-
addSQL.WriteString(" INVISIBLE")
2673-
} else {
2674-
addSQL.WriteString(" VISIBLE")
2675-
}
2676-
2677-
if err := rc.db.se.ExecuteInternal(ctx, alterTableDropIndexSQL, info.SchemaName, info.TableName, info.IndexInfo.Name.O); err != nil {
2678-
return errors.Trace(err)
2679-
}
2680-
if err := rc.db.se.ExecuteInternal(ctx, addSQL.String(), addArgs...); err != nil {
2681-
return errors.Trace(err)
2682-
}
2683-
w.Inc()
2684-
if err := w.Wait(ctx); err != nil {
2685-
return errors.Trace(err)
2686-
}
2687-
w.Close()
2688-
return nil
2689-
})
2690-
return errors.Trace(err)
2691-
}
2692-
26932620
const (
26942621
insertDeleteRangeSQLPrefix = `INSERT IGNORE INTO mysql.gc_delete_range VALUES `
26952622
insertDeleteRangeSQLValue = "(%d, %d, '%s', '%s', %%[1]d)"
@@ -2909,39 +2836,6 @@ func (rc *Client) ResetTiFlashReplicas(ctx context.Context, g glue.Glue, storage
29092836
})
29102837
}
29112838

2912-
// RangeFilterFromIngestRecorder rewrites the table id of items in the ingestRecorder
2913-
// TODO: need to implement the range filter out feature
2914-
func (rc *Client) RangeFilterFromIngestRecorder(recorder *ingestrec.IngestRecorder, rewriteRules map[int64]*RewriteRules) error {
2915-
err := recorder.RewriteTableID(func(tableID int64) (int64, bool, error) {
2916-
rewriteRule, exists := rewriteRules[tableID]
2917-
if !exists {
2918-
// since the table's files will be skipped restoring, here also skips.
2919-
return 0, true, nil
2920-
}
2921-
newTableID := GetRewriteTableID(tableID, rewriteRule)
2922-
if newTableID == 0 {
2923-
return 0, false, errors.Errorf("newTableID is 0, tableID: %d", tableID)
2924-
}
2925-
return newTableID, false, nil
2926-
})
2927-
return errors.Trace(err)
2928-
/* TODO: we can use range filter to skip restoring the index kv using accelerated indexing feature
2929-
filter := rtree.NewRangeTree()
2930-
err = recorder.Iterate(func(tableID int64, indexID int64, info *ingestrec.IngestIndexInfo) error {
2931-
// range after table ID rewritten
2932-
startKey := tablecodec.EncodeTableIndexPrefix(tableID, indexID)
2933-
endKey := tablecodec.EncodeTableIndexPrefix(tableID, indexID+1)
2934-
rg := rtree.Range{
2935-
StartKey: codec.EncodeBytes([]byte{}, startKey),
2936-
EndKey: codec.EncodeBytes([]byte{}, endKey),
2937-
}
2938-
filter.InsertRange(rg)
2939-
return nil
2940-
})
2941-
return errors.Trace(err)
2942-
*/
2943-
}
2944-
29452839
// MockClient create a fake client used to test.
29462840
func MockClient(dbs map[string]*utils.Database) *Client {
29472841
return &Client{databases: dbs}

br/pkg/restore/ingestrec/BUILD.bazel

-24
This file was deleted.

0 commit comments

Comments
 (0)