Skip to content

Commit

Permalink
ddl/schematracker: fix SetDDL will cause data race (pingcap#36768)
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored and morgo committed Aug 1, 2022
1 parent 6e667ba commit 3db73b4
Show file tree
Hide file tree
Showing 15 changed files with 174 additions and 390 deletions.
14 changes: 3 additions & 11 deletions ddl/column_modify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/schematracker"
testddlutil "github.com/pingcap/tidb/ddl/testutil"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/errno"
Expand All @@ -36,6 +35,7 @@ import (
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/testkit"
Expand Down Expand Up @@ -296,11 +296,7 @@ func TestDropColumn(t *testing.T) {
}

func TestChangeColumn(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomainWithSchemaLease(t, columnModifyLease)

ddlChecker := schematracker.NewChecker(dom.DDL())
dom.SetDDL(ddlChecker)
ddlChecker.CreateTestDB()
store := testkit.CreateMockStoreWithSchemaLease(t, columnModifyLease, mockstore.WithDDLChecker())

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down Expand Up @@ -385,11 +381,7 @@ func TestChangeColumn(t *testing.T) {
}

func TestRenameColumn(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomainWithSchemaLease(t, columnModifyLease)

ddlChecker := schematracker.NewChecker(dom.DDL())
dom.SetDDL(ddlChecker)
ddlChecker.CreateTestDB()
store := testkit.CreateMockStoreWithSchemaLease(t, columnModifyLease, mockstore.WithDDLChecker())

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down
18 changes: 4 additions & 14 deletions ddl/column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ import (

"github.com/pingcap/errors"
"github.com/pingcap/tidb/ddl"
"github.com/pingcap/tidb/ddl/schematracker"
"github.com/pingcap/tidb/domain"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/parser/model"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessiontxn"
"github.com/pingcap/tidb/store/mockstore"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/tables"
"github.com/pingcap/tidb/tablecodec"
Expand Down Expand Up @@ -156,11 +156,7 @@ func testDropColumns(tk *testkit.TestKit, t *testing.T, ctx sessionctx.Context,
}

func TestColumnBasic(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)

ddlChecker := schematracker.NewChecker(dom.DDL())
dom.SetDDL(ddlChecker)
ddlChecker.CreateTestDB()
store, dom := testkit.CreateMockStoreAndDomain(t, mockstore.WithDDLChecker())

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down Expand Up @@ -645,12 +641,9 @@ func testGetColumn(t table.Table, name string, isExist bool) error {
}

func TestAddColumn(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
store, dom := testkit.CreateMockStoreAndDomain(t, mockstore.WithDDLChecker())

d := dom.DDL()
ddlChecker := schematracker.NewChecker(d)
dom.SetDDL(ddlChecker)
ddlChecker.CreateTestDB()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down Expand Up @@ -710,12 +703,9 @@ func TestAddColumn(t *testing.T) {
}

func TestAddColumns(t *testing.T) {
store, dom := testkit.CreateMockStoreAndDomain(t)
store, dom := testkit.CreateMockStoreAndDomain(t, mockstore.WithDDLChecker())

d := dom.DDL()
ddlChecker := schematracker.NewChecker(d)
dom.SetDDL(ddlChecker)
ddlChecker.CreateTestDB()

tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
Expand Down
7 changes: 7 additions & 0 deletions ddl/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,11 @@ const (
ReorgTableID = meta.MaxInt48 - 2
// HistoryTableID is the table ID of `tidb_ddl_history`.
HistoryTableID = meta.MaxInt48 - 3

// JobTableSQL is the CREATE TABLE SQL of `tidb_ddl_job`.
JobTableSQL = "create table " + JobTable + "(job_id bigint not null, reorg int, schema_ids text(65535), table_ids text(65535), job_meta longblob, type int, processing int, primary key(job_id))"
// ReorgTableSQL is the CREATE TABLE SQL of `tidb_ddl_reorg`.
ReorgTableSQL = "create table " + ReorgTable + "(job_id bigint not null, ele_id bigint, ele_type blob, start_key blob, end_key blob, physical_id bigint, reorg_meta longblob, unique key(job_id, ele_id, ele_type(20)))"
// HistoryTableSQL is the CREATE TABLE SQL of `tidb_ddl_history`.
HistoryTableSQL = "create table " + HistoryTable + "(job_id bigint not null, job_meta longblob, db_name char(64), table_name char(64), schema_ids text(65535), table_ids text(65535), create_time datetime, primary key(job_id))"
)
Loading

0 comments on commit 3db73b4

Please sign in to comment.