Skip to content

Commit 0ad0a46

Browse files
Do not load table stats when booting vttablet.
Signed-off-by: Arthur Schreiber <[email protected]>
1 parent e0637c2 commit 0ad0a46

File tree

9 files changed

+155
-50
lines changed

9 files changed

+155
-50
lines changed

go/mysql/flavor_mysql.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,11 @@ func (mysqlFlavor) readBinlogEvent(c *Conn) (BinlogEvent, error) {
299299

300300
// baseShowTables is part of the Flavor interface.
301301
func (mysqlFlavor) baseShowTables() string {
302-
return "SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()"
302+
return BaseShowTables
303303
}
304304

305+
const BaseShowTables = `SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()`
306+
305307
// TablesWithSize56 is a query to select table along with size for mysql 5.6
306308
const TablesWithSize56 = `SELECT table_name,
307309
table_type,
@@ -340,8 +342,6 @@ LEFT OUTER JOIN (
340342
WHERE t.table_schema = database()
341343
GROUP BY t.table_name, t.table_type, t.create_time, t.table_comment`
342344

343-
// TablesWithSize80 is a query to select table along with size for mysql 8.0
344-
//
345345
// Note the following:
346346
// - We use a single query to fetch both partitioned and non-partitioned tables. This is because
347347
// accessing `information_schema.innodb_tablespaces` is expensive on servers with many tablespaces,

go/vt/vtexplain/vtexplain_vttablet.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,11 @@ func newTabletEnvironment(ddls []sqlparser.DDLStatement, opts *Options) (*tablet
438438
Rows: showTableRows,
439439
})
440440

441+
tEnv.addResult(mysql.BaseShowTables, &sqltypes.Result{
442+
Fields: mysql.BaseShowTablesFields[0:4],
443+
Rows: showTableRows,
444+
})
445+
441446
indexRows := make([][]sqltypes.Value, 0, 4)
442447
for _, ddl := range ddls {
443448
table := sqlparser.String(ddl.GetTable().Name)

go/vt/vttablet/tabletserver/health_streamer_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,17 @@ func TestReloadSchema(t *testing.T) {
249249
"product|BASE TABLE|1684735966||114688|114688",
250250
"users|BASE TABLE|1684735966||114688|114688",
251251
))
252+
253+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
254+
sqltypes.MakeTestResult(
255+
sqltypes.MakeTestFields(
256+
"TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT",
257+
"varchar|varchar|int64|varchar",
258+
),
259+
"product|BASE TABLE|1684735966|",
260+
"users|BASE TABLE|1684735966|",
261+
))
262+
252263
db.AddQueryPattern("SELECT COLUMN_NAME as column_name.*", sqltypes.MakeTestResult(
253264
sqltypes.MakeTestFields(
254265
"column_name",
@@ -293,6 +304,16 @@ func TestReloadSchema(t *testing.T) {
293304
"users|BASE TABLE|1684735967||114688|114688",
294305
))
295306

307+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
308+
sqltypes.MakeTestResult(
309+
sqltypes.MakeTestFields(
310+
"TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT",
311+
"varchar|varchar|int64|varchar",
312+
),
313+
"product|BASE TABLE|1684735967|",
314+
"users|BASE TABLE|1684735967|",
315+
))
316+
296317
var wg sync.WaitGroup
297318
wg.Add(1)
298319
go func() {
@@ -359,6 +380,13 @@ func TestReloadView(t *testing.T) {
359380
"varchar|varchar|int64|varchar|int64|int64",
360381
),
361382
))
383+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
384+
sqltypes.MakeTestResult(
385+
sqltypes.MakeTestFields(
386+
"TABLE_NAME | TABLE_TYPE | UNIX_TIMESTAMP(t.create_time) | TABLE_COMMENT",
387+
"varchar|varchar|int64|varchar",
388+
),
389+
))
362390
db.AddQueryPattern("SELECT COLUMN_NAME as column_name.*", sqltypes.MakeTestResult(
363391
sqltypes.MakeTestFields(
364392
"column_name",

go/vt/vttablet/tabletserver/query_engine_test.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,17 @@ func addSchemaEngineQueries(db *fakesqldb.DB) {
121121
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
122122
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"),
123123
}})
124+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
125+
&sqltypes.Result{
126+
Fields: mysql.BaseShowTablesFields,
127+
Rows: [][]sqltypes.Value{
128+
mysql.BaseShowTablesRow("test_table_01", false, ""),
129+
mysql.BaseShowTablesRow("test_table_02", false, ""),
130+
mysql.BaseShowTablesRow("test_table_03", false, ""),
131+
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
132+
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"),
133+
},
134+
})
124135
db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
125136
"Variable_name|Value",
126137
"varchar|int64"),

go/vt/vttablet/tabletserver/query_executor_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,6 +1557,15 @@ func initQueryExecutorTestDB(db *fakesqldb.DB) {
15571557
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"),
15581558
},
15591559
})
1560+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
1561+
&sqltypes.Result{
1562+
Fields: mysql.BaseShowTablesFields,
1563+
Rows: [][]sqltypes.Value{
1564+
mysql.BaseShowTablesRow("test_table", false, ""),
1565+
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
1566+
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"),
1567+
},
1568+
})
15601569
db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
15611570
"Variable_name|Value",
15621571
"varchar|int64"),

go/vt/vttablet/tabletserver/schema/engine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func (se *Engine) Open() error {
254254
}
255255
se.notifiers = make(map[string]notifier)
256256

257-
if err := se.reload(ctx, true); err != nil {
257+
if err := se.reload(ctx, false); err != nil {
258258
return err
259259
}
260260
if !se.SkipMetaCheck {

go/vt/vttablet/tabletserver/schema/engine_test.go

Lines changed: 89 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,23 @@ func TestOpenAndReload(t *testing.T) {
5454
db := fakesqldb.New(t)
5555
defer db.Close()
5656
schematest.AddDefaultQueries(db)
57-
db.AddQueryPattern(baseShowTablesPattern,
58-
&sqltypes.Result{
59-
Fields: mysql.BaseShowTablesFields,
60-
RowsAffected: 0,
61-
InsertID: 0,
62-
Rows: [][]sqltypes.Value{
63-
mysql.BaseShowTablesRow("test_table_01", false, ""),
64-
mysql.BaseShowTablesRow("test_table_02", false, ""),
65-
mysql.BaseShowTablesRow("test_table_03", false, ""),
66-
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
67-
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"),
68-
},
69-
SessionStateChanges: "",
70-
StatusFlags: 0,
71-
})
57+
58+
db.RejectQueryPattern(baseShowTablesPattern, "Opening schema engine should query tables without size information")
59+
60+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
61+
Fields: mysql.BaseShowTablesFields,
62+
RowsAffected: 0,
63+
InsertID: 0,
64+
Rows: [][]sqltypes.Value{
65+
mysql.BaseShowTablesRow("test_table_01", false, ""),
66+
mysql.BaseShowTablesRow("test_table_02", false, ""),
67+
mysql.BaseShowTablesRow("test_table_03", false, ""),
68+
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
69+
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"),
70+
},
71+
SessionStateChanges: "",
72+
StatusFlags: 0,
73+
})
7274

7375
// advance to one second after the default 1427325875.
7476
db.AddQuery("select unix_timestamp()", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
@@ -84,8 +86,8 @@ func TestOpenAndReload(t *testing.T) {
8486

8587
want := initialSchema()
8688
mustMatch(t, want, se.GetSchema())
87-
assert.Equal(t, int64(100), se.tableFileSizeGauge.Counts()["msg"])
88-
assert.Equal(t, int64(150), se.tableAllocatedSizeGauge.Counts()["msg"])
89+
assert.Equal(t, int64(0), se.tableFileSizeGauge.Counts()["msg"])
90+
assert.Equal(t, int64(0), se.tableAllocatedSizeGauge.Counts()["msg"])
8991

9092
// Advance time some more.
9193
db.AddQuery("select unix_timestamp()", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
@@ -116,6 +118,9 @@ func TestOpenAndReload(t *testing.T) {
116118
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
117119
},
118120
})
121+
122+
db.AddRejectedQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", fmt.Errorf("Reloading schema engine should query tables with size information"))
123+
119124
db.MockQueriesForTable("test_table_03", &sqltypes.Result{
120125
Fields: []*querypb.Field{{
121126
Name: "pk1",
@@ -171,6 +176,15 @@ func TestOpenAndReload(t *testing.T) {
171176

172177
assert.EqualValues(t, secondReadRowsValue, se.innoDbReadRowsCounter.Get())
173178

179+
want["seq"].FileSize = 100
180+
want["seq"].AllocatedSize = 150
181+
182+
want["test_table_01"].FileSize = 100
183+
want["test_table_01"].AllocatedSize = 150
184+
185+
want["test_table_02"].FileSize = 100
186+
want["test_table_02"].AllocatedSize = 150
187+
174188
want["test_table_03"] = &Table{
175189
Name: sqlparser.NewIdentifierCS("test_table_03"),
176190
Fields: []*querypb.Field{{
@@ -228,6 +242,17 @@ func TestOpenAndReload(t *testing.T) {
228242
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
229243
},
230244
})
245+
246+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
247+
Fields: mysql.BaseShowTablesFields,
248+
Rows: [][]sqltypes.Value{
249+
mysql.BaseShowTablesRow("test_table_01", false, ""),
250+
mysql.BaseShowTablesRow("test_table_02", false, ""),
251+
mysql.BaseShowTablesRow("test_table_04", false, ""),
252+
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
253+
},
254+
})
255+
231256
db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{
232257
Fields: mysql.ShowPrimaryFields,
233258
Rows: [][]sqltypes.Value{
@@ -251,21 +276,23 @@ func TestReloadWithSwappedTables(t *testing.T) {
251276
db := fakesqldb.New(t)
252277
defer db.Close()
253278
schematest.AddDefaultQueries(db)
254-
db.AddQueryPattern(baseShowTablesPattern,
255-
&sqltypes.Result{
256-
Fields: mysql.BaseShowTablesFields,
257-
RowsAffected: 0,
258-
InsertID: 0,
259-
Rows: [][]sqltypes.Value{
260-
mysql.BaseShowTablesRow("test_table_01", false, ""),
261-
mysql.BaseShowTablesRow("test_table_02", false, ""),
262-
mysql.BaseShowTablesRow("test_table_03", false, ""),
263-
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
264-
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"),
265-
},
266-
SessionStateChanges: "",
267-
StatusFlags: 0,
268-
})
279+
280+
db.RejectQueryPattern(baseShowTablesPattern, "Opening schema engine should query tables without size information")
281+
282+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
283+
Fields: mysql.BaseShowTablesFields,
284+
RowsAffected: 0,
285+
InsertID: 0,
286+
Rows: [][]sqltypes.Value{
287+
mysql.BaseShowTablesRow("test_table_01", false, ""),
288+
mysql.BaseShowTablesRow("test_table_02", false, ""),
289+
mysql.BaseShowTablesRow("test_table_03", false, ""),
290+
mysql.BaseShowTablesRow("seq", false, "vitess_sequence"),
291+
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"),
292+
},
293+
SessionStateChanges: "",
294+
StatusFlags: 0,
295+
})
269296
firstReadRowsValue := 12
270297
AddFakeInnoDBReadRowsResult(db, firstReadRowsValue)
271298

@@ -319,6 +346,22 @@ func TestReloadWithSwappedTables(t *testing.T) {
319346
})
320347
err := se.Reload(context.Background())
321348
require.NoError(t, err)
349+
350+
want["msg"].FileSize = 100
351+
want["msg"].AllocatedSize = 150
352+
353+
want["seq"].FileSize = 100
354+
want["seq"].AllocatedSize = 150
355+
356+
want["test_table_01"].FileSize = 100
357+
want["test_table_01"].AllocatedSize = 150
358+
359+
want["test_table_02"].FileSize = 100
360+
want["test_table_02"].AllocatedSize = 150
361+
362+
want["test_table_03"].FileSize = 100
363+
want["test_table_03"].AllocatedSize = 150
364+
322365
want["test_table_04"] = &Table{
323366
Name: sqlparser.NewIdentifierCS("test_table_04"),
324367
Fields: []*querypb.Field{{
@@ -418,7 +461,7 @@ func TestOpenFailedDueToExecErr(t *testing.T) {
418461
defer db.Close()
419462
schematest.AddDefaultQueries(db)
420463
want := "injected error"
421-
db.RejectQueryPattern(baseShowTablesPattern, want)
464+
db.AddRejectedQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", fmt.Errorf(want))
422465
se := newEngine(10, 1*time.Second, 1*time.Second, 0, db)
423466
err := se.Open()
424467
if err == nil || !strings.Contains(err.Error(), want) {
@@ -433,7 +476,7 @@ func TestOpenFailedDueToLoadTableErr(t *testing.T) {
433476
db := fakesqldb.New(t)
434477
defer db.Close()
435478
schematest.AddDefaultQueries(db)
436-
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
479+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
437480
Fields: mysql.BaseShowTablesFields,
438481
Rows: [][]sqltypes.Value{
439482
mysql.BaseShowTablesRow("test_table", false, ""),
@@ -468,7 +511,7 @@ func TestOpenNoErrorDueToInvalidViews(t *testing.T) {
468511
db := fakesqldb.New(t)
469512
defer db.Close()
470513
schematest.AddDefaultQueries(db)
471-
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{
514+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{
472515
Fields: mysql.BaseShowTablesFields,
473516
Rows: [][]sqltypes.Value{
474517
mysql.BaseShowTablesRow("foo_view", true, "VIEW"),
@@ -526,7 +569,7 @@ func TestSchemaEngineCloseTickRace(t *testing.T) {
526569
db := fakesqldb.New(t)
527570
defer db.Close()
528571
schematest.AddDefaultQueries(db)
529-
db.AddQueryPattern(baseShowTablesPattern,
572+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
530573
&sqltypes.Result{
531574
Fields: mysql.BaseShowTablesFields,
532575
RowsAffected: 0,
@@ -602,8 +645,8 @@ func initialSchema() map[string]*Table {
602645
}},
603646
PKColumns: []int{0},
604647
CreateTime: 1427325875,
605-
FileSize: 0x64,
606-
AllocatedSize: 0x96,
648+
FileSize: 0,
649+
AllocatedSize: 0,
607650
},
608651
"test_table_02": {
609652
Name: sqlparser.NewIdentifierCS("test_table_02"),
@@ -613,8 +656,8 @@ func initialSchema() map[string]*Table {
613656
}},
614657
PKColumns: []int{0},
615658
CreateTime: 1427325875,
616-
FileSize: 0x64,
617-
AllocatedSize: 0x96,
659+
FileSize: 0,
660+
AllocatedSize: 0,
618661
},
619662
"test_table_03": {
620663
Name: sqlparser.NewIdentifierCS("test_table_03"),
@@ -624,8 +667,8 @@ func initialSchema() map[string]*Table {
624667
}},
625668
PKColumns: []int{0},
626669
CreateTime: 1427325875,
627-
FileSize: 0x64,
628-
AllocatedSize: 0x96,
670+
FileSize: 0,
671+
AllocatedSize: 0,
629672
},
630673
"seq": {
631674
Name: sqlparser.NewIdentifierCS("seq"),
@@ -645,8 +688,8 @@ func initialSchema() map[string]*Table {
645688
}},
646689
PKColumns: []int{0},
647690
CreateTime: 1427325875,
648-
FileSize: 0x64,
649-
AllocatedSize: 0x96,
691+
FileSize: 0,
692+
AllocatedSize: 0,
650693
SequenceInfo: &SequenceInfo{},
651694
},
652695
"msg": {
@@ -673,8 +716,8 @@ func initialSchema() map[string]*Table {
673716
}},
674717
PKColumns: []int{0},
675718
CreateTime: 1427325875,
676-
FileSize: 0x64,
677-
AllocatedSize: 0x96,
719+
FileSize: 0,
720+
AllocatedSize: 0,
678721
MessageInfo: &MessageInfo{
679722
Fields: []*querypb.Field{{
680723
Name: "id",

go/vt/vttablet/tabletserver/schema/main_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func getTestSchemaEngine(t *testing.T, schemaMaxAgeSeconds int64) (*Engine, *fak
3535
"1427325876",
3636
))
3737
db.AddQueryPattern(baseShowTablesPattern, &sqltypes.Result{})
38+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()", &sqltypes.Result{})
3839
db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{})
3940
AddFakeInnoDBReadRowsResult(db, 1)
4041
se := newEngine(10, 10*time.Second, 10*time.Second, schemaMaxAgeSeconds, db)

go/vt/vttablet/tabletserver/tabletserver_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,6 +2353,14 @@ func setupFakeDB(t *testing.T) *fakesqldb.DB {
23532353
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"),
23542354
},
23552355
})
2356+
db.AddQuery("SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()",
2357+
&sqltypes.Result{
2358+
Fields: mysql.BaseShowTablesFields,
2359+
Rows: [][]sqltypes.Value{
2360+
mysql.BaseShowTablesRow("test_table", false, ""),
2361+
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"),
2362+
},
2363+
})
23562364
db.AddQuery("show status like 'Innodb_rows_read'", sqltypes.MakeTestResult(sqltypes.MakeTestFields(
23572365
"Variable_name|Value",
23582366
"varchar|int64"),

0 commit comments

Comments
 (0)