@@ -31,7 +31,6 @@ import (
31
31
"github.com/pingcap/tidb/br/pkg/metautil"
32
32
"github.com/pingcap/tidb/br/pkg/pdutil"
33
33
"github.com/pingcap/tidb/br/pkg/redact"
34
- "github.com/pingcap/tidb/br/pkg/restore/ingestrec"
35
34
tidalloc "github.com/pingcap/tidb/br/pkg/restore/prealloc_table_id"
36
35
"github.com/pingcap/tidb/br/pkg/restore/split"
37
36
"github.com/pingcap/tidb/br/pkg/restore/tiflashrec"
@@ -2618,78 +2617,6 @@ func (rc *Client) UpdateSchemaVersion(ctx context.Context) error {
2618
2617
return nil
2619
2618
}
2620
2619
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
-
2693
2620
const (
2694
2621
insertDeleteRangeSQLPrefix = `INSERT IGNORE INTO mysql.gc_delete_range VALUES `
2695
2622
insertDeleteRangeSQLValue = "(%d, %d, '%s', '%s', %%[1]d)"
@@ -2909,39 +2836,6 @@ func (rc *Client) ResetTiFlashReplicas(ctx context.Context, g glue.Glue, storage
2909
2836
})
2910
2837
}
2911
2838
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
-
2945
2839
// MockClient create a fake client used to test.
2946
2840
func MockClient (dbs map [string ]* utils.Database ) * Client {
2947
2841
return & Client {databases : dbs }
0 commit comments