Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions br/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@
ErrPDInvalidResponse = errors.Normalize("PD invalid response", errors.RFCCodeText("BR:PD:ErrPDInvalidResponse"))
ErrPDBatchScanRegion = errors.Normalize("batch scan region", errors.RFCCodeText("BR:PD:ErrPDBatchScanRegion"))
ErrPDUnknownScatterResult = errors.Normalize("failed to wait region scattered", errors.RFCCodeText("BR:PD:ErrPDUknownScatterResult"))
<<<<<<< HEAD

Check failure on line 51 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

syntax error: unexpected <<, expected name

Check failure on line 51 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

syntax error: unexpected <<, expected name

Check failure on line 51 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

syntax error: unexpected <<, expected name

Check failure on line 51 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

syntax error: unexpected <<, expected name

Check failure on line 51 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

syntax error: unexpected <<, expected name

Check failure on line 51 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

syntax error: unexpected <<, expected name
ErrPDSplitFailed = errors.Normalize("failed to wait region splitted", errors.RFCCodeText("BR:PD:ErrPDUknownScatterResult"))
=======

Check failure on line 53 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

syntax error: unexpected ==, expected name

Check failure on line 53 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

syntax error: unexpected ==, expected name

Check failure on line 53 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

syntax error: unexpected ==, expected name

Check failure on line 53 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

syntax error: unexpected ==, expected name

Check failure on line 53 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

syntax error: unexpected ==, expected name

Check failure on line 53 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

syntax error: unexpected ==, expected name
ErrPDNotFullyScatter = errors.Normalize("pd not fully scattered", errors.RFCCodeText("BR:PD:ErrPDNotFullyScatter"))

Check failure on line 54 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

syntax error: unexpected comma in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 54 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

syntax error: unexpected comma in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 54 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

syntax error: unexpected comma in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 54 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

syntax error: unexpected comma in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 54 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

syntax error: unexpected comma in grouped declaration; possibly missing semicolon or newline or )

Check failure on line 54 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

syntax error: unexpected comma in grouped declaration; possibly missing semicolon or newline or )
ErrPDSplitFailed = errors.Normalize("failed to wait region split", errors.RFCCodeText("BR:PD:ErrPDUknownScatterResult"))
>>>>>>> bc50e0d3e23 (region scatter client: retry scatter regions when finished percentage is not 100. (#64884))

Check failure on line 56 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

invalid character U+0023 '#'

Check failure on line 56 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

invalid character U+0023 '#'

Check failure on line 56 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

invalid character U+0023 '#'

Check failure on line 56 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for FreeBSD job

invalid character U+0023 '#'

Check failure on line 56 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for ubuntu-latest

invalid character U+0023 '#'

Check failure on line 56 in br/pkg/errors/errors.go

View workflow job for this annotation

GitHub Actions / Compile for macos-latest

invalid character U+0023 '#'
ErrPDRegionsNotFullyScatter = errors.Normalize("regions not fully scattered", errors.RFCCodeText("BR:PD:ErrPDRegionsNotFullyScatter"))

ErrBackupChecksumMismatch = errors.Normalize("backup checksum mismatch", errors.RFCCodeText("BR:Backup:ErrBackupChecksumMismatch"))
Expand Down
2 changes: 1 addition & 1 deletion br/pkg/restore/split/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ go_test(
],
embed = [":split"],
flaky = True,
shard_count = 28,
shard_count = 29,
deps = [
"//br/pkg/errors",
"//br/pkg/restore/utils",
Expand Down
22 changes: 22 additions & 0 deletions br/pkg/restore/split/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,13 @@ func (c *pdClient) needScatter(ctx context.Context) bool {
func (c *pdClient) scatterRegions(ctx context.Context, newRegions []*RegionInfo) error {
log.Info("scatter regions", zap.Int("regions", len(newRegions)))
// the retry is for the temporary network errors during sending request.
<<<<<<< HEAD
return utils.WithRetry(ctx, func() error {
err := c.tryScatterRegions(ctx, newRegions)
=======
err := utils.WithRetry(ctx, func() error {
failedRegionsID, err := c.tryScatterRegions(ctx, newRegions)
>>>>>>> bc50e0d3e23 (region scatter client: retry scatter regions when finished percentage is not 100. (#64884))
// if err is unsupported, we need to fallback to the old method.
// ErrPDRegionsNotFullyScatter means the regions are not fully scattered,
// in new version of PD, the scatter regions API will return the failed regions id,
Expand Down Expand Up @@ -227,11 +232,28 @@ func (c *pdClient) tryScatterRegions(ctx context.Context, regionInfo []*RegionIn
return errors.Annotatef(berrors.ErrPDInvalidResponse,
"pd returns error during batch scattering: %s", pbErr)
}
<<<<<<< HEAD
if finished := resp.GetFinishedPercentage(); finished < 100 {
return errors.Annotatef(berrors.ErrPDRegionsNotFullyScatter, "scatter finished percentage %d less than 100", finished)
}

return nil
=======

if len(resp.FailedRegionsId) > 0 {
failedRegionsID := make(map[uint64]struct{})
for _, id := range resp.FailedRegionsId {
failedRegionsID[id] = struct{}{}
}
return failedRegionsID, nil
}

if finished := resp.GetFinishedPercentage(); finished < 100 {
return nil, errors.Annotatef(berrors.ErrPDRegionsNotFullyScatter, "scatter finished percentage %d less than 100", finished)
}

return nil, nil
>>>>>>> bc50e0d3e23 (region scatter client: retry scatter regions when finished percentage is not 100. (#64884))
}

func (c *pdClient) GetStore(ctx context.Context, storeID uint64) (*metapb.Store, error) {
Expand Down
14 changes: 14 additions & 0 deletions br/pkg/restore/split/mock_pd_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ type MockPDClientForSplit struct {
scatterRegions struct {
notImplemented bool
regionCount int
<<<<<<< HEAD
=======
failedCount int
>>>>>>> bc50e0d3e23 (region scatter client: retry scatter regions when finished percentage is not 100. (#64884))
finishedPercentage int
}
getOperator struct {
Expand Down Expand Up @@ -379,6 +383,16 @@ func (c *MockPDClientForSplit) ScatterRegions(_ context.Context, regionIDs []uin
if c.scatterRegions.notImplemented {
return nil, status.Error(codes.Unimplemented, "Ah, yep")
}
<<<<<<< HEAD
=======
if c.scatterRegions.failedCount > 0 {
c.scatterRegions.failedCount--
return &pdpb.ScatterRegionResponse{
FinishedPercentage: 0,
FailedRegionsId: regionIDs[:],
}, nil
}
>>>>>>> bc50e0d3e23 (region scatter client: retry scatter regions when finished percentage is not 100. (#64884))
c.scatterRegions.regionCount += len(regionIDs) * c.scatterRegions.finishedPercentage / 100
return &pdpb.ScatterRegionResponse{FinishedPercentage: uint64(c.scatterRegions.finishedPercentage)}, nil
}
Expand Down
41 changes: 41 additions & 0 deletions br/pkg/restore/split/split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1075,3 +1075,44 @@ func TestSplitPoint2(t *testing.T) {
})
require.NoError(t, err)
}

func TestRegionsNotFullyScatter(t *testing.T) {
mockClient := NewMockPDClientForSplit()
client := pdClient{
needScatterVal: true,
client: mockClient,
}
client.needScatterInit.Do(func() {})
ctx := context.Background()

regions := []*RegionInfo{
{
Region: &metapb.Region{
Id: 1,
},
},
{
Region: &metapb.Region{
Id: 2,
},
},
}
err := client.scatterRegions(ctx, regions)
require.NoError(t, err)
require.Equal(t, 2, mockClient.scatterRegions.regionCount)
require.Len(t, mockClient.scatterRegion.count, 0)

// simulate that one region is not fully scattered when scatterRegions
mockClient.scatterRegions.finishedPercentage = 50
err = client.scatterRegions(ctx, regions)
require.NoError(t, err)
require.Equal(t, 2+1, mockClient.scatterRegions.regionCount)
require.Equal(t, map[uint64]int{1: 1, 2: 1}, mockClient.scatterRegion.count)

// simulate that the regions is not fully scattered when scatterRegion
mockClient.scatterRegion.eachRegionFailBefore = 7
err = client.scatterRegions(ctx, regions)
require.NoError(t, err)
require.Equal(t, 2+1+1, mockClient.scatterRegions.regionCount)
require.Equal(t, map[uint64]int{1: 1 + 7, 2: 1 + 7}, mockClient.scatterRegion.count)
}
5 changes: 5 additions & 0 deletions errors.toml
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,11 @@ error = '''
regions not fully scattered
'''

["BR:PD:ErrPDRegionsNotFullyScatter"]
error = '''
regions not fully scattered
'''

["BR:PD:ErrPDUknownScatterResult"]
error = '''
failed to wait region splitted
Expand Down
Loading