Skip to content

Commit

Permalink
Fix data race in keyspace event watcher (#16683)
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <manan@planetscale.com>
  • Loading branch information
GuptaManan100 committed Aug 29, 2024
1 parent e89f684 commit 357b2b3
Showing 1 changed file with 8 additions and 1 deletion.
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

0 comments on commit 357b2b3

Please sign in to comment.