From 075464afb5691f4049c863567e797f52c58e211b Mon Sep 17 00:00:00 2001 From: JmPotato Date: Fri, 15 Sep 2023 11:35:25 +0800 Subject: [PATCH] Return error if the split keyspace list is empty Signed-off-by: JmPotato --- pkg/keyspace/tso_keyspace_group.go | 4 ++++ pkg/keyspace/tso_keyspace_group_test.go | 3 +-- pkg/keyspace/util.go | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/pkg/keyspace/tso_keyspace_group.go b/pkg/keyspace/tso_keyspace_group.go index ac5b035ae3f..a092e5b18a6 100644 --- a/pkg/keyspace/tso_keyspace_group.go +++ b/pkg/keyspace/tso_keyspace_group.go @@ -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 { diff --git a/pkg/keyspace/tso_keyspace_group_test.go b/pkg/keyspace/tso_keyspace_group_test.go index 5f01146eb96..993923d2fd7 100644 --- a/pkg/keyspace/tso_keyspace_group_test.go +++ b/pkg/keyspace/tso_keyspace_group_test.go @@ -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}, diff --git a/pkg/keyspace/util.go b/pkg/keyspace/util.go index 6042a0b23be..aa8d0f350ea 100644 --- a/pkg/keyspace/util.go +++ b/pkg/keyspace/util.go @@ -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.