@@ -511,7 +511,11 @@ func loadTableRanges(
511
511
maxSleep := 10000 // ms
512
512
bo := tikv .NewBackofferWithVars (ctx , maxSleep , nil )
513
513
var ranges []kv.KeyRange
514
- err := util .RunWithRetry (util .DefaultMaxRetries , util .RetryInterval , func () (bool , error ) {
514
+ maxRetryTimes := util .DefaultMaxRetries
515
+ failpoint .Inject ("loadTableRangesNoRetry" , func () {
516
+ maxRetryTimes = 1
517
+ })
518
+ err := util .RunWithRetry (maxRetryTimes , util .RetryInterval , func () (bool , error ) {
515
519
logutil .DDLLogger ().Info ("load table ranges from PD" ,
516
520
zap .Int64 ("physicalTableID" , t .GetPhysicalID ()),
517
521
zap .String ("start key" , hex .EncodeToString (startKey )),
@@ -549,6 +553,9 @@ func loadTableRanges(
549
553
}
550
554
551
555
func validateAndFillRanges (ranges []kv.KeyRange , startKey , endKey []byte ) error {
556
+ failpoint .Inject ("validateAndFillRangesErr" , func () {
557
+ failpoint .Return (dbterror .ErrInvalidSplitRegionRanges .GenWithStackByArgs ("mock" ))
558
+ })
552
559
if len (ranges ) == 0 {
553
560
errMsg := fmt .Sprintf ("cannot find region in range [%s, %s]" ,
554
561
hex .EncodeToString (startKey ), hex .EncodeToString (endKey ))
@@ -559,19 +566,26 @@ func validateAndFillRanges(ranges []kv.KeyRange, startKey, endKey []byte) error
559
566
s := r .StartKey
560
567
if len (s ) == 0 || bytes .Compare (s , startKey ) < 0 {
561
568
ranges [i ].StartKey = startKey
569
+ } else if bytes .Compare (s , startKey ) > 0 {
570
+ errMsg := fmt .Sprintf ("get empty range at the beginning of ranges, expected %s, but got %s" ,
571
+ hex .EncodeToString (startKey ), hex .EncodeToString (s ))
572
+ return dbterror .ErrInvalidSplitRegionRanges .GenWithStackByArgs (errMsg )
562
573
}
563
574
}
564
575
if i == len (ranges )- 1 {
565
576
e := r .EndKey
566
577
if len (e ) == 0 || bytes .Compare (e , endKey ) > 0 {
567
578
ranges [i ].EndKey = endKey
568
579
}
580
+ // We don't need to check the end key because a limit may set before scanning regions.
569
581
}
570
582
if len (ranges [i ].StartKey ) == 0 || len (ranges [i ].EndKey ) == 0 {
571
- return errors . Errorf ("get empty start/end key in the middle of ranges" )
583
+ return dbterror . ErrInvalidSplitRegionRanges . GenWithStackByArgs ("get empty start/end key in the middle of ranges" )
572
584
}
573
585
if i > 0 && ! bytes .Equal (ranges [i - 1 ].EndKey , ranges [i ].StartKey ) {
574
- return errors .Errorf ("ranges are not continuous" )
586
+ errMsg := fmt .Sprintf ("ranges are not continuous, last end key %s, next start key %s" ,
587
+ hex .EncodeToString (ranges [i - 1 ].EndKey ), hex .EncodeToString (ranges [i ].StartKey ))
588
+ return dbterror .ErrInvalidSplitRegionRanges .GenWithStackByArgs (errMsg )
575
589
}
576
590
}
577
591
return nil
0 commit comments