Skip to content

Commit

Permalink
br: update log description for split check (#30763)
Browse files Browse the repository at this point in the history
  • Loading branch information
3pointer authored Dec 16, 2021
1 parent 1e5e869 commit 83af272
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 4 deletions.
8 changes: 4 additions & 4 deletions br/pkg/restore/split.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,18 +339,18 @@ func (rs *RegionSplitter) ScatterRegions(ctx context.Context, newRegions []*Regi
})
}

func checkRegionConsistency(startKey, endKey []byte, regions []*RegionInfo) error {
func CheckRegionConsistency(startKey, endKey []byte, regions []*RegionInfo) error {
// current pd can't guarantee the consistency of returned regions
if len(regions) == 0 {
return errors.Annotatef(berrors.ErrPDBatchScanRegion, "scan region return empty result, startKey: %s, endkey: %s",
return errors.Annotatef(berrors.ErrPDBatchScanRegion, "scan region return empty result, startKey: %s, endKey: %s",
redact.Key(startKey), redact.Key(endKey))
}

if bytes.Compare(regions[0].Region.StartKey, startKey) > 0 {
return errors.Annotatef(berrors.ErrPDBatchScanRegion, "first region's startKey > startKey, startKey: %s, regionStartKey: %s",
redact.Key(startKey), redact.Key(regions[0].Region.StartKey))
} else if len(regions[len(regions)-1].Region.EndKey) != 0 && bytes.Compare(regions[len(regions)-1].Region.EndKey, endKey) < 0 {
return errors.Annotatef(berrors.ErrPDBatchScanRegion, "last region's endKey < startKey, startKey: %s, regionStartKey: %s",
return errors.Annotatef(berrors.ErrPDBatchScanRegion, "last region's endKey < endKey, endKey: %s, regionEndKey: %s",
redact.Key(endKey), redact.Key(regions[len(regions)-1].Region.EndKey))
}

Expand Down Expand Up @@ -398,7 +398,7 @@ func PaginateScanRegion(
break
}
}
if err := checkRegionConsistency(startKey, endKey, regions); err != nil {
if err := CheckRegionConsistency(startKey, endKey, regions); err != nil {
log.Warn("failed to scan region, retrying", logutil.ShortError(err))
return err
}
Expand Down
67 changes: 67 additions & 0 deletions br/pkg/restore/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,3 +445,70 @@ func (s *testRangeSuite) TestNeedSplit(c *C) {
// Out of region
c.Assert(restore.NeedSplit([]byte("e"), regions), IsNil)
}

func (s *testRangeSuite) TestRegionConsistency(c *C) {
cases := []struct {
startKey []byte
endKey []byte
err string
regions []*restore.RegionInfo
}{
{
codec.EncodeBytes([]byte{}, []byte("a")),
codec.EncodeBytes([]byte{}, []byte("a")),
"scan region return empty result, startKey: (.*?), endKey: (.*?)",
[]*restore.RegionInfo{},
},
{
codec.EncodeBytes([]byte{}, []byte("a")),
codec.EncodeBytes([]byte{}, []byte("a")),
"first region's startKey > startKey, startKey: (.*?), regionStartKey: (.*?)",
[]*restore.RegionInfo{
{
Region: &metapb.Region{
StartKey: codec.EncodeBytes([]byte{}, []byte("b")),
EndKey: codec.EncodeBytes([]byte{}, []byte("d")),
},
},
},
},
{
codec.EncodeBytes([]byte{}, []byte("b")),
codec.EncodeBytes([]byte{}, []byte("e")),
"last region's endKey < endKey, endKey: (.*?), regionEndKey: (.*?)",
[]*restore.RegionInfo{
{
Region: &metapb.Region{
StartKey: codec.EncodeBytes([]byte{}, []byte("b")),
EndKey: codec.EncodeBytes([]byte{}, []byte("d")),
},
},
},
},
{
codec.EncodeBytes([]byte{}, []byte("c")),
codec.EncodeBytes([]byte{}, []byte("e")),
"region endKey not equal to next region startKey(.*?)",
[]*restore.RegionInfo{
{
Region: &metapb.Region{
StartKey: codec.EncodeBytes([]byte{}, []byte("b")),
EndKey: codec.EncodeBytes([]byte{}, []byte("d")),
},
},
{
Region: &metapb.Region{
StartKey: codec.EncodeBytes([]byte{}, []byte("e")),
EndKey: codec.EncodeBytes([]byte{}, []byte("f")),
},
},
},
},
}
for _, ca := range cases {
c.Assert(
restore.CheckRegionConsistency(ca.startKey, ca.endKey, ca.regions),
ErrorMatches,
ca.err)
}
}

0 comments on commit 83af272

Please sign in to comment.