§ Loop Prevention in Primary-Primary Replication


§ Feature Description

In cross-data-center disaster recovery scenarios, when multi-source replication and primary-primary bidirectional replication are enabled at the same time, data loop problems may occur. The new replicate_server_mode option is used to control the application of only the binlog generated by the adjacent primary node in the multi-source replication channel, and not the binlog generated by other non-adjacent nodes, avoiding data loop problems. Multi-channel primary-primary bidirectional replication can reduce the source-replica configuration changes during data center disaster recovery drills and switchovers. This feature is contributed by the China Mobile Smart Home DBA team (Xu Liang). For more details, refer to: issue#I8E8QB (opens new window).

§ New System Option

System Variable Name replicate_server_mode
Command-Line Format replicate_server_mode[={0|1}]
System Variable replicate_server_mode
Variable Scope Global
Dynamic Variable No
Type bool
Permitted Values [0, 1]
Default 0

Setting it to 1 means only the binlog generated by the adjacent primary node in the multi-source replication channel is applied, and the binlog generated by other non-adjacent nodes is not applied; setting it to 0 means no such constraint is applied when applying binlog.

Reminder: This option is a global option and cannot be dynamically modified online, so it must be set before the instance starts. Attempting to modify it online will result in an error. For example:

greatsql> select @@session.replicate_server_mode;
ERROR 1238 (HY000): Variable 'replicate_server_mode' is a GLOBAL variable

greatsql> select @@global.replicate_server_mode;
+--------------------------------+
| @@global.replicate_server_mode |
+--------------------------------+
|                              0 |
+--------------------------------+
1 row in set (0.00 sec)

greatsql> set global replicate_server_mode = 0;
ERROR 1238 (HY000): Variable 'replicate_server_mode' is a read only variable
1
2
3
4
5
6
7
8
9
10
11
12
13

For more application cases of this feature, please refer to: Cross-Data-Center Multi-Channel Primary-Primary Bidirectional Replication Disaster Recovery Drill Based on GreatSQL (opens new window), Data Center Disaster Recovery Solution Based on MySQL Multi-Channel Primary-Primary Bidirectional Replication (opens new window).

Further Reading

Scan the QR code to follow our WeChat official account

greatsql-wx