Bidirectional replication
With bidirectional replication, both universes can perform reads and writes, and writes are replicated in both directions. This is also referred to as Active-active multi-master.
You set up bidirectional replication using YugabyteDB Anywhere by creating two separate non-transactional xCluster Replication configurations. Under this scenario, you create a replication configuration from universe A to universe B, and then you create a new replication configuration from universe B to universe A.
YugabyteDB Anywhere detects an xCluster setup is for bidirectional if the tables that are being added to the replication are already part of a replication in the reverse direction (from A to B). In this scenario, YugabyteDB Anywhere skips the full copy for tables on universe B that are already in replication.
Bidirectional xCluster deployment
Due to its operational complexity, bidirectional xCluster is not recommended for most use cases. If you are considering a bidirectional xCluster deployment, contact Yugabyte Support.Limitations
In addition to the regular limitations, Bidirectional replication can only be done using non-transactional replication.
Prerequisites
Create two universes as described in Set up xCluster Replication Prerequisites.
Set up bidirectional replication
To set up bidirectional replication from universe A to universe B, and vice versa on the same set of tables or databases, do the following:
-
Make sure that there are no writes happening on universe B.
-
Set up xCluster Replication from A to B following the steps in Deploy xCluster. A full copy of the selected tables or databases may be performed as part of this operation.
-
Set up xCluster Replication from universe B to A following the steps in Deploy xCluster.
No full copy is performed for the reverse replication. It is important to have no writes on B during this setup, as these writes might not be replicated to universe A.
For information on how to monitor and manage the replication configurations, refer to Monitoring and alerts.
Add a database to an existing bidirectional replication
To add a newly created database to bidirectional replication, follow the instructions in Add a database to an existing replication in both directions.
For best results, add databases to bidirectional configurations right after you create them, and before any writes are performed on the tables in them.
You can add databases that have data to replication in both directions, but note that YugabyteDB Anywhere performs a full copy from the source to the target, and this causes the existing database on the target to be re-created.
Restart bidirectional replication
In case of an extended network partition, or if replication is broken for any other reason, you may need to restart replication.
Before restarting bidirectional replication, you need to identify the universe whose data is more up to date.
To restart a bidirectional replication setup:
- Identify the universe whose data is more up to date.
- Delete the replication configuration where this universe is the target universe.
- Restart the other replication configuration, where this universe is the source universe.
- Set up the replication configuration deleted in step (2) again, with this universe as the target universe.
Note that restarting one side of an existing bidirectional replication configuration without performing step 2 simply re-establishes the replication configuration from the current data without performing a full copy. This can cause inconsistencies in the data between the source and target universes.
DDL operations in bidirectional replication
In general, for DDL operations, you can follow the steps in Manage tables and indexes while taking care to update the xCluster Replication configuration on both configurations involved.
However, in some special cases, you need to follow different procedures.
Add table or partition
It is highly recommended that you add tables to bidirectional configurations immediately after creating them and before any writes are performed.
To add a table to bidirectional replication:
- Add the table to both universes.
- Add the table to both replication configurations by following the steps in Add a table to xCluster Replication.
Non-empty tables can still be added to replication in both directions as above, but this is not advisable. In this case, no full copy is performed so any initial writes to the table are not replicated and data might be inconsistent between the source and target universes. To fix any inconsistencies, restart the replication.
Add index table
To add an index table to a bidirectional replication, do the following:
- Stop the workload on the main table.
- Wait for the replication lag for the corresponding main table to become 0.
- Create the index table on both universes.
- Add the newly created index tables to both replication configurations by following the steps in Add a table to xCluster Replication.
Note: If the main table has data, and the index table is added to the replication configurations without stopping the workload against the main table, the index table can be potentially inconsistent between the two universes.