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.
Síntomas
Cuando se ejecuta una operación DDL en una base de datos de PolarDB for MySQL, se produce un error que indica que no se puede obtener un bloqueo de metadatos (MDL). A continuación se muestran los mensajes de error:
ERROR HY000: Fail to get MDL on replica during DDL synchronize
ERROR HY000: Fail to get table lock on replica; you can 'set polar_support_mdl_sync_preemption = ON' and try restarting transaction
Requisitos previos
El clúster de PolarDB for MySQL debe usar una de las siguientes revisiones:
PolarDB for MySQL 5.6: revisión 5.6.1.0.43 o posterior.
PolarDB for MySQL 5.7: revisión 5.7.1.0.34 o posterior.
PolarDB for MySQL 8.0.1: revisión 8.0.1.1.39 o posterior.
PolarDB for MySQL 8.0.2: revisión 8.0.2.2.14 o posterior.
Para comprobar la revisión del clúster, consulte View the version of a cluster.
Limitations
La función Preemptive DDL feature solo es compatible con nodos de solo lectura, no con el nodo principal.
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.
En PolarDB for MySQL 8.0.1 y PolarDB for MySQL 8.0.2, esta función no admite operaciones de cambio de nombre. Se recomienda usar la instrucción
ALTER TABLE ... RENAMEen su lugar.
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.
|
Parámetro |
Nivel |
Descripción |
|
loose_polar_support_mdl_sync_preemption |
Session |
Controla la función Preemptive DDL. Valores válidos:
|
|
loose_polar_mdl_sync_preempt_after_wait_second |
Global |
Especifica el tiempo de espera en segundos cuando se bloquea la sincronización de un bloqueo MDL. Si no se adquiere el bloqueo después de este periodo, el sistema inicia la apropiación de los hilos que lo bloquean. Valores válidos: de 1 a 31536000. Unidad: segundos. Valor predeterminado: 10. |
Ejemplos
Preemptive DDL disabled
Preemptive DDL enabled
Contacto
Si tiene dudas sobre las operaciones DDL, Contact us.