-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: report error when scan region encounter hole region (#8375)
close #8358 client: report error when scan region encounter hole region - add a input parameter(OutputMustContainAllKeyRange) in the BatchScanRegionsRequest - when the new param enable and find the result doesn't contain all key range(input), it will return an error to user - add Merge() method to merge the continuous KeyRanges - pull out the scanRegion function and add unit tests for it Signed-off-by: okJiang <819421878@qq.com> Co-authored-by: ti-chi-bot[bot] <108142056+ti-chi-bot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1ad446e
commit 0b5ed0f
Showing
15 changed files
with
417 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// Copyright 2024 TiKV Project Authors. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package core | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestMergeKeyRanges(t *testing.T) { | ||
re := require.New(t) | ||
|
||
testCases := []struct { | ||
name string | ||
input []*KeyRange | ||
expect []*KeyRange | ||
}{ | ||
{ | ||
name: "empty", | ||
input: []*KeyRange{}, | ||
expect: []*KeyRange{}, | ||
}, | ||
{ | ||
name: "single", | ||
input: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("b")}, | ||
}, | ||
expect: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("b")}, | ||
}, | ||
}, | ||
{ | ||
name: "non-overlapping", | ||
input: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("b")}, | ||
{StartKey: []byte("c"), EndKey: []byte("d")}, | ||
}, | ||
expect: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("b")}, | ||
{StartKey: []byte("c"), EndKey: []byte("d")}, | ||
}, | ||
}, | ||
{ | ||
name: "continuous", | ||
input: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("b")}, | ||
{StartKey: []byte("b"), EndKey: []byte("c")}, | ||
}, | ||
expect: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("c")}, | ||
}, | ||
}, | ||
{ | ||
name: "boundless 1", | ||
input: []*KeyRange{ | ||
{StartKey: nil, EndKey: []byte("b")}, | ||
{StartKey: []byte("b"), EndKey: []byte("c")}, | ||
}, | ||
expect: []*KeyRange{ | ||
{StartKey: nil, EndKey: []byte("c")}, | ||
}, | ||
}, | ||
{ | ||
name: "boundless 2", | ||
input: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: []byte("b")}, | ||
{StartKey: []byte("b"), EndKey: nil}, | ||
}, | ||
expect: []*KeyRange{ | ||
{StartKey: []byte("a"), EndKey: nil}, | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
rs := &KeyRanges{krs: tc.input} | ||
rs.Merge() | ||
re.Equal(tc.expect, rs.Ranges(), tc.name) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.