Skip to content

Commit e30f73e

Browse files
committed
feat: fix data race
Signed-off-by: Manan Gupta <manan@planetscale.com>
1 parent e89f684 commit e30f73e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

go/vt/discovery/keyspace_events.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ type keyspaceState struct {
118118
moveTablesState *MoveTablesState
119119
}
120120

121+
// isConsistent returns whether the keyspace is currently consistent or not.
122+
func (kss *keyspaceState) isConsistent() bool {
123+
kss.mu.Lock()
124+
defer kss.mu.Unlock()
125+
return kss.consistent
126+
}
127+
121128
// Format prints the internal state for this keyspace for debug purposes.
122129
func (kss *keyspaceState) Format(f fmt.State, verb rune) {
123130
kss.mu.Lock()
@@ -752,7 +759,7 @@ func (kew *KeyspaceEventWatcher) WaitForConsistentKeyspaces(ctx context.Context,
752759
kss := kew.getKeyspaceStatus(ctx, ks)
753760
// If kss is nil, then it must be deleted. In that case too it is fine for us to consider
754761
// it consistent since the keyspace has been deleted.
755-
if kss == nil || kss.consistent {
762+
if kss == nil || kss.isConsistent() {
756763
keyspaces[i] = ""
757764
} else {
758765
allConsistent = false

0 commit comments

Comments
 (0)