From e30f73ea118e639490ca57b7e9b79259bdb78605 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 29 Aug 2024 16:46:35 +0530 Subject: [PATCH] feat: fix data race Signed-off-by: Manan Gupta --- go/vt/discovery/keyspace_events.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/go/vt/discovery/keyspace_events.go b/go/vt/discovery/keyspace_events.go index 036d4f3ad14..3de31ea6d9a 100644 --- a/go/vt/discovery/keyspace_events.go +++ b/go/vt/discovery/keyspace_events.go @@ -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() @@ -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