@@ -23,6 +23,7 @@ import (
23
23
backuppb "github.com/pingcap/kvproto/pkg/brpb"
24
24
"github.com/pingcap/log"
25
25
berrors "github.com/pingcap/tidb/br/pkg/errors"
26
+ "github.com/pingcap/tidb/br/pkg/logutil"
26
27
"github.com/pingcap/tidb/br/pkg/restore/ingestrec"
27
28
"github.com/pingcap/tidb/br/pkg/restore/tiflashrec"
28
29
"github.com/pingcap/tidb/pkg/kv"
@@ -705,10 +706,11 @@ func (sr *SchemasReplace) restoreFromHistory(job *model.Job, isSubJob bool) erro
705
706
}
706
707
707
708
func (sr * SchemasReplace ) deleteRange (job * model.Job ) error {
709
+ lctx := logutil .ContextWithField (context .Background (), logutil .RedactAny ("category" , "ddl: rewrite delete range" ))
708
710
dbReplace , exist := sr .DbMap [job .SchemaID ]
709
711
if ! exist {
710
712
// skip this mddljob, the same below
711
- log . Debug ("try to drop a non-existent range, missing oldDBID" , zap .Int64 ("oldDBID" , job .SchemaID ))
713
+ logutil . CL ( lctx ). Warn ("try to drop a non-existent range, missing oldDBID" , zap .Int64 ("oldDBID" , job .SchemaID ))
712
714
return nil
713
715
}
714
716
@@ -744,14 +746,14 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
744
746
newTableIDs := make ([]int64 , 0 , len (tableIDs ))
745
747
for tableID , tableReplace := range dbReplace .TableMap {
746
748
if _ , exist := argsSet [tableID ]; ! exist {
747
- log . Debug ("DropSchema: record a table, but it doesn't exist in job args" ,
749
+ logutil . CL ( lctx ). Warn ("DropSchema: record a table, but it doesn't exist in job args" ,
748
750
zap .Int64 ("oldTableID" , tableID ))
749
751
continue
750
752
}
751
753
newTableIDs = append (newTableIDs , tableReplace .TableID )
752
754
for partitionID , newPartitionID := range tableReplace .PartitionMap {
753
755
if _ , exist := argsSet [partitionID ]; ! exist {
754
- log . Debug ("DropSchema: record a partition, but it doesn't exist in job args" ,
756
+ logutil . CL ( lctx ). Warn ("DropSchema: record a partition, but it doesn't exist in job args" ,
755
757
zap .Int64 ("oldPartitionID" , partitionID ))
756
758
continue
757
759
}
@@ -760,7 +762,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
760
762
}
761
763
762
764
if len (newTableIDs ) != len (tableIDs ) {
763
- log . Debug (
765
+ logutil . CL ( lctx ). Warn (
764
766
"DropSchema: try to drop a non-existent table/partition, whose oldID doesn't exist in tableReplace" )
765
767
// only drop newTableIDs' ranges
766
768
}
@@ -774,7 +776,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
774
776
case model .ActionDropTable , model .ActionTruncateTable :
775
777
tableReplace , exist := dbReplace .TableMap [job .TableID ]
776
778
if ! exist {
777
- log . Debug ("DropTable/TruncateTable: try to drop a non-existent table, missing oldTableID" ,
779
+ logutil . CL ( lctx ). Warn ("DropTable/TruncateTable: try to drop a non-existent table, missing oldTableID" ,
778
780
zap .Int64 ("oldTableID" , job .TableID ))
779
781
return nil
780
782
}
@@ -787,18 +789,19 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
787
789
return errors .Trace (err )
788
790
}
789
791
if len (physicalTableIDs ) > 0 {
790
- // delete partition id instead of table id
791
- for i := 0 ; i < len (physicalTableIDs ); i ++ {
792
- newPid , exist := tableReplace.PartitionMap [physicalTableIDs [i ]]
792
+ newPhysicalTableIDs := make ([]int64 , 0 , len (physicalTableIDs ))
793
+ // delete partition id
794
+ for _ , oldPid := range physicalTableIDs {
795
+ newPid , exist := tableReplace .PartitionMap [oldPid ]
793
796
if ! exist {
794
- log . Debug ("DropTable/TruncateTable: try to drop a non-existent table, missing oldPartitionID" ,
795
- zap .Int64 ("oldPartitionID" , physicalTableIDs [ i ] ))
797
+ logutil . CL ( lctx ). Warn ("DropTable/TruncateTable: try to drop a non-existent table, missing oldPartitionID" ,
798
+ zap .Int64 ("oldPartitionID" , oldPid ))
796
799
continue
797
800
}
798
- physicalTableIDs [ i ] = newPid
801
+ newPhysicalTableIDs = append ( newPhysicalTableIDs , newPid )
799
802
}
800
- if len (physicalTableIDs ) > 0 {
801
- sr .insertDeleteRangeForTable (newJobID , physicalTableIDs )
803
+ if len (newPhysicalTableIDs ) > 0 {
804
+ sr .insertDeleteRangeForTable (newJobID , newPhysicalTableIDs )
802
805
}
803
806
return nil
804
807
}
@@ -808,7 +811,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
808
811
case model .ActionDropTablePartition , model .ActionTruncateTablePartition :
809
812
tableReplace , exist := dbReplace .TableMap [job .TableID ]
810
813
if ! exist {
811
- log . Debug (
814
+ logutil . CL ( lctx ). Warn (
812
815
"DropTablePartition/TruncateTablePartition: try to drop a non-existent table, missing oldTableID" ,
813
816
zap .Int64 ("oldTableID" , job .TableID ))
814
817
return nil
@@ -818,26 +821,27 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
818
821
return errors .Trace (err )
819
822
}
820
823
821
- for i := 0 ; i < len (physicalTableIDs ); i ++ {
822
- newPid , exist := tableReplace.PartitionMap [physicalTableIDs [i ]]
824
+ newPhysicalTableIDs := make ([]int64 , 0 , len (physicalTableIDs ))
825
+ for _ , oldPid := range physicalTableIDs {
826
+ newPid , exist := tableReplace .PartitionMap [oldPid ]
823
827
if ! exist {
824
- log . Debug (
828
+ logutil . CL ( lctx ). Warn (
825
829
"DropTablePartition/TruncateTablePartition: try to drop a non-existent table, missing oldPartitionID" ,
826
- zap .Int64 ("oldPartitionID" , physicalTableIDs [ i ] ))
830
+ zap .Int64 ("oldPartitionID" , oldPid ))
827
831
continue
828
832
}
829
- physicalTableIDs [ i ] = newPid
833
+ newPhysicalTableIDs = append ( newPhysicalTableIDs , newPid )
830
834
}
831
- if len (physicalTableIDs ) > 0 {
832
- sr .insertDeleteRangeForTable (newJobID , physicalTableIDs )
835
+ if len (newPhysicalTableIDs ) > 0 {
836
+ sr .insertDeleteRangeForTable (newJobID , newPhysicalTableIDs )
833
837
}
834
838
return nil
835
839
// ActionAddIndex, ActionAddPrimaryKey needs do it, because it needs to be rolled back when it's canceled.
836
840
case model .ActionAddIndex , model .ActionAddPrimaryKey :
837
841
// iff job.State = model.JobStateRollbackDone
838
842
tableReplace , exist := dbReplace .TableMap [job .TableID ]
839
843
if ! exist {
840
- log . Debug ("AddIndex/AddPrimaryKey roll-back: try to drop a non-existent table, missing oldTableID" ,
844
+ logutil . CL ( lctx ). Warn ("AddIndex/AddPrimaryKey roll-back: try to drop a non-existent table, missing oldTableID" ,
841
845
zap .Int64 ("oldTableID" , job .TableID ))
842
846
return nil
843
847
}
@@ -856,7 +860,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
856
860
for _ , oldPid := range partitionIDs {
857
861
newPid , exist := tableReplace .PartitionMap [oldPid ]
858
862
if ! exist {
859
- log . Debug (
863
+ logutil . CL ( lctx ). Warn (
860
864
"AddIndex/AddPrimaryKey roll-back: try to drop a non-existent table, missing oldPartitionID" ,
861
865
zap .Int64 ("oldPartitionID" , oldPid ))
862
866
continue
@@ -871,7 +875,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
871
875
case model .ActionDropIndex , model .ActionDropPrimaryKey :
872
876
tableReplace , exist := dbReplace .TableMap [job .TableID ]
873
877
if ! exist {
874
- log . Debug ("DropIndex/DropPrimaryKey: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
878
+ logutil . CL ( lctx ). Warn ("DropIndex/DropPrimaryKey: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
875
879
return nil
876
880
}
877
881
@@ -890,7 +894,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
890
894
for _ , oldPid := range partitionIDs {
891
895
newPid , exist := tableReplace .PartitionMap [oldPid ]
892
896
if ! exist {
893
- log . Debug ("DropIndex/DropPrimaryKey: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
897
+ logutil . CL ( lctx ). Warn ("DropIndex/DropPrimaryKey: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
894
898
continue
895
899
}
896
900
// len(indexIDs) = 1
@@ -913,7 +917,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
913
917
914
918
tableReplace , exist := dbReplace .TableMap [job .TableID ]
915
919
if ! exist {
916
- log . Debug ("DropIndexes: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
920
+ logutil . CL ( lctx ). Warn ("DropIndexes: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
917
921
return nil
918
922
}
919
923
@@ -922,7 +926,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
922
926
for _ , oldPid := range partitionIDs {
923
927
newPid , exist := tableReplace .PartitionMap [oldPid ]
924
928
if ! exist {
925
- log . Debug ("DropIndexes: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
929
+ logutil . CL ( lctx ). Warn ("DropIndexes: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
926
930
continue
927
931
}
928
932
sr .insertDeleteRangeForIndex (newJobID , & elementID , newPid , indexIDs )
@@ -942,7 +946,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
942
946
if len (indexIDs ) > 0 {
943
947
tableReplace , exist := dbReplace .TableMap [job .TableID ]
944
948
if ! exist {
945
- log . Debug ("DropColumn: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
949
+ logutil . CL ( lctx ). Warn ("DropColumn: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
946
950
return nil
947
951
}
948
952
@@ -951,7 +955,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
951
955
for _ , oldPid := range partitionIDs {
952
956
newPid , exist := tableReplace .PartitionMap [oldPid ]
953
957
if ! exist {
954
- log . Debug ("DropColumn: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
958
+ logutil . CL ( lctx ). Warn ("DropColumn: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
955
959
continue
956
960
}
957
961
sr .insertDeleteRangeForIndex (newJobID , & elementID , newPid , indexIDs )
@@ -972,7 +976,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
972
976
if len (indexIDs ) > 0 {
973
977
tableReplace , exist := dbReplace .TableMap [job .TableID ]
974
978
if ! exist {
975
- log . Debug ("DropColumns: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
979
+ logutil . CL ( lctx ). Warn ("DropColumns: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
976
980
return nil
977
981
}
978
982
@@ -981,7 +985,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
981
985
for _ , oldPid := range partitionIDs {
982
986
newPid , exist := tableReplace .PartitionMap [oldPid ]
983
987
if ! exist {
984
- log . Debug ("DropColumns: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
988
+ logutil . CL ( lctx ). Warn ("DropColumns: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
985
989
continue
986
990
}
987
991
sr .insertDeleteRangeForIndex (newJobID , & elementID , newPid , indexIDs )
@@ -1001,7 +1005,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
1001
1005
}
1002
1006
tableReplace , exist := dbReplace .TableMap [job .TableID ]
1003
1007
if ! exist {
1004
- log . Debug ("DropColumn: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
1008
+ logutil . CL ( lctx ). Warn ("DropColumn: try to drop a non-existent table, missing oldTableID" , zap .Int64 ("oldTableID" , job .TableID ))
1005
1009
return nil
1006
1010
}
1007
1011
@@ -1010,7 +1014,7 @@ func (sr *SchemasReplace) deleteRange(job *model.Job) error {
1010
1014
for _ , oldPid := range partitionIDs {
1011
1015
newPid , exist := tableReplace .PartitionMap [oldPid ]
1012
1016
if ! exist {
1013
- log . Debug ("DropColumn: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
1017
+ logutil . CL ( lctx ). Warn ("DropColumn: try to drop a non-existent table, missing oldPartitionID" , zap .Int64 ("oldPartitionID" , oldPid ))
1014
1018
continue
1015
1019
}
1016
1020
sr .insertDeleteRangeForIndex (newJobID , & elementID , newPid , indexIDs )
0 commit comments