This topic describes the configuration parameters for the DMSLockFreeSqlOperator.
Features
This operator executes large-scale, lock-free DML operations using the DMS Chunk DML service. It is ideal for UPDATE or DELETE statements on large tables, as it splits them into smaller batches to prevent long-running table locks.
Parameters
The sql, instance, and database parameters support Jinja templates.
Parameter | Type | Required | Description |
sql | string | Yes | The DML statement (UPDATE or DELETE) to execute. |
instance | string | Yes | The connection name (DBLink) of the DMS-managed database instance. |
database | string | Yes | The name of the database. Note For a MySQL instance, specify only the database name, such as |
callback | function | No | The callback function to process the execution results. |
polling_interval | int | No | The polling interval for the execution status, in seconds. The default is 10. If you set this parameter to 0 or a negative number, the task is submitted, but the operator does not wait for the result. The status check includes a built-in retry mechanism. |
Example
task_id and dag are Airflow-specific parameters. For more information, see the official Airflow documentation.
from airflow import DAG
from airflow.providers.alibabadms.cloud.operators.dms_lock_free_sql import DMSLockFreeSqlOperator
with DAG(
"dms_lock_free_sql_example",
) as dag:
lock_free_task = DMSLockFreeSqlOperator(
task_id="batch_update",
instance="my_mysql_instance",
database="my_database",
sql="UPDATE orders SET status = 'archived' WHERE created_at < '{{ macros.ds_add(ds, -90) }}';",
polling_interval=30,
dag=dag,
)All DMS Airflow operators support common features such as task cancellation and automatic retries. For more information, see Airflow DMS Operator.