PolarDB for MySQL provides the Preemptive DDL feature to prevent Data Definition Language (DDL) operations from failing due to large queries or long-running transactions on tables in read-only nodes.
Symptoms
When you run a DDL operation in a PolarDB for MySQL database, an error occurs indicating that a metadata lock (MDL) cannot be obtained. The following error messages are displayed:
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
Your PolarDB for MySQL cluster must use one of the following revisions:
-
PolarDB for MySQL 5.6: revision 5.6.1.0.43 or later.
-
PolarDB for MySQL 5.7: revision 5.7.1.0.34 or later.
-
PolarDB for MySQL 8.0.1: revision 8.0.1.1.39 or later.
-
PolarDB for MySQL 8.0.2: revision 8.0.2.2.14 or later.
To check the revision of your cluster, see View the version of a cluster.
Limitations
The Preemptive DDL feature is supported only on read-only nodes, not on the primary node.
Usage notes
-
Enabling Preemptive DDL can terminate connections that are accessing the target table on a read-only node or roll back in-progress SQL queries on that table. Use this feature with caution.
-
The Preemptive DDL feature is effective only if 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.
-
For PolarDB for MySQL 8.0.1 and PolarDB for MySQL 8.0.2, this feature does not support rename operations. We recommend that you 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 exclusive metadata (MDL-X) lock and then directs all read-only nodes to acquire the same lock. If a transaction is accessing the target table on a read-only node, the MDL lock synchronization process is blocked. If a read-only node fails to acquire the MDL-X lock within the specified timeout period, the client returns the ERROR 8007 (HY000): Fail to get MDL on replica during DDL synchronize error. This issue is common in PolarDB for MySQL clusters with multiple read-only nodes. The Preemptive DDL feature is designed to address this problem.
Procedure
You can enable the Preemptive DDL feature with the loose_polar_support_mdl_sync_preemption parameter and set the preemption wait timeout with the loose_polar_mdl_sync_preempt_after_wait_second parameter. For more information, see Specify cluster 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 in seconds when an MDL lock synchronization is blocked. If the lock is not acquired after this period, the system initiates the preemption of blocking threads. Valid values: 1 to 31536000. Unit: seconds. Default value: 10. |
Examples
Preemptive DDL disabled
Preemptive DDL enabled
Contact us
If you have any questions about DDL operations, please contact technical support.