PolarDB for MySQL provides the Preemptive DDL feature. Preemptive DDL prevents Data Definition Language (DDL) operations from failing because of large queries and long-running transactions on tables in read-only nodes.
Symptoms
When you run a DDL operation in a PolarDB for MySQL database, the system cannot obtain a metadata lock (MDL) and returns the following error:
ERROR HY000: Fail to get MDL on replica during DDL synchronizeERROR HY000: Fail to get table lock on replica; you can 'set polar_support_mdl_sync_preemption = ON' and try restarting transaction
Prerequisites
PolarDB for MySQL clusters must run one of the following versions:
-
5.6 with revision 5.6.1.0.43 or later.
-
5.7 with revision 5.7.1.0.34 or later.
-
8.0.1 with revision 8.0.1.1.39 or later.
-
8.0.2 with revision 8.0.2.2.14 or later.
To view the cluster version, see Checking the engine version.
Limits
Only read-only nodes support the Preemptive DDL feature. The primary node does not support this feature.
Usage notes
-
Enabling the Preemptive DDL feature may interrupt connections that access the current table on a read-only node or roll back unfinished SQL statements on that table. Proceed with caution.
-
Only when the value of the loose_replica_lock_wait_timeout parameter is greater than the value of the loose_polar_mdl_sync_preempt_after_wait_second parameter plus 5 does the Preemptive DDL feature take effect.
-
MySQL 8.0.1 and MySQL 8.0.2 do not support Preemptive DDL on the rename path. Use the
alter table renamestatement instead.
Background information
PolarDB for MySQL uses a shared storage architecture. When you run a DDL operation, the primary node first acquires an MDL-X lock and then notifies the read-only nodes to acquire an MDL-X lock. If a transaction is accessing the table on a read-only node, the MDL lock synchronization thread is blocked. If the read-only node cannot acquire the MDL-X lock within the timeout period, the client returns the ERROR 8007 (HY000): Fail to get MDL on replica during DDL synchronize error. In PolarDB for MySQL clusters with multiple read-only nodes, MDL lock synchronization often fails and causes DDL operations to fail. Preemptive DDL was added to address this issue.
Procedure
Enable the Preemptive DDL feature by using the loose_polar_support_mdl_sync_preemption parameter, and set the wait timeout used during preemption by using the loose_polar_mdl_sync_preempt_after_wait_second parameter. For instructions, see Set cluster parameters and node parameters. The following table describes the parameters.
|
Parameter |
Level |
Description |
|
loose_polar_support_mdl_sync_preemption |
Session |
Controls the Preemptive DDL feature. Valid values:
|
|
loose_polar_mdl_sync_preempt_after_wait_second |
Global |
Specifies the wait timeout when MDL lock synchronization is blocked. If the MDL lock is still not synchronized after this period, the system starts preempting threads. Valid values: 1 to 31536000. Unit: seconds. Default value: 10. |
Examples
Preemptive DDL disabled
Preemptive DDL enabled
Contact us
If you have questions about DDL operations, Contact us.