Skip to content

Commit

Permalink
Fix split and split-range command bugs.
Browse files Browse the repository at this point in the history
Signed-off-by: Bin Shi <binshi.bing@gmail.com>
  • Loading branch information
binshi-bing committed Jun 30, 2023
1 parent 0fe5eb4 commit 5dd5562
Show file tree
Hide file tree
Showing 2 changed files with 34 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 @@ -622,7 +622,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 @@ -634,7 +644,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
20 changes: 20 additions & 0 deletions pkg/keyspace/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,26 @@ 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,
Expand Down

0 comments on commit 5dd5562

Please sign in to comment.