From baa8dd2b257ecda5b95d248c5ff54be42d96dca9 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 22 Jul 2021 13:21:56 +0200 Subject: [PATCH 1/4] Clearing current shard's _vt.schemacopy rows only during schema tracking reload Signed-off-by: Florent Poinsard --- go/mysql/schema.go | 2 +- .../schematracker/sharded/st_sharded_test.go | 33 +++++++++++++++++++ .../vttablet/tabletserver/health_streamer.go | 2 +- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/go/mysql/schema.go b/go/mysql/schema.go index 88a1bf6f89f..218d04d858c 100644 --- a/go/mysql/schema.go +++ b/go/mysql/schema.go @@ -89,7 +89,7 @@ where c.table_schema = database() AND ISC.table_schema is null` DetectSchemaChange = detectChangeColumns + " UNION " + detectNewColumns + " UNION " + detectRemoveColumns // ClearSchemaCopy query clears the schemacopy table. - ClearSchemaCopy = `delete from _vt.schemacopy` + ClearSchemaCopy = `delete from _vt.schemacopy where table_schema = database()` // InsertIntoSchemaCopy query copies over the schema information from information_schema.columns table. InsertIntoSchemaCopy = `insert _vt.schemacopy diff --git a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go index 08901571299..a8d7630970d 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go @@ -61,6 +61,12 @@ create table t8( testId bigint, primary key(id8) ) Engine=InnoDB; + +create table t9( + id9 bigint, + testId bigint, + primary key(id9) +) Engine=InnoDB; ` VSchema = ` @@ -165,6 +171,33 @@ func TestMain(m *testing.M) { os.Exit(exitCode) } +func TestNewTable(t *testing.T) { + ctx := context.Background() + conn, err := mysql.Connect(ctx, &vtParams) + require.NoError(t, err) + defer conn.Close() + + shard1Params := vtParams + shard1Params.DbName += ":-80@master" + connShard1, err := mysql.Connect(ctx, &shard1Params) + require.NoError(t, err) + defer connShard1.Close() + + shard2Params := vtParams + shard2Params.DbName += ":80-@master" + connShard2, err := mysql.Connect(ctx, &shard2Params) + require.NoError(t, err) + defer connShard2.Close() + + _ = exec(t, conn, "create table test_table (id bigint, name varchar(100))") + + time.Sleep(2 * time.Second) + + assertMatches(t, conn, "select * from test_table", `[]`) + assertMatches(t, connShard1, "select * from test_table", `[]`) + assertMatches(t, connShard2, "select * from test_table", `[]`) +} + func TestAmbiguousColumnJoin(t *testing.T) { defer cluster.PanicHandler(t) ctx := context.Background() diff --git a/go/vt/vttablet/tabletserver/health_streamer.go b/go/vt/vttablet/tabletserver/health_streamer.go index 5d7f20b8c25..56820464c0a 100644 --- a/go/vt/vttablet/tabletserver/health_streamer.go +++ b/go/vt/vttablet/tabletserver/health_streamer.go @@ -359,7 +359,7 @@ func (hs *healthStreamer) reload() error { } tableNamePredicate := fmt.Sprintf("table_name IN (%s)", strings.Join(tableNames, ", ")) - del := fmt.Sprintf("%s WHERE %s", mysql.ClearSchemaCopy, tableNamePredicate) + del := fmt.Sprintf("%s AND %s", mysql.ClearSchemaCopy, tableNamePredicate) upd := fmt.Sprintf("%s AND %s", mysql.InsertIntoSchemaCopy, tableNamePredicate) // Reload the schema in a transaction. From 41d367744c5a956eb6853a80ab87b78bf72ca3d3 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 22 Jul 2021 14:16:11 +0200 Subject: [PATCH 2/4] Fixed usages of ClearSchemaCopy consts in tests Signed-off-by: Florent Poinsard --- go/mysql/endtoend/schema_change_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go/mysql/endtoend/schema_change_test.go b/go/mysql/endtoend/schema_change_test.go index 4ddcfbb94a9..39e1275dc08 100644 --- a/go/mysql/endtoend/schema_change_test.go +++ b/go/mysql/endtoend/schema_change_test.go @@ -123,7 +123,7 @@ func TestChangeSchemaIsNoticed(t *testing.T) { tables = append(tables, "table_name = "+sqlparser.String(apa)) } tableNamePredicates := strings.Join(tables, " OR ") - del := fmt.Sprintf("%s WHERE %s", mysql.ClearSchemaCopy, tableNamePredicates) + del := fmt.Sprintf("%s AND %s", mysql.ClearSchemaCopy, tableNamePredicates) upd := fmt.Sprintf("%s AND %s", mysql.InsertIntoSchemaCopy, tableNamePredicates) _, err = conn.ExecuteFetch(del, 1000, true) From a5b2bbbd15da8d339bb0b71154b91bacf0c54d1a Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 22 Jul 2021 15:24:09 +0200 Subject: [PATCH 3/4] Drop test_table at the end of the test Signed-off-by: Florent Poinsard --- go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go index a8d7630970d..f69dd436792 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go @@ -190,6 +190,7 @@ func TestNewTable(t *testing.T) { defer connShard2.Close() _ = exec(t, conn, "create table test_table (id bigint, name varchar(100))") + defer exec(t, conn, "drop table test_table") time.Sleep(2 * time.Second) From 6079103fd0418a196b5b55b46b8d5ee46d22cdd9 Mon Sep 17 00:00:00 2001 From: Florent Poinsard Date: Thu, 22 Jul 2021 16:00:00 +0200 Subject: [PATCH 4/4] Wait after drop table to let schema tracking propagate the changes Signed-off-by: Florent Poinsard --- .../vtgate/schematracker/sharded/st_sharded_test.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go index f69dd436792..3c604d19e3c 100644 --- a/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go +++ b/go/test/endtoend/vtgate/schematracker/sharded/st_sharded_test.go @@ -61,12 +61,6 @@ create table t8( testId bigint, primary key(id8) ) Engine=InnoDB; - -create table t9( - id9 bigint, - testId bigint, - primary key(id9) -) Engine=InnoDB; ` VSchema = ` @@ -190,13 +184,16 @@ func TestNewTable(t *testing.T) { defer connShard2.Close() _ = exec(t, conn, "create table test_table (id bigint, name varchar(100))") - defer exec(t, conn, "drop table test_table") time.Sleep(2 * time.Second) assertMatches(t, conn, "select * from test_table", `[]`) assertMatches(t, connShard1, "select * from test_table", `[]`) assertMatches(t, connShard2, "select * from test_table", `[]`) + + exec(t, conn, "drop table test_table") + + time.Sleep(2 * time.Second) } func TestAmbiguousColumnJoin(t *testing.T) {