-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
*: refine mysql.tidb_mdl_view #48728
Changes from all commits
df07f0d
624c93c
f6d77d6
7b2f530
6caac1c
b649ad6
4aa07d7
d94c369
7a1d3f8
cd956d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -460,19 +460,18 @@ const ( | |
);` | ||
// CreateMDLView is a view about metadata locks. | ||
CreateMDLView = `CREATE OR REPLACE VIEW mysql.tidb_mdl_view as ( | ||
SELECT job_id, | ||
db_name, | ||
table_name, | ||
query, | ||
SELECT tidb_mdl_info.job_id, | ||
JSON_UNQUOTE(JSON_EXTRACT(cast(cast(job_meta as char) as json), "$.schema_name")) as db_name, | ||
JSON_UNQUOTE(JSON_EXTRACT(cast(cast(job_meta as char) as json), "$.table_name")) as table_name, | ||
JSON_UNQUOTE(JSON_EXTRACT(cast(cast(job_meta as char) as json), "$.query")) as query, | ||
session_id, | ||
txnstart, | ||
cluster_tidb_trx.start_time, | ||
tidb_decode_sql_digests(all_sql_digests, 4096) AS SQL_DIGESTS | ||
FROM information_schema.ddl_jobs, | ||
information_schema.cluster_tidb_trx, | ||
information_schema.cluster_processlist | ||
WHERE (ddl_jobs.state != 'synced' and ddl_jobs.state != 'cancelled') | ||
AND Find_in_set(ddl_jobs.table_id, cluster_tidb_trx.related_table_ids) | ||
AND cluster_tidb_trx.session_id = cluster_processlist.id | ||
FROM mysql.tidb_ddl_job, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TiDB versions less than 6.2 do not have this table. Does this have compatibility issues? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. After testing, the old owner doesn't check if the table exists or not. So there it no compatibility issues for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Got it. Maybe we can create an issue. |
||
mysql.tidb_mdl_info, | ||
information_schema.cluster_tidb_trx | ||
WHERE tidb_ddl_job.job_id=tidb_mdl_info.job_id | ||
AND CONCAT(',', tidb_mdl_info.table_ids, ',') REGEXP CONCAT(',', REPLACE(cluster_tidb_trx.related_table_ids, ',', '|'), ',') != 0 | ||
);` | ||
|
||
// CreatePlanReplayerStatusTable is a table about plan replayer status | ||
|
@@ -1044,6 +1043,7 @@ const ( | |
// version 179 | ||
// enlarge `VARIABLE_VALUE` of `mysql.global_variables` from `varchar(1024)` to `varchar(16383)`. | ||
version179 = 179 | ||
|
||
// version 180 | ||
// add priority/create_time/end_time to `mysql.tidb_global_task`/`mysql.tidb_global_task_history` | ||
// add concurrency/create_time/end_time/digest to `mysql.tidb_background_subtask`/`mysql.tidb_background_subtask_history` | ||
|
@@ -1059,11 +1059,15 @@ const ( | |
// add new system table `mysql.request_unit_by_group`, which is used for | ||
// historical RU consumption by resource group per day. | ||
version182 = 182 | ||
|
||
// version 183 | ||
// replace `mysql.tidb_mdl_view` table | ||
version183 = 183 | ||
) | ||
|
||
// 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 = version183 | ||
|
||
// 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 | ||
|
@@ -1221,6 +1225,7 @@ var ( | |
upgradeToVer180, | ||
upgradeToVer181, | ||
upgradeToVer182, | ||
upgradeToVer183, | ||
} | ||
) | ||
|
||
|
@@ -2977,6 +2982,13 @@ func upgradeToVer182(s sessiontypes.Session, ver int64) { | |
doReentrantDDL(s, CreateRequestUnitByGroupTable) | ||
} | ||
|
||
func upgradeToVer183(s sessiontypes.Session, ver int64) { | ||
if ver >= version183 { | ||
return | ||
} | ||
doReentrantDDL(s, CreateMDLView) | ||
} | ||
|
||
func writeOOMAction(s sessiontypes.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= %?`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3707,6 +3707,11 @@ func (s *session) loadCommonGlobalVariablesIfNeeded() error { | |
} | ||
if s.Value(sessionctx.Initing) != nil { | ||
// When running bootstrap or upgrade, we should not access global storage. | ||
// But we need to init max_allowed_packet to use concat function during bootstrap or upgrade. | ||
err := vars.SetSystemVar(variable.MaxAllowedPacket, strconv.FormatUint(variable.DefMaxAllowedPacket, 10)) | ||
if err != nil { | ||
logutil.BgLogger().Error("set system variable max_allowed_packet error", zap.Error(err)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we return err if it's required? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not always required, only when we need to create or replace this view. Do you think we still need to return an error? |
||
} | ||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check it does return err?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all the SQLs return an error, I don't think it's necessary to check the error since it is just a preparation.