Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear only the current shard's schemacopy rows during schema reload #8519

Merged
merged 4 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go/mysql/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = `
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/health_streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down