Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add group id to error logs #6695

Merged
merged 2 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pkg/keyspace/keyspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,10 @@ func (manager *Manager) PatrolKeyspaceAssignment(startKeyspaceID, endKeyspaceID
return errors.Errorf("default keyspace group %d not found", utils.DefaultKeyspaceGroupID)
}
if defaultKeyspaceGroup.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(utils.DefaultKeyspaceGroupID)
}
if defaultKeyspaceGroup.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(utils.DefaultKeyspaceGroupID)
}
keyspaces, err := manager.store.LoadRangeKeyspace(txn, manager.nextPatrolStartID, maxEtcdTxnOps)
if err != nil {
Expand Down
69 changes: 36 additions & 33 deletions pkg/keyspace/tso_keyspace_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ func (m *GroupManager) DeleteKeyspaceGroupByID(id uint32) (*endpoint.KeyspaceGro
return nil
}
if kg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(id)
}
return m.store.DeleteKeyspaceGroup(txn, id)
}); err != nil {
Expand Down Expand Up @@ -339,10 +339,10 @@ func (m *GroupManager) saveKeyspaceGroups(keyspaceGroups []*endpoint.KeyspaceGro
return ErrKeyspaceGroupExists
}
if oldKG.IsSplitting() && overwrite {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(keyspaceGroup.ID)
}
if oldKG.IsMerging() && overwrite {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(keyspaceGroup.ID)
}
newKG := &endpoint.KeyspaceGroup{
ID: keyspaceGroup.ID,
Expand Down Expand Up @@ -414,13 +414,13 @@ func (m *GroupManager) UpdateKeyspaceForGroup(userKind endpoint.UserKind, groupI
func (m *GroupManager) updateKeyspaceForGroupLocked(userKind endpoint.UserKind, groupID uint64, keyspaceID uint32, mutation int) error {
kg := m.groups[userKind].Get(uint32(groupID))
if kg == nil {
return errors.Errorf("keyspace group %d not found", groupID)
return ErrKeyspaceGroupNotExists(uint32(groupID))
}
if kg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(uint32(groupID))
}
if kg.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(uint32(groupID))
}

changed := false
Expand Down Expand Up @@ -473,11 +473,14 @@ func (m *GroupManager) UpdateKeyspaceGroup(oldGroupID, newGroupID string, oldUse
if newKG == nil {
return errors.Errorf("keyspace group %s not found in %s group", newGroupID, newUserKind)
}
if oldKG.IsSplitting() || newKG.IsSplitting() {
return ErrKeyspaceGroupInSplit
}
if oldKG.IsMerging() || newKG.IsMerging() {
return ErrKeyspaceGroupInMerging
if oldKG.IsSplitting() {
return ErrKeyspaceGroupInSplit(uint32(oldID))
} else if newKG.IsSplitting() {
return ErrKeyspaceGroupInSplit(uint32(newID))
} else if oldKG.IsMerging() {
return ErrKeyspaceGroupInMerging(uint32(oldID))
} else if newKG.IsMerging() {
return ErrKeyspaceGroupInMerging(uint32(newID))
}

var updateOld, updateNew bool
Expand Down Expand Up @@ -523,15 +526,15 @@ func (m *GroupManager) SplitKeyspaceGroupByID(
return err
}
if splitSourceKg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(splitSourceID)
}
// A keyspace group can not take part in multiple split processes.
if splitSourceKg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(splitSourceID)
}
// A keyspace group can not be split when it is in merging.
if splitSourceKg.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(splitSourceID)
}
// Check if the source keyspace group has enough replicas.
if len(splitSourceKg.Members) < utils.DefaultKeyspaceGroupReplicaCount {
Expand Down Expand Up @@ -661,22 +664,22 @@ func (m *GroupManager) FinishSplitKeyspaceByID(splitTargetID uint32) error {
return err
}
if splitTargetKg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(splitTargetID)
}
// Check if it's in the split state.
if !splitTargetKg.IsSplitTarget() {
return ErrKeyspaceGroupNotInSplit
return ErrKeyspaceGroupNotInSplit(splitTargetID)
}
// Load the split source keyspace group then.
splitSourceKg, err = m.store.LoadKeyspaceGroup(txn, splitTargetKg.SplitSource())
if err != nil {
return err
}
if splitSourceKg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(splitTargetKg.SplitSource())
}
if !splitSourceKg.IsSplitSource() {
return ErrKeyspaceGroupNotInSplit
return ErrKeyspaceGroupNotInSplit(splitTargetKg.SplitSource())
}
splitTargetKg.SplitState = nil
splitSourceKg.SplitState = nil
Expand Down Expand Up @@ -721,13 +724,13 @@ func (m *GroupManager) AllocNodesForKeyspaceGroup(id uint32, desiredReplicaCount
return err
}
if kg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(id)
}
if kg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(id)
}
if kg.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(id)
}
exists := make(map[string]struct{})
for _, member := range kg.Members {
Expand Down Expand Up @@ -783,13 +786,13 @@ func (m *GroupManager) SetNodesForKeyspaceGroup(id uint32, nodes []string) error
return err
}
if kg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(id)
}
if kg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(id)
}
if kg.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(id)
}
members := make([]endpoint.KeyspaceGroupMember, 0, len(nodes))
for _, node := range nodes {
Expand Down Expand Up @@ -820,13 +823,13 @@ func (m *GroupManager) SetPriorityForKeyspaceGroup(id uint32, node string, prior
return err
}
if kg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(id)
}
if kg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(id)
}
if kg.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(id)
}
inKeyspaceGroup := false
members := make([]endpoint.KeyspaceGroupMember, 0, len(kg.Members))
Expand Down Expand Up @@ -891,15 +894,15 @@ func (m *GroupManager) MergeKeyspaceGroups(mergeTargetID uint32, mergeList []uin
return err
}
if kg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(kgID)
}
// A keyspace group can not be merged if it's in splitting.
if kg.IsSplitting() {
return ErrKeyspaceGroupInSplit
return ErrKeyspaceGroupInSplit(kgID)
}
// A keyspace group can not be split when it is in merging.
if kg.IsMerging() {
return ErrKeyspaceGroupInMerging
return ErrKeyspaceGroupInMerging(kgID)
}
groups[kgID] = kg
}
Expand Down Expand Up @@ -955,11 +958,11 @@ func (m *GroupManager) FinishMergeKeyspaceByID(mergeTargetID uint32) error {
return err
}
if mergeTargetKg == nil {
return ErrKeyspaceGroupNotExists
return ErrKeyspaceGroupNotExists(mergeTargetID)
}
// Check if it's in the merging state.
if !mergeTargetKg.IsMergeTarget() {
return ErrKeyspaceGroupNotInMerging
return ErrKeyspaceGroupNotInMerging(mergeTargetID)
}
// Make sure all merging keyspace groups are deleted.
for _, kgID := range mergeTargetKg.MergeState.MergeList {
Expand All @@ -968,7 +971,7 @@ func (m *GroupManager) FinishMergeKeyspaceByID(mergeTargetID uint32) error {
return err
}
if kg != nil {
return ErrKeyspaceGroupNotInMerging
return ErrKeyspaceGroupNotInMerging(kgID)
}
}
mergeTargetKg.MergeState = nil
Expand Down
18 changes: 9 additions & 9 deletions pkg/keyspace/tso_keyspace_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,25 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() {

// finish the split of the keyspace group 2
err = suite.kgm.FinishSplitKeyspaceByID(2)
re.ErrorIs(err, ErrKeyspaceGroupNotInSplit)
re.ErrorContains(err, ErrKeyspaceGroupNotInSplit(2).Error())
// finish the split of a non-existing keyspace group
err = suite.kgm.FinishSplitKeyspaceByID(5)
re.ErrorIs(err, ErrKeyspaceGroupNotExists)
re.ErrorContains(err, ErrKeyspaceGroupNotExists(5).Error())
// split the in-split keyspace group
err = suite.kgm.SplitKeyspaceGroupByID(2, 4, []uint32{333})
re.ErrorIs(err, ErrKeyspaceGroupInSplit)
re.ErrorContains(err, ErrKeyspaceGroupInSplit(2).Error())
// remove the in-split keyspace group
kg2, err = suite.kgm.DeleteKeyspaceGroupByID(2)
re.Nil(kg2)
re.ErrorIs(err, ErrKeyspaceGroupInSplit)
re.ErrorContains(err, ErrKeyspaceGroupInSplit(2).Error())
kg4, err = suite.kgm.DeleteKeyspaceGroupByID(4)
re.Nil(kg4)
re.ErrorIs(err, ErrKeyspaceGroupInSplit)
re.ErrorContains(err, ErrKeyspaceGroupInSplit(4).Error())
// update the in-split keyspace group
err = suite.kg.kgm.UpdateKeyspaceForGroup(endpoint.Standard, "2", 444, opAdd)
re.ErrorIs(err, ErrKeyspaceGroupInSplit)
re.ErrorContains(err, ErrKeyspaceGroupInSplit(2).Error())
err = suite.kg.kgm.UpdateKeyspaceForGroup(endpoint.Standard, "4", 444, opAdd)
re.ErrorIs(err, ErrKeyspaceGroupInSplit)
re.ErrorContains(err, ErrKeyspaceGroupInSplit(4).Error())

// finish the split of keyspace group 4
err = suite.kgm.FinishSplitKeyspaceByID(4)
Expand All @@ -314,7 +314,7 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupSplit() {

// split a non-existing keyspace group
err = suite.kgm.SplitKeyspaceGroupByID(3, 5, nil)
re.ErrorIs(err, ErrKeyspaceGroupNotExists)
re.ErrorContains(err, ErrKeyspaceGroupNotExists(3).Error())
// split into an existing keyspace group
err = suite.kgm.SplitKeyspaceGroupByID(2, 4, nil)
re.ErrorIs(err, ErrKeyspaceGroupExists)
Expand Down Expand Up @@ -442,7 +442,7 @@ func (suite *keyspaceGroupTestSuite) TestKeyspaceGroupMerge() {

// merge a non-existing keyspace group
err = suite.kgm.MergeKeyspaceGroups(4, []uint32{5})
re.ErrorIs(err, ErrKeyspaceGroupNotExists)
re.ErrorContains(err, ErrKeyspaceGroupNotExists(5).Error())
// merge with the number of keyspace groups exceeds the limit
err = suite.kgm.MergeKeyspaceGroups(1, make([]uint32, maxEtcdTxnOps/2))
re.ErrorIs(err, ErrExceedMaxEtcdTxnOps)
Expand Down
20 changes: 15 additions & 5 deletions pkg/keyspace/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,25 @@ var (
// ErrKeyspaceGroupExists indicates target keyspace group already exists.
ErrKeyspaceGroupExists = errors.New("keyspace group already exists")
// ErrKeyspaceGroupNotExists is used to indicate target keyspace group does not exist.
ErrKeyspaceGroupNotExists = errors.New("keyspace group does not exist")
ErrKeyspaceGroupNotExists = func(groupID uint32) error {
return errors.Errorf("keyspace group %v does not exist", groupID)
}
// ErrKeyspaceGroupInSplit is used to indicate target keyspace group is in split state.
ErrKeyspaceGroupInSplit = errors.New("keyspace group is in split state")
ErrKeyspaceGroupInSplit = func(groupID uint32) error {
return errors.Errorf("keyspace group %v is in split state", groupID)
}
// ErrKeyspaceGroupNotInSplit is used to indicate target keyspace group is not in split state.
ErrKeyspaceGroupNotInSplit = errors.New("keyspace group is not in split state")
ErrKeyspaceGroupNotInSplit = func(groupID uint32) error {
return errors.Errorf("keyspace group %v is not in split state", groupID)
}
// ErrKeyspaceGroupInMerging is used to indicate target keyspace group is in merging state.
ErrKeyspaceGroupInMerging = errors.New("keyspace group is in merging state")
ErrKeyspaceGroupInMerging = func(groupID uint32) error {
return errors.Errorf("keyspace group %v is in merging state", groupID)
}
// ErrKeyspaceGroupNotInMerging is used to indicate target keyspace group is not in merging state.
ErrKeyspaceGroupNotInMerging = errors.New("keyspace group is not in merging state")
ErrKeyspaceGroupNotInMerging = func(groupID uint32) error {
return errors.Errorf("keyspace group %v is not in merging state", groupID)
}
// ErrKeyspaceNotInKeyspaceGroup is used to indicate target keyspace is not in this keyspace group.
ErrKeyspaceNotInKeyspaceGroup = errors.New("keyspace is not in this keyspace group")
// ErrNodeNotInKeyspaceGroup is used to indicate the tso node is not in this keyspace group.
Expand Down