Skip to content

Commit

Permalink
ttl: add system table for TTL status (#39315)
Browse files Browse the repository at this point in the history
close #39272
  • Loading branch information
YangKeao committed Dec 5, 2022
1 parent 2d30149 commit a7c4c71
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion executor/infoschema_cluster_table_test.go
Expand Up @@ -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.
Expand Down
32 changes: 32 additions & 0 deletions session/bootstrap.go
Expand Up @@ -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.
Expand Down Expand Up @@ -710,6 +730,8 @@ const (
version106 = 106
// version107 add columns related to password expiration into mysql.user
version107 = 107
// version107 adds the table tidb_ttl_table_status
version108 = 108
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
Expand Down Expand Up @@ -826,6 +848,7 @@ var (
upgradeToVer105,
upgradeToVer106,
upgradeToVer107,
upgradeToVer108,
}
)

Expand Down Expand Up @@ -2160,6 +2183,13 @@ func upgradeToVer107(s Session, ver int64) {
"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= %?`,
Expand Down Expand Up @@ -2264,6 +2294,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.
Expand Down
3 changes: 3 additions & 0 deletions session/bootstrap_test.go
Expand Up @@ -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
Expand Down

0 comments on commit a7c4c71

Please sign in to comment.