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

Fix data race in keyspace event watcher #16683

Merged
merged 1 commit into from
Aug 29, 2024
Merged
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
9 changes: 8 additions & 1 deletion go/vt/discovery/keyspace_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ type keyspaceState struct {
moveTablesState *MoveTablesState
}

// isConsistent returns whether the keyspace is currently consistent or not.
func (kss *keyspaceState) isConsistent() bool {
kss.mu.Lock()
defer kss.mu.Unlock()
return kss.consistent
}

// Format prints the internal state for this keyspace for debug purposes.
func (kss *keyspaceState) Format(f fmt.State, verb rune) {
kss.mu.Lock()
Expand Down Expand Up @@ -752,7 +759,7 @@ func (kew *KeyspaceEventWatcher) WaitForConsistentKeyspaces(ctx context.Context,
kss := kew.getKeyspaceStatus(ctx, ks)
// If kss is nil, then it must be deleted. In that case too it is fine for us to consider
// it consistent since the keyspace has been deleted.
if kss == nil || kss.consistent {
if kss == nil || kss.isConsistent() {
keyspaces[i] = ""
} else {
allConsistent = false
Expand Down
Loading