Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ttl: add system table for TTL status (#39315) #39619

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion executor/infoschema_cluster_table_test.go
Original file line number Diff line number Diff line change
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
35 changes: 34 additions & 1 deletion session/bootstrap.go
Original file line number Diff line number Diff line change
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,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
Expand Down Expand Up @@ -826,6 +848,7 @@ var (
upgradeToVer105,
upgradeToVer106,
upgradeToVer107,
upgradeToVer108,
}
)

Expand Down Expand Up @@ -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= %?`,
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions session/bootstrap_test.go
Original file line number Diff line number Diff line change
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