Skip to content

Commit

Permalink
mcs, tso: fix split and split-range command bugs. (tikv#6732)
Browse files Browse the repository at this point in the history
close tikv#6687, close tikv#6731

Fix split and split-range command bugs.

Signed-off-by: Bin Shi <binshi.bing@gmail.com>
  • Loading branch information
binshi-bing authored and rleungx committed Aug 2, 2023
1 parent bb1e511 commit 578aeb1
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
16 changes: 14 additions & 2 deletions pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,17 @@ func buildSplitKeyspaces(
oldSplit = append(oldSplit, keyspace)
}
}
return oldSplit, new, nil
// If newNum != len(newKeyspaceMap), it means the provided new keyspace list contains
// duplicate keyspaces, and we need to dedup them (https://github.com/tikv/pd/issues/6687);
// otherwise, we can just return the old split and new keyspace list.
if newNum == len(newKeyspaceMap) {
return oldSplit, new, nil
}
newSplit := make([]uint32, 0, len(newKeyspaceMap))
for keyspace := range newKeyspaceMap {
newSplit = append(newSplit, keyspace)
}
return oldSplit, newSplit, nil
}
// Split according to the start and end keyspace ID.
if startKeyspaceID == 0 && endKeyspaceID == 0 {
Expand All @@ -628,7 +638,9 @@ func buildSplitKeyspaces(
)
for _, keyspace := range old {
if keyspace == utils.DefaultKeyspaceID {
return nil, nil, ErrModifyDefaultKeyspace
// The source keyspace group must be the default keyspace group and we always keep the default
// keyspace in the default keyspace group.
continue
}
if startKeyspaceID <= keyspace && keyspace <= endKeyspaceID {
newSplit = append(newSplit, keyspace)
Expand Down
41 changes: 41 additions & 0 deletions pkg/keyspace/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,27 +483,68 @@ func TestBuildSplitKeyspaces(t *testing.T) {
new: []uint32{6},
err: ErrKeyspaceNotInKeyspaceGroup,
},
{
old: []uint32{1, 2},
new: []uint32{2, 2},
expectedOld: []uint32{1},
expectedNew: []uint32{2},
},
{
old: []uint32{0, 1, 2, 3, 4, 5},
startKeyspaceID: 2,
endKeyspaceID: 4,
expectedOld: []uint32{0, 1, 5},
expectedNew: []uint32{2, 3, 4},
},
{
old: []uint32{0, 1, 2, 3, 4, 5},
startKeyspaceID: 0,
endKeyspaceID: 4,
expectedOld: []uint32{0, 5},
expectedNew: []uint32{1, 2, 3, 4},
},
{
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 2,
endKeyspaceID: 4,
expectedOld: []uint32{1, 5},
expectedNew: []uint32{2, 3, 4},
},
{
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 5,
endKeyspaceID: 6,
expectedOld: []uint32{1, 2, 3, 4},
expectedNew: []uint32{5},
},
{
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 2,
endKeyspaceID: 6,
expectedOld: []uint32{1},
expectedNew: []uint32{2, 3, 4, 5},
},
{
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 1,
endKeyspaceID: 1,
expectedOld: []uint32{2, 3, 4, 5},
expectedNew: []uint32{1},
},
{
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 0,
endKeyspaceID: 6,
expectedOld: []uint32{},
expectedNew: []uint32{1, 2, 3, 4, 5},
},
{
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 7,
endKeyspaceID: 10,
expectedOld: []uint32{1, 2, 3, 4, 5},
expectedNew: []uint32{},
},
{
old: []uint32{1, 2, 3, 4, 5},
err: ErrKeyspaceNotInKeyspaceGroup,
Expand Down

0 comments on commit 578aeb1

Please sign in to comment.