Skip to content

Commit

Permalink
adding test that validates engine.Reload, and specifically validates …
Browse files Browse the repository at this point in the history
…we're reading innodb table sizes; particular validation for nonzero filesize for partitioned table proves the logic is sound

Signed-off-by: Shlomi Noach <[email protected]>
  • Loading branch information
shlomi-noach committed Oct 30, 2024
1 parent 1aba77b commit 4471468
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
83 changes: 83 additions & 0 deletions go/vt/vttablet/endtoend/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ import (
"vitess.io/vitess/go/sqltypes"
"vitess.io/vitess/go/test/utils"
"vitess.io/vitess/go/vt/callerid"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/log"
querypb "vitess.io/vitess/go/vt/proto/query"
vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtenv"
"vitess.io/vitess/go/vt/vttablet/endtoend/framework"
"vitess.io/vitess/go/vt/vttablet/tabletserver/schema"
"vitess.io/vitess/go/vt/vttablet/tabletserver/tabletenv"
)

func TestSimpleRead(t *testing.T) {
Expand Down Expand Up @@ -1021,6 +1026,84 @@ func TestShowTablesWithSizes(t *testing.T) {
assert.ElementsMatch(t, expectedTables, actualTables)
}

func newTestSchemaEngine(connParams *mysql.ConnParams) *schema.Engine {
cfg := tabletenv.NewDefaultConfig()
cfg.DB = dbconfigs.NewTestDBConfigs(*connParams, *connParams, connParams.DbName)
env := tabletenv.NewEnv(vtenv.NewTestEnv(), cfg, "EngineTest")
se := schema.NewEngine(env)
se.InitDBConfig(dbconfigs.New(connParams))
return se
}

func TestEngineReload(t *testing.T) {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &connParams)
require.NoError(t, err)
defer conn.Close()
t.Run("validate innodb size query", func(t *testing.T) {
q := conn.BaseShowInnodbTableSizes()
require.NotEmpty(t, q)
})
t.Run("validate conn schema", func(t *testing.T) {
rs, err := conn.ExecuteFetch(`select database() as d`, 1, true)
require.NoError(t, err)
row := rs.Named().Row()
require.NotNil(t, row)
database := row.AsString("d", "")
require.Equal(t, connParams.DbName, database)
})
setupQueries := []string{
`drop view if exists view_simple`,
`drop table if exists tbl_simple`,
`drop table if exists tbl_part`,
`drop table if exists tbl_fts`,
`create table tbl_simple (id int primary key)`,
`create view view_simple as select * from tbl_simple`,
`create table tbl_part (id INT NOT NULL, store_id INT) PARTITION BY HASH(store_id) PARTITIONS 4`,
`create table tbl_fts (id int primary key, name text, fulltext key name_fts (name))`,
}

defer func() {
_, _ = conn.ExecuteFetch(`drop view if exists view_simple`, 1, false)
_, _ = conn.ExecuteFetch(`drop table if exists tbl_simple`, 1, false)
_, _ = conn.ExecuteFetch(`drop table if exists tbl_part`, 1, false)
_, _ = conn.ExecuteFetch(`drop table if exists tbl_fts`, 1, false)
}()
for _, query := range setupQueries {
_, err := conn.ExecuteFetch(query, 1, false)
require.NoError(t, err)
}

expectedTables := []string{
"tbl_simple",
"tbl_part",
"tbl_fts",
"view_simple",
}
engine := newTestSchemaEngine(&connParams)
require.NotNil(t, engine)
err = engine.Open()
require.NoError(t, err)
err = engine.Reload(ctx)
require.NoError(t, err)

schema := engine.GetSchema()
require.NotEmpty(t, schema)
for _, expectTable := range expectedTables {
t.Run(expectTable, func(t *testing.T) {
tbl := engine.GetTable(sqlparser.NewIdentifierCS(expectTable))
require.NotNil(t, tbl)
if expectTable == "view_simple" {
assert.Zero(t, tbl.FileSize)
assert.Zero(t, tbl.AllocatedSize)
} else {
assert.NotZero(t, tbl.FileSize)
assert.NotZero(t, tbl.AllocatedSize)
}
})
}
}

// TestTuple tests that bind variables having tuple values work with vttablet.
func TestTuple(t *testing.T) {
client := framework.NewClient()
Expand Down
1 change: 1 addition & 0 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ func (se *Engine) reload(ctx context.Context, includeStats bool) error {
}
}
}
// See testing in TestEngineReload
}
}
tableData, err := getTableData(ctx, conn.Conn, includeStats)
Expand Down

0 comments on commit 4471468

Please sign in to comment.