Skip to main content

Disaster Recovery and Dual-Active Replication

info

To retain a continuously updated replica in another TDengine cluster, first confirm replication direction, versions, licenses, and WAL retention. Dual-active replication uses dedicated WITH TYPE 'replica' tasks. Each task replicates one direction and one database. Verify replication progress, target data, and business cutover results separately.

Manage dual-active tasks with SQL. The old taosx replica command is deprecated.

Where to operate: run Xnode task SQL in the management cluster's taosExplorer Data Browser or taos CLI. Query subscription progress on the source cluster. Perform business cutover according to the dual-active configuration of the client in use.

Remote disaster recovery retains a replica in another cluster through continuous replication. Dual-active solutions also require failover in applicable clients and loop-prevention mechanisms. Each dual-active task replicates one direction and one database. Bidirectional configuration uses two dedicated replica tasks, not two ordinary TMQ tasks.

1. Choose a Mechanism and Check Prerequisites​

NeedChoice and boundaries
One-way data replicaUse one-way synchronization or one dedicated replication direction according to business goals, with a separate procedure for activating the standby cluster.
Dedicated bidirectional replication and applicable client failoverUse this page's WITH TYPE 'replica' tasks and client configuration.
Protection against accidental deletion and historical restore pointsUse independent backups. Replication propagates data changes and does not replace backups.
Task takeover after execution-node failureThis concerns Xnode deployment and task maintenance, not database dual-active operation or automatic client failover.

Before creation, have the administrator confirm:

  • The management cluster, xnoded, and taosX support this syntax. taosX and taosd versions match, and dual-active support has been confirmed for the distribution in use. Check minimum source/target requirements and cross-version combinations in Dual-Active Solution. Do not upgrade taosX alone.
  • Target databases exist on both sides with equal precision, and source wal_retention_period > 0. Actual retention covers downtime, repair, and catch-up combined, with margin.
  • Both sides meet dual-active licensing requirements, and the target also has corresponding TDengine authorization. The management cluster has a registered Xnode able to reach both sides.
  • Accounts have required permissions for creating and maintaining subscription resources, reading the source, and writing the target. Verify the selected deployment's least-privilege plan; do not copy default superuser passwords.
  • Application database names, accounts, permissions, and driver failover methods are aligned. Replication tasks do not automatically create newly added databases or replicate all application configuration.

2. Create One Replication Direction​

Verify with isolated test databases on both sides first. The following assumes cluster A also acts as the management cluster, both sides have aa_demo prepared, and Xnode can reach the taosAdapters of A and B from its execution host.

Run in A's taosExplorer Data Browser or taos CLI, replacing placeholders:

CREATE XNODE TASK 'aa_demo_a_b'
FROM 'tmq+ws://<源用户>:<编码后的源密码>@<集群A>:6041/aa_demo?auto.offset.reset=earliest&experimental.snapshot.enable=true&msg.consume.start.ts=0'
TO 'taos+ws://<目标用户>:<编码后的目标密码>@<集群B>:6041/aa_demo'
WITH TYPE 'replica';
SHOW XNODE TASKS WHERE type = 'replica';
START XNODE TASK 'aa_demo_a_b';
warning

The task is stopped after creation. Start it explicitly and confirm type=replica in the result.

Do not create dual-active tasks before a rolling upgrade completes: older components may ignore the type option and run them as ordinary tasks.

ConfigurationMeaning and maintenance restrictions
DSN path aa_demoA database here, not a manually created topic name.
auto.offset.reset=earliestStart at the earliest available position if no committed position exists. Existing positions take precedence.
experimental.snapshot.enable=trueReplicate readable historical data first, then read WAL.
msg.consume.start.ts=0A nonnegative Unix millisecond timestamp filtering by records' primary timestamps. 0 disables this time filter.
Topics and consumer groupsThe system generates exclusive identifiers per task. Do not manually specify group.id, client.id, or use.topic.name.

2.1 Bidirectional Dual-Active Configuration Example​

Bidirectional dual-active replication consists of two dedicated tasks in opposite directions. Create and verify A→B above first. Confirm both sides still have isolated test database aa_demo, then use B as management cluster and create B→A in its taosExplorer Data Browser or taos CLI. The task name must be unused:

CREATE XNODE TASK 'aa_demo_b_a'
FROM 'tmq+ws://<源用户>:<编码后的源密码>@<集群B>:6041/aa_demo?auto.offset.reset=earliest&experimental.snapshot.enable=true&msg.consume.start.ts=0'
TO 'taos+ws://<目标用户>:<编码后的目标密码>@<集群A>:6041/aa_demo'
WITH TYPE 'replica';
SHOW XNODE TASKS WHERE type = 'replica';
START XNODE TASK 'aa_demo_b_a';

Both tasks must explicitly use WITH TYPE 'replica', each for one direction and one database. First confirm task status, subscription progress, and arrival of new-primary-key records at the opposite side separately, then drill client failover as described in section 4. Do not test conflict handling by concurrently writing different values with the same primary key on both sides. The old taosx replica start is not part of the current version and cannot replace this SQL.

3. Inspect Status and Per-Partition Progress​

Run in the management cluster's taosExplorer Data Browser or taos CLI:

SHOW XNODE TASKS WHERE type = 'replica';
SELECT id FROM information_schema.ins_cluster;

Record the actual task ID and management cluster ID. ins_cluster is privileged and requires corresponding system-information permissions. Then connect to the source cluster and replace the identifiers below:

SELECT topic_name, vgroup_id, consumer_id, `offset`, `rows`
FROM information_schema.ins_subscriptions
WHERE topic_name = '__replica__<管理集群ID>_<任务ID>'
AND consumer_group = '__replica__<管理集群ID>_<任务ID>';

tsdb: indicates the snapshot phase. wal:<已消费版本>/<最新版本> indicates the WAL phase; the difference helps observe backlog but is neither seconds nor an exact missing-row count. Positions are reported by the consumer and can be ahead of committed positions. rows is the current consumer process's cumulative consumed-row count, resetting on restart, not the target's successful write count. If consumer_id is empty, check whether the task stopped or failed.

4. Verify Data and Business Failover​

  1. Write a new-primary-key record in an isolated test table on A. Record timestamp, value, and tags and query the corresponding record on B.
  2. If reverse replication is configured, write another new-primary-key record on B and query it on A. Do not test undefined conflict handling with simultaneous differing values for one primary key.
  3. Verify schema and historical windows and continuously observe both directions' progress and target values. See Validation and Business Cutover.
  4. If automatic client failover is needed, configure it according to Dual-Active Solution and drill in an approved environment. The documented automatic failover applies to Java connector WebSocket mode, not all drivers or subscription applications.
note

Creating replication tasks does not mean applications support automatic failover. Data appearing in both directions does not prove a recovery drill passed.

5. Error Handling and Maintenance​

SymptomNext action
Creation or startup failsCheck all component versions, database precision, licenses, DSNs, and reason in SHOW XNODE TASKS.
Task is failed with a desired stopped stateFix the cause and explicitly start it. Do not depend on service restart for automatic recovery.
Positions are close but target records are missingCheck earlier WAL gaps, historical retention, and filtered ranges by table and time. Catch-up alone does not justify proceeding.
Long downtime exceeds retentionIdentify the earliest missing time and whether source history remains. Prepare an approved rebuild or backfill plan; do not promise automatic completion.
Task record remains after deletionDistinguish deleting from delete_failed. Fix errors and retry deletion; do not immediately recreate the same mapping.

In the management cluster, pause with STOP XNODE TASK 'aa_demo_a_b'; and resume with START XNODE TASK 'aa_demo_a_b';. Normal stopping commits positions successfully written to the target. Recovery continues from committed positions, still subject to WAL retention, failure acknowledgment, and historical scope.

Subscription starting-position parameters and connection targets cannot be changed arbitrarily after creation. Adjust credentials and permitted runtime parameters according to Xnode SQL Management; stop and restart for changes to take effect. Dedicated tasks do not accept PARSER, VIA, or object-renaming configuration.

6. Rebuild and Legacy Migration Boundaries​

Deletion asynchronously cleans topics, consumer groups, and positions. A successful return does not mean cleanup is complete. Recreate the same mapping only after the task fully disappears. A new task does not inherit old progress. When rebuilding because of a WAL gap, enable historical snapshots and set the start no later than the earliest missing record's primary timestamp, then verify data again.

Legacy dual-active tasks upgraded from v3.3 do not migrate automatically. Record progress and stop old tasks before upgrading, then rebuild through Dedicated Migration for Legacy Dual-Active Tasks. The v3.4.4.2 release notes document migrate_active_active.py for legacy v3.3.6 configurations. By default, it only generates files; stopping or deleting old tasks and creating or starting new tasks each require explicit options. VIA, custom parsers, parallel tasks, and auto.offset.reset=latest require manual handling. Do not infer that arbitrary legacy configurations can be migrated automatically. taosx replica has been removed. Downgrading to versions that do not recognize task types risks replication loops and type loss. Follow the formal downgrade plan rather than simply replacing binaries.

7. Limitations​

This solution does not promise automatic resolution of arbitrary conflicts, zero loss under any failure, or rollback of accidental deletion. Downtime shorter than WAL retention still does not guarantee timely catch-up. Capacity planning must include both repair and replication duration. Drill production disaster recovery regularly and verify data replicas, client failover, and independent backups separately.