Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
Signed-off-by: lance6716 <lance6716@gmail.com>
  • Loading branch information
lance6716 committed Apr 2, 2024
1 parent 283c637 commit dcd7f5d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions br/pkg/restore/split/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,13 @@ func sendSplitRegionRequest(
return false, resp, nil
}

// batchSplitRegionsWithOrigin calls the batch split region API and groups the
// returned regions into two groups: the region with the same ID as the origin,
// and the other regions. The former does not need to be scattered while the
// latter need to be scattered.
//
// Depending on the TiKV configuration right-derive-when-split, the origin region
// can be the first return region or the last return region.
func (c *pdClient) batchSplitRegionsWithOrigin(
ctx context.Context, regionInfo *RegionInfo, keys [][]byte,
) (*RegionInfo, []*RegionInfo, error) {
Expand Down Expand Up @@ -606,11 +613,12 @@ func (c *pdClient) SplitWaitAndScatter(ctx context.Context, region *RegionInfo,
)
}

// the region with the max start key is the region need to be further split, it
// can be the leftmost region or the rightmost region.
lastRegion := newRegionsOfBatch[len(newRegionsOfBatch)-1]
if bytes.Compare(originRegion.Region.StartKey, lastRegion.Region.StartKey) < 0 {
region = lastRegion
// the region with the max start key is the region need to be further split,
// depending on the origin region is the first region or last region, we need to
// compare the origin region and the last one of new regions.
lastNewRegion := newRegionsOfBatch[len(newRegionsOfBatch)-1]
if bytes.Compare(originRegion.Region.StartKey, lastNewRegion.Region.StartKey) < 0 {
region = lastNewRegion
} else {
region = originRegion
}
Expand Down

0 comments on commit dcd7f5d

Please sign in to comment.