From 01f621add0597fddf0e32f074ce7e45db08182bd Mon Sep 17 00:00:00 2001 From: "vitess-bot[bot]" <108069721+vitess-bot[bot]@users.noreply.github.com> Date: Mon, 7 Aug 2023 23:56:06 -0700 Subject: [PATCH] Fix vtcombo DBDDL plugin race condition (#13117) Signed-off-by: Jaskanwal Pawar <32091345+jspawar@users.noreply.github.com> Co-authored-by: Arthur Schreiber --- go/cmd/vtcombo/plugin_dbddl.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/go/cmd/vtcombo/plugin_dbddl.go b/go/cmd/vtcombo/plugin_dbddl.go index 49a7a601fb1..1a95e073308 100644 --- a/go/cmd/vtcombo/plugin_dbddl.go +++ b/go/cmd/vtcombo/plugin_dbddl.go @@ -18,6 +18,7 @@ package main import ( "context" + "sync" "vitess.io/vitess/go/vt/servenv" "vitess.io/vitess/go/vt/vtgate/engine" @@ -29,7 +30,9 @@ var globalCreateDb func(ctx context.Context, ks *vttestpb.Keyspace) error var globalDropDb func(ctx context.Context, ksName string) error // DBDDL doesn't need to store any state - we use the global variables above instead -type DBDDL struct{} +type DBDDL struct { + mu sync.Mutex +} // CreateDatabase implements the engine.DBDDLPlugin interface func (plugin *DBDDL) CreateDatabase(ctx context.Context, name string) error { @@ -39,6 +42,8 @@ func (plugin *DBDDL) CreateDatabase(ctx context.Context, name string) error { Name: "0", }}, } + plugin.mu.Lock() + defer plugin.mu.Unlock() return globalCreateDb(ctx, ks) }