From 998315b28f13b760d5b291e3542ec7304ad3d6c7 Mon Sep 17 00:00:00 2001 From: YangKeao Date: Mon, 5 Dec 2022 02:44:03 -0500 Subject: [PATCH] This is an automated cherry-pick of #39315 Signed-off-by: ti-chi-bot Signed-off-by: YangKeao --- executor/infoschema_cluster_table_test.go | 2 +- session/bootstrap.go | 35 ++++++++++++++++++++++- session/bootstrap_test.go | 3 ++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/executor/infoschema_cluster_table_test.go b/executor/infoschema_cluster_table_test.go index 3633daf1945e2..bdf7ac14235e5 100644 --- a/executor/infoschema_cluster_table_test.go +++ b/executor/infoschema_cluster_table_test.go @@ -290,7 +290,7 @@ func TestTableStorageStats(t *testing.T) { "test 2", )) rows := tk.MustQuery("select TABLE_NAME from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql';").Rows() - result := 41 + result := 42 require.Len(t, rows, result) // More tests about the privileges. diff --git a/session/bootstrap.go b/session/bootstrap.go index bb4c23ae5baab..a3c98a014b4e2 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -476,6 +476,26 @@ const ( Password text, PRIMARY KEY (Host,User,Password_timestamp ) ) COMMENT='Password history for user accounts' ` + + // CreateTTLTableStatus is a table about TTL task schedule + CreateTTLTableStatus = `CREATE TABLE IF NOT EXISTS mysql.tidb_ttl_table_status ( + table_id bigint(64) PRIMARY KEY, + parent_table_id bigint(64), + table_statistics text DEFAULT NULL, + last_job_id varchar(64) DEFAULT NULL, + last_job_start_time timestamp NULL DEFAULT NULL, + last_job_finish_time timestamp NULL DEFAULT NULL, + last_job_ttl_expire timestamp NULL DEFAULT NULL, + last_job_summary text DEFAULT NULL, + current_job_id varchar(64) DEFAULT NULL, + current_job_owner_id varchar(64) DEFAULT NULL, + current_job_owner_addr varchar(256) DEFAULT NULL, + current_job_owner_hb_time timestamp, + current_job_start_time timestamp NULL DEFAULT NULL, + current_job_ttl_expire timestamp NULL DEFAULT NULL, + current_job_state text DEFAULT NULL, + current_job_status varchar(64) DEFAULT NULL, + current_job_status_update_time timestamp NULL DEFAULT NULL);` ) // bootstrap initiates system DB for a store. @@ -710,11 +730,13 @@ const ( version106 = 106 // version107 add columns related to password expiration into mysql.user version107 = 107 + // version108 adds the table tidb_ttl_table_status + version108 = 108 ) // 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 = version107 +var currentBootstrapVersion int64 = version108 // 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 @@ -826,6 +848,7 @@ var ( upgradeToVer105, upgradeToVer106, upgradeToVer107, + upgradeToVer108, } ) @@ -2160,6 +2183,14 @@ func upgradeToVer107(s Session, ver int64) { doReentrantDDL(s, "ALTER TABLE mysql.user ADD COLUMN IF NOT EXISTS `Password_lifetime` SMALLINT UNSIGNED DEFAULT NULL") } +func upgradeToVer108(s Session, ver int64) { + if ver >= version108 { + return + } + + doReentrantDDL(s, CreateTTLTableStatus) +} + func writeOOMAction(s Session) { comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+" mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`, @@ -2264,6 +2295,8 @@ func doDDLWorks(s Session) { mustExecute(s, CreatePlanReplayerTaskTable) // Create stats_meta_table_locked table mustExecute(s, CreateStatsTableLocked) + // Create tidb_ttl_table_status table + mustExecute(s, CreateTTLTableStatus) } // inTestSuite checks if we are bootstrapping in the context of tests. diff --git a/session/bootstrap_test.go b/session/bootstrap_test.go index 19c3c71a4a125..f7ced237b0170 100644 --- a/session/bootstrap_test.go +++ b/session/bootstrap_test.go @@ -216,6 +216,9 @@ func TestBootstrapWithError(t *testing.T) { require.Equal(t, 1, row.Len()) require.Equal(t, []byte("True"), row.GetBytes(0)) require.NoError(t, r.Close()) + + // Check tidb_ttl_table_status table + mustExec(t, se, "SELECT * from mysql.tidb_ttl_table_status").Close() } // TestUpgrade tests upgrading