Skip to content

Commit

Permalink
bootstrap: revert ddl_jobs table change (#49919)
Browse files Browse the repository at this point in the history
close #49899
  • Loading branch information
okJiang authored Jan 2, 2024
1 parent a6ba2ec commit 1b0a77f
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 24 deletions.
2 changes: 0 additions & 2 deletions pkg/ddl/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ const (
job_meta longblob,
type int,
processing int,
bdr_role varchar(64),
primary key(job_id))`
// ReorgTableSQL is the CREATE TABLE SQL of `tidb_ddl_reorg`.
ReorgTableSQL = "create table " + ReorgTable + `(
Expand All @@ -69,7 +68,6 @@ const (
schema_ids text(65535),
table_ids text(65535),
create_time datetime,
bdr_role varchar(64),
primary key(job_id))`
// BackgroundSubtaskTableSQL is the CREATE TABLE SQL of `tidb_background_subtask`.
BackgroundSubtaskTableSQL = `create table tidb_background_subtask (
Expand Down
3 changes: 1 addition & 2 deletions pkg/ddl/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -1827,12 +1827,11 @@ func addHistoryDDLJob2Table(sess *sess.Session, job *model.Job, updateRawArgs bo
return err
}
_, err = sess.Execute(context.Background(),
fmt.Sprintf("insert ignore into mysql.tidb_ddl_history(job_id, job_meta, db_name, table_name, schema_ids, table_ids, create_time, bdr_role) values (%d, %s, %s, %s, %s, %s, %v, '%s')",
fmt.Sprintf("insert ignore into mysql.tidb_ddl_history(job_id, job_meta, db_name, table_name, schema_ids, table_ids, create_time) values (%d, %s, %s, %s, %s, %s, %v)",
job.ID, util.WrapKey2String(b), strconv.Quote(job.SchemaName), strconv.Quote(job.TableName),
strconv.Quote(strconv.FormatInt(job.SchemaID, 10)),
strconv.Quote(strconv.FormatInt(job.TableID, 10)),
strconv.Quote(model.TSConvert2Time(job.StartTS).String()),
job.BDRRole,
),
"insert_history")
return errors.Trace(err)
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/job_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func (d *ddl) getTableByTxn(r autoid.Requirement, schemaID, tableID int64) (*mod
}

const (
addDDLJobSQL = "insert into mysql.tidb_ddl_job(job_id, reorg, schema_ids, table_ids, job_meta, type, processing, bdr_role) values"
addDDLJobSQL = "insert into mysql.tidb_ddl_job(job_id, reorg, schema_ids, table_ids, job_meta, type, processing) values"
updateDDLJobSQL = "update mysql.tidb_ddl_job set job_meta = %s where job_id = %d"
)

Expand All @@ -494,7 +494,7 @@ func insertDDLJobs2Table(se *sess.Session, updateRawArgs bool, jobs ...*model.Jo
if i != 0 {
sql.WriteString(",")
}
fmt.Fprintf(&sql, "(%d, %t, %s, %s, %s, %d, %t, '%s')", job.ID, job.MayNeedReorg(), strconv.Quote(job2SchemaIDs(job)), strconv.Quote(job2TableIDs(job)), util.WrapKey2String(b), job.Type, !job.NotStarted(), job.BDRRole)
fmt.Fprintf(&sql, "(%d, %t, %s, %s, %s, %d, %t)", job.ID, job.MayNeedReorg(), strconv.Quote(job2SchemaIDs(job)), strconv.Quote(job2TableIDs(job)), util.WrapKey2String(b), job.Type, !job.NotStarted())
}
se.SetDiskFullOpt(kvrpcpb.DiskFullOpt_AllowedOnAlmostFull)
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnDDL)
Expand Down
2 changes: 1 addition & 1 deletion pkg/ddl/modify_column_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ func TestModifyColumnReorgInfo(t *testing.T) {
}
// check the consistency of the tables.
currJobID := strconv.FormatInt(currJob.ID, 10)
tk.MustQuery("select job_id, reorg, schema_ids, table_ids, type, processing, bdr_role from mysql.tidb_ddl_job where job_id = " + currJobID).Check(testkit.Rows())
tk.MustQuery("select job_id, reorg, schema_ids, table_ids, type, processing from mysql.tidb_ddl_job where job_id = " + currJobID).Check(testkit.Rows())
tk.MustQuery("select job_id from mysql.tidb_ddl_history where job_id = " + currJobID).Check(testkit.Rows(currJobID))
tk.MustQuery("select job_id, ele_id, ele_type, physical_id from mysql.tidb_ddl_reorg where job_id = " + currJobID).Check(testkit.Rows())
require.NoError(t, sessiontxn.NewTxn(context.Background(), ctx))
Expand Down
4 changes: 2 additions & 2 deletions pkg/ddl/stat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ func addDDLJobs(sess sessiontypes.Session, txn kv.Transaction, job *model.Job) e
if err != nil {
return err
}
_, err = sess.Execute(kv.WithInternalSourceType(context.Background(), kv.InternalTxnDDL), fmt.Sprintf("insert into mysql.tidb_ddl_job(job_id, reorg, schema_ids, table_ids, job_meta, type, processing, bdr_role) values (%d, %t, %s, %s, %s, %d, %t, '%s')",
job.ID, job.MayNeedReorg(), strconv.Quote(strconv.FormatInt(job.SchemaID, 10)), strconv.Quote(strconv.FormatInt(job.TableID, 10)), util.WrapKey2String(b), job.Type, false, job.BDRRole))
_, err = sess.Execute(kv.WithInternalSourceType(context.Background(), kv.InternalTxnDDL), fmt.Sprintf("insert into mysql.tidb_ddl_job(job_id, reorg, schema_ids, table_ids, job_meta, type, processing) values (%d, %t, %s, %s, %s, %d, %t)",
job.ID, job.MayNeedReorg(), strconv.Quote(strconv.FormatInt(job.SchemaID, 10)), strconv.Quote(strconv.FormatInt(job.TableID, 10)), util.WrapKey2String(b), job.Type, false))
return err
}

Expand Down
17 changes: 2 additions & 15 deletions pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1039,17 +1039,13 @@ const (
version180 = 180

// version 181
// add column `bdr_role` to `mysql.tidb_ddl_job` and `mysql.tidb_ddl_history`.
version181 = 181

// version 182
// set tidb_txn_mode to Optimistic when tidb_txn_mode is not set.
version182 = 182
version181 = 181
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version182
var currentBootstrapVersion int64 = version181

// DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it.
var internalSQLTimeout = owner.ManagerSessionTTL + 15
Expand Down Expand Up @@ -1206,7 +1202,6 @@ var (
upgradeToVer179,
upgradeToVer180,
upgradeToVer181,
upgradeToVer182,
}
)

Expand Down Expand Up @@ -2949,14 +2944,6 @@ func upgradeToVer181(s sessiontypes.Session, ver int64) {
if ver >= version181 {
return
}
doReentrantDDL(s, "ALTER TABLE mysql.tidb_ddl_job ADD COLUMN `bdr_role` varchar(64)", infoschema.ErrColumnExists)
doReentrantDDL(s, "ALTER TABLE mysql.tidb_ddl_history ADD COLUMN `bdr_role` varchar(64)", infoschema.ErrColumnExists)
}

func upgradeToVer182(s sessiontypes.Session, ver int64) {
if ver >= version182 {
return
}
sql := fmt.Sprintf("INSERT HIGH_PRIORITY IGNORE INTO %s.%s VALUES('%s', '%s')",
mysql.SystemDB, mysql.GlobalVariablesTable,
variable.TiDBTxnMode, variable.OptimisticTxnMode)
Expand Down

0 comments on commit 1b0a77f

Please sign in to comment.