From ec43f9ec22a6307fb9713e83d01c3c9e0bc72898 Mon Sep 17 00:00:00 2001 From: Arthur Schreiber Date: Mon, 10 Jun 2024 23:53:04 +0200 Subject: [PATCH] Do not load table stats when booting `vttablet`. (#15715) Signed-off-by: Arthur Schreiber --- go/mysql/flavor_mysql.go | 11 +- go/mysql/schema.go | 15 +- go/vt/vtexplain/vtexplain_vttablet.go | 17 +- .../tabletserver/health_streamer_test.go | 28 +++ .../tabletserver/query_engine_test.go | 25 ++- .../tabletserver/query_executor_test.go | 21 +- go/vt/vttablet/tabletserver/schema/engine.go | 2 +- .../tabletserver/schema/engine_test.go | 197 +++++++++++------- .../vttablet/tabletserver/schema/main_test.go | 3 +- .../tabletserver/tabletserver_test.go | 16 +- 10 files changed, 230 insertions(+), 105 deletions(-) diff --git a/go/mysql/flavor_mysql.go b/go/mysql/flavor_mysql.go index 612bb04fac7..bfc37855e7e 100644 --- a/go/mysql/flavor_mysql.go +++ b/go/mysql/flavor_mysql.go @@ -299,9 +299,18 @@ func (mysqlFlavor) readBinlogEvent(c *Conn) (BinlogEvent, error) { // baseShowTables is part of the Flavor interface. func (mysqlFlavor) baseShowTables() string { - return "SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()" + return BaseShowTables } +const BaseShowTables = `SELECT t.table_name, + t.table_type, + UNIX_TIMESTAMP(t.create_time), + t.table_comment + FROM information_schema.tables t + WHERE + t.table_schema = database() +` + // TablesWithSize56 is a query to select table along with size for mysql 5.6 const TablesWithSize56 = `SELECT table_name, table_type, diff --git a/go/mysql/schema.go b/go/mysql/schema.go index b436212cf0a..3b0df5d731b 100644 --- a/go/mysql/schema.go +++ b/go/mysql/schema.go @@ -139,19 +139,21 @@ var BaseShowTablesFields = []*querypb.Field{{ ColumnLength: 6144, Charset: uint32(collations.SystemCollation.Collation), Flags: uint32(querypb.MySqlFlag_NOT_NULL_FLAG), -}, { +}} + +var BaseShowTablesWithSizesFields = append(BaseShowTablesFields, &querypb.Field{ Name: "i.file_size", Type: querypb.Type_INT64, ColumnLength: 11, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG), -}, { +}, &querypb.Field{ Name: "i.allocated_size", Type: querypb.Type_INT64, ColumnLength: 11, Charset: collations.CollationBinaryID, Flags: uint32(querypb.MySqlFlag_BINARY_FLAG | querypb.MySqlFlag_NUM_FLAG), -}} +}) // BaseShowTablesRow returns the fields from a BaseShowTables or // BaseShowTablesForTable command. @@ -165,9 +167,14 @@ func BaseShowTablesRow(tableName string, isView bool, comment string) []sqltypes sqltypes.MakeTrusted(sqltypes.VarChar, []byte(tableType)), sqltypes.MakeTrusted(sqltypes.Int64, []byte("1427325875")), // unix_timestamp(create_time) sqltypes.MakeTrusted(sqltypes.VarChar, []byte(comment)), + } +} + +func BaseShowTablesWithSizesRow(tableName string, isView bool, comment string) []sqltypes.Value { + return append(BaseShowTablesRow(tableName, isView, comment), sqltypes.MakeTrusted(sqltypes.Int64, []byte("100")), // file_size sqltypes.MakeTrusted(sqltypes.Int64, []byte("150")), // allocated_size - } + ) } // ShowPrimaryFields contains the fields for a BaseShowPrimary. diff --git a/go/vt/vtexplain/vtexplain_vttablet.go b/go/vt/vtexplain/vtexplain_vttablet.go index 24c17b8f969..1346630552a 100644 --- a/go/vt/vtexplain/vtexplain_vttablet.go +++ b/go/vt/vtexplain/vtexplain_vttablet.go @@ -415,7 +415,9 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) (*tablet tEnv.addResult(query, result) } - showTableRows := make([][]sqltypes.Value, 0, 4) + showTableRows := make([][]sqltypes.Value, 0, len(ddls)) + showTableWithSizesRows := make([][]sqltypes.Value, 0, len(ddls)) + for _, ddl := range ddls { table := ddl.GetTable().Name.String() options := "" @@ -428,14 +430,21 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) (*tablet } } showTableRows = append(showTableRows, mysql.BaseShowTablesRow(table, false, options)) + showTableWithSizesRows = append(showTableWithSizesRows, mysql.BaseShowTablesWithSizesRow(table, true, options)) } - tEnv.addResult(mysql.TablesWithSize57, &sqltypes.Result{ + + tEnv.addResult(mysql.BaseShowTables, &sqltypes.Result{ Fields: mysql.BaseShowTablesFields, Rows: showTableRows, }) + + tEnv.addResult(mysql.TablesWithSize57, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, + Rows: showTableWithSizesRows, + }) tEnv.addResult(mysql.TablesWithSize80, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, - Rows: showTableRows, + Fields: mysql.BaseShowTablesWithSizesFields, + Rows: showTableWithSizesRows, }) indexRows := make([][]sqltypes.Value, 0, 4) diff --git a/go/vt/vttablet/tabletserver/health_streamer_test.go b/go/vt/vttablet/tabletserver/health_streamer_test.go index 7f19d640d7f..b5ddbd29fb2 100644 --- a/go/vt/vttablet/tabletserver/health_streamer_test.go +++ b/go/vt/vttablet/tabletserver/health_streamer_test.go @@ -249,6 +249,17 @@ func TestReloadSchema(t *testing.T) { "product|BASE TABLE|1684735966||114688|114688", "users|BASE TABLE|1684735966||114688|114688", )) + + db.AddQuery(mysql.BaseShowTables, + sqltypes.MakeTestResult( + sqltypes.MakeTestFields( + "TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT", + "varchar|varchar|int64|varchar", + ), + "product|BASE TABLE|1684735966|", + "users|BASE TABLE|1684735966|", + )) + db.AddQueryPattern("SELECT COLUMN_NAME as column_name.*", sqltypes.MakeTestResult( sqltypes.MakeTestFields( "column_name", @@ -293,6 +304,16 @@ func TestReloadSchema(t *testing.T) { "users|BASE TABLE|1684735967||114688|114688", )) + db.AddQuery(mysql.BaseShowTables, + sqltypes.MakeTestResult( + sqltypes.MakeTestFields( + "TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT", + "varchar|varchar|int64|varchar", + ), + "product|BASE TABLE|1684735967|", + "users|BASE TABLE|1684735967|", + )) + var wg sync.WaitGroup wg.Add(1) go func() { @@ -359,6 +380,13 @@ func TestReloadView(t *testing.T) { "varchar|varchar|int64|varchar|int64|int64", ), )) + db.AddQuery(mysql.BaseShowTables, + sqltypes.MakeTestResult( + sqltypes.MakeTestFields( + "TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT", + "varchar|varchar|int64|varchar", + ), + )) db.AddQueryPattern("SELECT COLUMN_NAME as column_name.*", sqltypes.MakeTestResult( sqltypes.MakeTestFields( "column_name", diff --git a/go/vt/vttablet/tabletserver/query_engine_test.go b/go/vt/vttablet/tabletserver/query_engine_test.go index 33849c3f5e6..fbf935cf7f0 100644 --- a/go/vt/vttablet/tabletserver/query_engine_test.go +++ b/go/vt/vttablet/tabletserver/query_engine_test.go @@ -112,15 +112,26 @@ func TestGetPlanPanicDuetoEmptyQuery(t *testing.T) { } func addSchemaEngineQueries(db *fakesqldb.DB) { - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), - mysql.BaseShowTablesRow("test_table_03", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_03", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), }}) + db.AddQuery(mysql.BaseShowTables, + &sqltypes.Result{ + Fields: mysql.BaseShowTablesFields, + Rows: [][]sqltypes.Value{ + mysql.BaseShowTablesRow("test_table_01", false, ""), + mysql.BaseShowTablesRow("test_table_02", false, ""), + mysql.BaseShowTablesRow("test_table_03", false, ""), + mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + }, + }) db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields( "Variable_name|Value", "varchar|int64"), diff --git a/go/vt/vttablet/tabletserver/query_executor_test.go b/go/vt/vttablet/tabletserver/query_executor_test.go index 3ab653bf50c..570c1ffdb1b 100644 --- a/go/vt/vttablet/tabletserver/query_executor_test.go +++ b/go/vt/vttablet/tabletserver/query_executor_test.go @@ -1545,18 +1545,27 @@ func setUpQueryExecutorTest(t *testing.T) *fakesqldb.DB { return db } -const baseShowTablesPattern = `SELECT t\.table_name.*` +const baseShowTablesWithSizesPattern = `SELECT t\.table_name.*SUM\(i\.file_size\).*` func initQueryExecutorTestDB(db *fakesqldb.DB) { addQueryExecutorSupportedQueries(db) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + mysql.BaseShowTablesWithSizesRow("test_table", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), }, }) + db.AddQuery(mysql.BaseShowTables, + &sqltypes.Result{ + Fields: mysql.BaseShowTablesFields, + Rows: [][]sqltypes.Value{ + mysql.BaseShowTablesRow("test_table", false, ""), + mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + }, + }) db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields( "Variable_name|Value", "varchar|int64"), diff --git a/go/vt/vttablet/tabletserver/schema/engine.go b/go/vt/vttablet/tabletserver/schema/engine.go index 0ca6701d38d..a64748f8b6f 100644 --- a/go/vt/vttablet/tabletserver/schema/engine.go +++ b/go/vt/vttablet/tabletserver/schema/engine.go @@ -254,7 +254,7 @@ func (se *Engine) Open() error { } se.notifiers = make(map[string]notifier) - if err := se.reload(ctx, true); err != nil { + if err := se.reload(ctx, false); err != nil { return err } if !se.SkipMetaCheck { diff --git a/go/vt/vttablet/tabletserver/schema/engine_test.go b/go/vt/vttablet/tabletserver/schema/engine_test.go index 950619f95de..e5d4bb47122 100644 --- a/go/vt/vttablet/tabletserver/schema/engine_test.go +++ b/go/vt/vttablet/tabletserver/schema/engine_test.go @@ -46,7 +46,7 @@ import ( "vitess.io/vitess/go/vt/vttablet/tabletserver/tabletenv" ) -const baseShowTablesPattern = `SELECT t\.table_name.*` +const baseShowTablesWithSizesPattern = `SELECT t\.table_name.*SUM\(i\.file_size\).*` var mustMatch = utils.MustMatchFn(".Mutex") @@ -54,21 +54,23 @@ func TestOpenAndReload(t *testing.T) { db := fakesqldb.New(t) defer db.Close() schematest.AddDefaultQueries(db) - db.AddQueryPattern(baseShowTablesPattern, - &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, - RowsAffected: 0, - InsertID: 0, - Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), - mysql.BaseShowTablesRow("test_table_03", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), - }, - SessionStateChanges: "", - StatusFlags: 0, - }) + + db.RejectQueryPattern(baseShowTablesWithSizesPattern, "Opening schema engine should query tables without size information") + + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{ + Fields: mysql.BaseShowTablesFields, + RowsAffected: 0, + InsertID: 0, + Rows: [][]sqltypes.Value{ + mysql.BaseShowTablesRow("test_table_01", false, ""), + mysql.BaseShowTablesRow("test_table_02", false, ""), + mysql.BaseShowTablesRow("test_table_03", false, ""), + mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + }, + SessionStateChanges: "", + StatusFlags: 0, + }) // advance to one second after the default 1427325875. db.AddQuery("select unix_timestamp()", sqltypes.MakeTestResult(sqltypes.MakeTestFields( @@ -84,8 +86,8 @@ func TestOpenAndReload(t *testing.T) { want := initialSchema() mustMatch(t, want, se.GetSchema()) - assert.Equal(t, int64(100), se.tableFileSizeGauge.Counts()["msg"]) - assert.Equal(t, int64(150), se.tableAllocatedSizeGauge.Counts()["msg"]) + assert.Equal(t, int64(0), se.tableFileSizeGauge.Counts()["msg"]) + assert.Equal(t, int64(0), se.tableAllocatedSizeGauge.Counts()["msg"]) // Advance time some more. db.AddQuery("select unix_timestamp()", sqltypes.MakeTestResult(sqltypes.MakeTestFields( @@ -98,11 +100,11 @@ func TestOpenAndReload(t *testing.T) { // Modify test_table_03 // Add test_table_04 // Drop msg - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), { sqltypes.MakeTrusted(sqltypes.VarChar, []byte("test_table_03")), // table_name sqltypes.MakeTrusted(sqltypes.VarChar, []byte("BASE TABLE")), // table_type @@ -112,10 +114,13 @@ func TestOpenAndReload(t *testing.T) { sqltypes.MakeTrusted(sqltypes.Int64, []byte("256")), // allocated_size }, // test_table_04 will in spite of older timestamp because it doesn't exist yet. - mysql.BaseShowTablesRow("test_table_04", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("test_table_04", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), }, }) + + db.AddRejectedQuery(mysql.BaseShowTables, fmt.Errorf("Reloading schema engine should query tables with size information")) + db.MockQueriesForTable("test_table_03", &sqltypes.Result{ Fields: []*querypb.Field{{ Name: "pk1", @@ -171,6 +176,15 @@ func TestOpenAndReload(t *testing.T) { assert.EqualValues(t, secondReadRowsValue, se.innoDbReadRowsCounter.Get()) + want["seq"].FileSize = 100 + want["seq"].AllocatedSize = 150 + + want["test_table_01"].FileSize = 100 + want["test_table_01"].AllocatedSize = 150 + + want["test_table_02"].FileSize = 100 + want["test_table_02"].AllocatedSize = 150 + want["test_table_03"] = &Table{ Name: sqlparser.NewIdentifierCS("test_table_03"), Fields: []*querypb.Field{{ @@ -219,7 +233,17 @@ func TestOpenAndReload(t *testing.T) { require.NoError(t, err) assert.Equal(t, want, se.GetSchema()) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, + Rows: [][]sqltypes.Value{ + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_04", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + }, + }) + + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{ Fields: mysql.BaseShowTablesFields, Rows: [][]sqltypes.Value{ mysql.BaseShowTablesRow("test_table_01", false, ""), @@ -228,6 +252,7 @@ func TestOpenAndReload(t *testing.T) { mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), }, }) + db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{ Fields: mysql.ShowPrimaryFields, Rows: [][]sqltypes.Value{ @@ -251,21 +276,23 @@ func TestReloadWithSwappedTables(t *testing.T) { db := fakesqldb.New(t) defer db.Close() schematest.AddDefaultQueries(db) - db.AddQueryPattern(baseShowTablesPattern, - &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, - RowsAffected: 0, - InsertID: 0, - Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), - mysql.BaseShowTablesRow("test_table_03", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), - }, - SessionStateChanges: "", - StatusFlags: 0, - }) + + db.RejectQueryPattern(baseShowTablesWithSizesPattern, "Opening schema engine should query tables without size information") + + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{ + Fields: mysql.BaseShowTablesFields, + RowsAffected: 0, + InsertID: 0, + Rows: [][]sqltypes.Value{ + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_03", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + }, + SessionStateChanges: "", + StatusFlags: 0, + }) firstReadRowsValue := 12 AddFakeInnoDBReadRowsResult(db, firstReadRowsValue) @@ -282,12 +309,12 @@ func TestReloadWithSwappedTables(t *testing.T) { "int64"), "1427325876", )) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), - mysql.BaseShowTablesRow("test_table_03", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_03", false, ""), { sqltypes.MakeTrusted(sqltypes.VarChar, []byte("test_table_04")), sqltypes.MakeTrusted(sqltypes.VarChar, []byte("BASE TABLE")), @@ -296,8 +323,8 @@ func TestReloadWithSwappedTables(t *testing.T) { sqltypes.MakeTrusted(sqltypes.Int64, []byte("128")), // file_size sqltypes.MakeTrusted(sqltypes.Int64, []byte("256")), // allocated_size }, - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), }, }) db.MockQueriesForTable("test_table_04", &sqltypes.Result{ @@ -319,6 +346,22 @@ func TestReloadWithSwappedTables(t *testing.T) { }) err := se.Reload(context.Background()) require.NoError(t, err) + + want["msg"].FileSize = 100 + want["msg"].AllocatedSize = 150 + + want["seq"].FileSize = 100 + want["seq"].AllocatedSize = 150 + + want["test_table_01"].FileSize = 100 + want["test_table_01"].AllocatedSize = 150 + + want["test_table_02"].FileSize = 100 + want["test_table_02"].AllocatedSize = 150 + + want["test_table_03"].FileSize = 100 + want["test_table_03"].AllocatedSize = 150 + want["test_table_04"] = &Table{ Name: sqlparser.NewIdentifierCS("test_table_04"), Fields: []*querypb.Field{{ @@ -340,11 +383,11 @@ func TestReloadWithSwappedTables(t *testing.T) { "int64"), "1427325877", )) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), { sqltypes.MakeTrusted(sqltypes.VarChar, []byte("test_table_03")), sqltypes.MakeTrusted(sqltypes.VarChar, []byte("BASE TABLE")), @@ -353,9 +396,9 @@ func TestReloadWithSwappedTables(t *testing.T) { sqltypes.MakeTrusted(sqltypes.Int64, []byte("128")), // file_size sqltypes.MakeTrusted(sqltypes.Int64, []byte("256")), // allocated_size }, - mysql.BaseShowTablesRow("test_table_04", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + mysql.BaseShowTablesWithSizesRow("test_table_04", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), }, }) db.MockQueriesForTable("test_table_03", &sqltypes.Result{ @@ -418,7 +461,7 @@ func TestOpenFailedDueToExecErr(t *testing.T) { defer db.Close() schematest.AddDefaultQueries(db) want := "injected error" - db.RejectQueryPattern(baseShowTablesPattern, want) + db.AddRejectedQuery(mysql.BaseShowTables, fmt.Errorf(want)) se := newEngine(10, 1*time.Second, 1*time.Second, 0, db) err := se.Open() if err == nil || !strings.Contains(err.Error(), want) { @@ -433,11 +476,11 @@ func TestOpenFailedDueToLoadTableErr(t *testing.T) { db := fakesqldb.New(t) defer db.Close() schematest.AddDefaultQueries(db) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{ Fields: mysql.BaseShowTablesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table", false, ""), - mysql.BaseShowTablesRow("test_view", true, "VIEW"), + mysql.BaseShowTablesWithSizesRow("test_table", false, ""), + mysql.BaseShowTablesWithSizesRow("test_view", true, "VIEW"), }, }) // this will cause NewTable error, as it expects zero rows. @@ -468,11 +511,11 @@ func TestOpenNoErrorDueToInvalidViews(t *testing.T) { db := fakesqldb.New(t) defer db.Close() schematest.AddDefaultQueries(db) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{ Fields: mysql.BaseShowTablesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("foo_view", true, "VIEW"), - mysql.BaseShowTablesRow("bar_view", true, "VIEW"), + mysql.BaseShowTablesWithSizesRow("foo_view", true, "VIEW"), + mysql.BaseShowTablesWithSizesRow("bar_view", true, "VIEW"), }, }) @@ -526,17 +569,17 @@ func TestSchemaEngineCloseTickRace(t *testing.T) { db := fakesqldb.New(t) defer db.Close() schematest.AddDefaultQueries(db) - db.AddQueryPattern(baseShowTablesPattern, + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{ Fields: mysql.BaseShowTablesFields, RowsAffected: 0, InsertID: 0, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table_01", false, ""), - mysql.BaseShowTablesRow("test_table_02", false, ""), - mysql.BaseShowTablesRow("test_table_03", false, ""), - mysql.BaseShowTablesRow("seq", false, "vitess_sequence"), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + mysql.BaseShowTablesWithSizesRow("test_table_01", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_02", false, ""), + mysql.BaseShowTablesWithSizesRow("test_table_03", false, ""), + mysql.BaseShowTablesWithSizesRow("seq", false, "vitess_sequence"), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), }, SessionStateChanges: "", StatusFlags: 0, @@ -602,8 +645,8 @@ func initialSchema() map[string]*Table { }}, PKColumns: []int{0}, CreateTime: 1427325875, - FileSize: 0x64, - AllocatedSize: 0x96, + FileSize: 0, + AllocatedSize: 0, }, "test_table_02": { Name: sqlparser.NewIdentifierCS("test_table_02"), @@ -613,8 +656,8 @@ func initialSchema() map[string]*Table { }}, PKColumns: []int{0}, CreateTime: 1427325875, - FileSize: 0x64, - AllocatedSize: 0x96, + FileSize: 0, + AllocatedSize: 0, }, "test_table_03": { Name: sqlparser.NewIdentifierCS("test_table_03"), @@ -624,8 +667,8 @@ func initialSchema() map[string]*Table { }}, PKColumns: []int{0}, CreateTime: 1427325875, - FileSize: 0x64, - AllocatedSize: 0x96, + FileSize: 0, + AllocatedSize: 0, }, "seq": { Name: sqlparser.NewIdentifierCS("seq"), @@ -645,8 +688,8 @@ func initialSchema() map[string]*Table { }}, PKColumns: []int{0}, CreateTime: 1427325875, - FileSize: 0x64, - AllocatedSize: 0x96, + FileSize: 0, + AllocatedSize: 0, SequenceInfo: &SequenceInfo{}, }, "msg": { @@ -673,8 +716,8 @@ func initialSchema() map[string]*Table { }}, PKColumns: []int{0}, CreateTime: 1427325875, - FileSize: 0x64, - AllocatedSize: 0x96, + FileSize: 0, + AllocatedSize: 0, MessageInfo: &MessageInfo{ Fields: []*querypb.Field{{ Name: "id", diff --git a/go/vt/vttablet/tabletserver/schema/main_test.go b/go/vt/vttablet/tabletserver/schema/main_test.go index 19fc66c36d1..0ea3c38ebc3 100644 --- a/go/vt/vttablet/tabletserver/schema/main_test.go +++ b/go/vt/vttablet/tabletserver/schema/main_test.go @@ -34,7 +34,8 @@ func getTestSchemaEngine(t *testing.T, schemaMaxAgeSeconds int64) (*Engine, *fak "int64"), "1427325876", )) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{}) + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{}) + db.AddQuery(mysql.BaseShowTables, &sqltypes.Result{}) db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{}) AddFakeInnoDBReadRowsResult(db, 1) se := newEngine(10, 10*time.Second, 10*time.Second, schemaMaxAgeSeconds, db) diff --git a/go/vt/vttablet/tabletserver/tabletserver_test.go b/go/vt/vttablet/tabletserver/tabletserver_test.go index 51504ffb8ed..02f90226030 100644 --- a/go/vt/vttablet/tabletserver/tabletserver_test.go +++ b/go/vt/vttablet/tabletserver/tabletserver_test.go @@ -2346,13 +2346,21 @@ func setupTabletServerTestCustom(t *testing.T, config *tabletenv.TabletConfig, k func setupFakeDB(t *testing.T) *fakesqldb.DB { db := fakesqldb.New(t) addTabletServerSupportedQueries(db) - db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{ - Fields: mysql.BaseShowTablesFields, + db.AddQueryPattern(baseShowTablesWithSizesPattern, &sqltypes.Result{ + Fields: mysql.BaseShowTablesWithSizesFields, Rows: [][]sqltypes.Value{ - mysql.BaseShowTablesRow("test_table", false, ""), - mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + mysql.BaseShowTablesWithSizesRow("test_table", false, ""), + mysql.BaseShowTablesWithSizesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), }, }) + db.AddQuery(mysql.BaseShowTables, + &sqltypes.Result{ + Fields: mysql.BaseShowTablesFields, + Rows: [][]sqltypes.Value{ + mysql.BaseShowTablesRow("test_table", false, ""), + mysql.BaseShowTablesRow("msg", false, "vitess_message,vt_ack_wait=30,vt_purge_after=120,vt_batch_size=1,vt_cache_size=10,vt_poller_interval=30"), + }, + }) db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields( "Variable_name|Value", "varchar|int64"),