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

keyspace: unexpect dead code in saveKeyspaceGroups #6587

Closed
lhy1024 opened this issue Jun 12, 2023 · 1 comment
Closed

keyspace: unexpect dead code in saveKeyspaceGroups #6587

lhy1024 opened this issue Jun 12, 2023 · 1 comment
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@lhy1024
Copy link
Contributor

lhy1024 commented Jun 12, 2023

Enhancement Task

func (m *GroupManager) saveKeyspaceGroups(keyspaceGroups []*endpoint.KeyspaceGroup, overwrite bool) error {
return m.store.RunInTxn(m.ctx, func(txn kv.Txn) error {
for _, keyspaceGroup := range keyspaceGroups {
// Check if keyspace group has already existed.
oldKG, err := m.store.LoadKeyspaceGroup(txn, keyspaceGroup.ID)
if err != nil {
return err
}
if oldKG != nil && !overwrite {
return ErrKeyspaceGroupExists
}
if oldKG.IsSplitting() && overwrite {
return ErrKeyspaceGroupInSplit
}
newKG := &endpoint.KeyspaceGroup{
ID: keyspaceGroup.ID,
UserKind: keyspaceGroup.UserKind,
Members: keyspaceGroup.Members,
Keyspaces: keyspaceGroup.Keyspaces,
}
if oldKG.IsSplitting() {
newKG.SplitState = &endpoint.SplitState{
SplitSource: oldKG.SplitState.SplitSource,
}
}
err = m.store.SaveKeyspaceGroup(txn, newKG)
if err != nil {
return err
}
}
return nil
})
}

when oldKG.IsSplitting() is true, it means oldKG != nil is also true, so

  1. when overwrite is false, the code will return with ErrKeyspaceGroupExists
  2. when overwrite is true, the code will return with ErrKeyspaceGroupInSplit

so we cannot touch

if oldKG.IsSplitting() {
newKG.SplitState = &endpoint.SplitState{
SplitSource: oldKG.SplitState.SplitSource,
}
}

@lhy1024 lhy1024 added the type/enhancement The issue or PR belongs to an enhancement. label Jun 12, 2023
@lhy1024
Copy link
Contributor Author

lhy1024 commented Jun 13, 2023

closed by #6584

@lhy1024 lhy1024 closed this as completed Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

No branches or pull requests

1 participant