Skip to content

Commit

Permalink
*: tiny update bazel
Browse files Browse the repository at this point in the history
  • Loading branch information
zimulala committed Jun 25, 2024
1 parent c985212 commit 93310a8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion pkg/planner/core/plan_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func planCachePreprocess(ctx context.Context, sctx sessionctx.Context, isNonPrep
schemaNotMatch = true
continue
}
if stmt.tbls[i].Meta().Revision != newTbl.Meta().Revision || tbl.Meta().Revision != newTbl.Meta().Revision {
if stmt.tbls[i].Meta().Revision != newTbl.Meta().Revision || (tbl != nil && tbl.Meta().Revision != newTbl.Meta().Revision) {
schemaNotMatch = true
}
stmt.tbls[i] = newTbl
Expand Down
3 changes: 3 additions & 0 deletions pkg/server/internal/testserverclient/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ go_library(
importpath = "github.com/pingcap/tidb/pkg/server/internal/testserverclient",
visibility = ["//pkg/server:__subpackages__"],
deps = [
"//pkg/ddl/util/callback",
"//pkg/domain",
"//pkg/errno",
"//pkg/kv",
"//pkg/metrics",
"//pkg/parser/model",
"//pkg/parser/mysql",
"//pkg/server",
"//pkg/testkit",
Expand Down
47 changes: 23 additions & 24 deletions pkg/server/internal/testserverclient/server_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2798,12 +2798,12 @@ func (cli *TestServerClient) getNewDB(t *testing.T, overrider configOverrider) *
return testkit.NewDBTestKit(t, db)
}

func MustExec(t *testing.T, ctx context.Context, conn *sql.Conn, sql string) {
func MustExec(ctx context.Context, t *testing.T, conn *sql.Conn, sql string) {
_, err := conn.QueryContext(ctx, sql)
require.NoError(t, err)
}

func MustQuery(t *testing.T, ctx context.Context, cli *TestServerClient, conn *sql.Conn, sql string) {
func MustQuery(ctx context.Context, t *testing.T, cli *TestServerClient, conn *sql.Conn, sql string) {
rs, err := conn.QueryContext(ctx, sql)
require.NoError(t, err)
if rs != nil {
Expand All @@ -2813,9 +2813,8 @@ func MustQuery(t *testing.T, ctx context.Context, cli *TestServerClient, conn *s
}

type sqlWithErr struct {
sql string
expectErr error
stmt *sql.Stmt
stmt *sql.Stmt
sql string
}

type expectQuery struct {
Expand All @@ -2831,28 +2830,28 @@ func (cli *TestServerClient) RunTestIssue53634(t *testing.T, dom *domain.Domain)

conn, err := dbt.GetDB().Conn(ctx)
require.NoError(t, err)
MustExec(t, ctx, conn, "create database test_db_state default charset utf8 default collate utf8_bin")
MustExec(t, ctx, conn, "use test_db_state")
MustExec(t, ctx, conn, `CREATE TABLE stock (
MustExec(ctx, t, conn, "create database test_db_state default charset utf8 default collate utf8_bin")
MustExec(ctx, t, conn, "use test_db_state")
MustExec(ctx, t, conn, `CREATE TABLE stock (
a int NOT NULL,
b char(30) NOT NULL,
c int,
d char(64),
PRIMARY KEY(a,b)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_bin COMMENT='…comment';
`)
MustExec(t, ctx, conn, "insert into stock values(1, 'a', 11, 'x'), (2, 'b', 22, 'y')")
MustExec(t, ctx, conn, "alter table stock add column cct_1 int default 10")
MustExec(t, ctx, conn, "alter table stock modify cct_1 json")
MustExec(t, ctx, conn, "alter table stock add column adc_1 smallint")
defer MustExec(t, ctx, conn, "drop database test_db_state")
MustExec(ctx, t, conn, "insert into stock values(1, 'a', 11, 'x'), (2, 'b', 22, 'y')")
MustExec(ctx, t, conn, "alter table stock add column cct_1 int default 10")
MustExec(ctx, t, conn, "alter table stock modify cct_1 json")
MustExec(ctx, t, conn, "alter table stock add column adc_1 smallint")
defer MustExec(ctx, t, conn, "drop database test_db_state")

sqls := make([]sqlWithErr, 5)
sqls[0] = sqlWithErr{"begin", nil, nil}
sqls[1] = sqlWithErr{"SELECT a, c, d from stock where (a, b) IN ((?, ?),(?, ?)) FOR UPDATE", nil, nil}
sqls[2] = sqlWithErr{"UPDATE stock SET c = ? WHERE a= ? AND b = 'a'", nil, nil}
sqls[3] = sqlWithErr{"UPDATE stock SET c = ?, d = 'z' WHERE a= ? AND b = 'b'", nil, nil}
sqls[4] = sqlWithErr{"commit", nil, nil}
sqls[0] = sqlWithErr{nil, "begin"}
sqls[1] = sqlWithErr{nil, "SELECT a, c, d from stock where (a, b) IN ((?, ?),(?, ?)) FOR UPDATE"}
sqls[2] = sqlWithErr{nil, "UPDATE stock SET c = ? WHERE a= ? AND b = 'a'"}
sqls[3] = sqlWithErr{nil, "UPDATE stock SET c = ?, d = 'z' WHERE a= ? AND b = 'b'"}
sqls[4] = sqlWithErr{nil, "commit"}
dropColumnSQL := "alter table stock drop column cct_1"
query := &expectQuery{sql: "select * from stock;", rows: []string{"1 a 101 x <nil>\n2 b 102 z <nil>"}}
runTestInSchemaState(t, conn, cli, dom, model.StateWriteReorganization, true, dropColumnSQL, sqls, query)
Expand All @@ -2871,7 +2870,7 @@ func runTestInSchemaState(
expectQuery *expectQuery,
) {
ctx := context.Background()
MustExec(t, ctx, conn, "use test_db_state")
MustExec(ctx, t, conn, "use test_db_state")

callback := &callback.TestDDLCallback{Do: dom}
prevState := model.StateNone
Expand All @@ -2885,14 +2884,14 @@ func runTestInSchemaState(
err := dbt.GetDB().Close()
require.NoError(t, err)
}()
MustExec(t, ctx, conn1, "use test_db_state")
MustExec(ctx, t, conn1, "use test_db_state")

for i, sqlWithErr := range sqlWithErrs {
// Start the test txn.
// Step 1: begin(when i = 0).
if i == 0 || i == len(sqlWithErrs)-1 {
sqlWithErr := sqlWithErrs[i]
MustExec(t, ctx, conn1, sqlWithErr.sql)
MustExec(ctx, t, conn1, sqlWithErr.sql)
} else {
// Step 2: prepare stmts.
// SELECT a, c, d from stock where (a, b) IN ((?, ?),(?, ?)) FOR UPDATE
Expand All @@ -2907,7 +2906,7 @@ func runTestInSchemaState(

// Step 3: begin.
sqlWithErr := sqlWithErrs[0]
MustExec(t, ctx, conn1, sqlWithErr.sql)
MustExec(ctx, t, conn1, sqlWithErr.sql)

prevState = model.StateNone
state = model.StateWriteOnly
Expand All @@ -2933,7 +2932,7 @@ func runTestInSchemaState(
_, err = sqlWithErr.stmt.ExecContext(ctx, 100+i, i)
require.NoError(t, err)
} else {
MustQuery(t, ctx, cli, conn1, sqlWithErr.sql)
MustQuery(ctx, t, cli, conn1, sqlWithErr.sql)
}
}
}
Expand All @@ -2945,7 +2944,7 @@ func runTestInSchemaState(
d := dom.DDL()
originalCallback := d.GetHook()
d.SetHook(callback)
MustExec(t, ctx, conn, dropColumnSQL)
MustExec(ctx, t, conn, dropColumnSQL)
require.NoError(t, checkErr)

// Check the result.
Expand Down
2 changes: 2 additions & 0 deletions pkg/server/tests/servertestkit/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ go_library(
"//pkg/util/cpuprofile",
"//pkg/util/topsql/collector/mock",
"//pkg/util/topsql/state",
"@com_github_cockroachdb_errors//:errors",
"@com_github_stretchr_testify//require",
"@io_opencensus_go//stats/view",
"@org_uber_go_zap//:zap",
],
)

0 comments on commit 93310a8

Please sign in to comment.