From 6afbcec08960fd9257b1d442958717ba373383d1 Mon Sep 17 00:00:00 2001 From: JmPotato Date: Thu, 15 Jun 2023 12:21:08 +0800 Subject: [PATCH] keyspace: prohibit merging the default keyspace group (#6606) ref tikv/pd#6589 Prohibit merging the default keyspace group. Signed-off-by: JmPotato --- pkg/keyspace/tso_keyspace_group.go | 3 +++ pkg/keyspace/tso_keyspace_group_test.go | 3 +++ pkg/keyspace/util.go | 2 ++ 3 files changed, 8 insertions(+) diff --git a/pkg/keyspace/tso_keyspace_group.go b/pkg/keyspace/tso_keyspace_group.go index c58dac46128..f208cd96b79 100644 --- a/pkg/keyspace/tso_keyspace_group.go +++ b/pkg/keyspace/tso_keyspace_group.go @@ -773,6 +773,9 @@ func (m *GroupManager) MergeKeyspaceGroups(mergeTargetID uint32, mergeList []uin if (mergeListNum+1)*2 > maxEtcdTxnOps { return ErrExceedMaxEtcdTxnOps } + if slice.Contains(mergeList, utils.DefaultKeyspaceGroupID) { + return ErrModifyDefaultKeyspaceGroup + } var ( groups = make(map[uint32]*endpoint.KeyspaceGroup, mergeListNum+1) mergeTargetKg *endpoint.KeyspaceGroup diff --git a/pkg/keyspace/tso_keyspace_group_test.go b/pkg/keyspace/tso_keyspace_group_test.go index f4f8bcd69ff..8d2f6f6f034 100644 --- a/pkg/keyspace/tso_keyspace_group_test.go +++ b/pkg/keyspace/tso_keyspace_group_test.go @@ -394,4 +394,7 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupMerge() { // merge with the number of keyspace groups exceeds the limit err = suite.kgm.MergeKeyspaceGroups(1, make([]uint32, maxEtcdTxnOps/2)) re.ErrorIs(err, ErrExceedMaxEtcdTxnOps) + // merge the default keyspace group + err = suite.kgm.MergeKeyspaceGroups(1, []uint32{utils.DefaultKeyspaceGroupID}) + re.ErrorIs(err, ErrModifyDefaultKeyspaceGroup) } diff --git a/pkg/keyspace/util.go b/pkg/keyspace/util.go index 041e8fc0494..fa661780a99 100644 --- a/pkg/keyspace/util.go +++ b/pkg/keyspace/util.go @@ -62,6 +62,8 @@ var ( ErrKeyspaceNotInKeyspaceGroup = errors.New("keyspace 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") + // 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. ErrNoAvailableNode = errors.New("no available node") // ErrExceedMaxEtcdTxnOps is used to indicate the number of etcd txn operations exceeds the limit.