Skip to content

Commit

Permalink
Return error if the split keyspace list is empty
Browse files Browse the repository at this point in the history
Signed-off-by: JmPotato <[email protected]>
  • Loading branch information
JmPotato committed Sep 15, 2023
1 parent e295e62 commit 075464a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,10 @@ func buildSplitKeyspaces(
newKeyspaceMap[keyspace] = struct{}{}
}
}
// Check if the new keyspace list is empty.
if len(newSplit) == 0 {
return nil, nil, ErrKeyspaceGroupWithEmptyKeyspace
}
// Get the split keyspace list for the old keyspace group.
oldSplit := make([]uint32, 0, oldNum-len(newSplit))
for _, keyspace := range old {
Expand Down
3 changes: 1 addition & 2 deletions pkg/keyspace/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,8 +542,7 @@ func TestBuildSplitKeyspaces(t *testing.T) {
old: []uint32{1, 2, 3, 4, 5},
startKeyspaceID: 7,
endKeyspaceID: 10,
expectedOld: []uint32{1, 2, 3, 4, 5},
expectedNew: []uint32{},
err: ErrKeyspaceGroupWithEmptyKeyspace,
},
{
old: []uint32{1, 2, 3, 4, 5},
Expand Down
2 changes: 2 additions & 0 deletions pkg/keyspace/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ var (
ErrNodeNotInKeyspaceGroup = errors.New("the tso node is not in this keyspace group")
// ErrKeyspaceGroupNotEnoughReplicas is used to indicate not enough replicas in the keyspace group.
ErrKeyspaceGroupNotEnoughReplicas = errors.New("not enough replicas in the keyspace group")
// ErrKeyspaceGroupWithEmptyKeyspace is used to indicate keyspace group with empty keyspace.
ErrKeyspaceGroupWithEmptyKeyspace = errors.New("keyspace group with empty keyspace")
// ErrModifyDefaultKeyspaceGroup is used to indicate that default keyspace group cannot be modified.
ErrModifyDefaultKeyspaceGroup = errors.New("default keyspace group cannot be modified")
// ErrNoAvailableNode is used to indicate no available node in the keyspace group.
Expand Down

0 comments on commit 075464a

Please sign in to comment.