Bug #64314 Multi-Master Replication implement
Submitted: 14 Feb 2012 3:10 Modified: 18 Jan 2018 14:22
Reporter: Lixun Peng (OCA) Email Updates:
Status: Won't fix Impact on me:
None 
Category:MySQL Server: Replication Severity:S4 (Feature request)
Version:5.* OS:Any
Assigned to: CPU Architecture:Any
Tags: Contribution, multi-master

[14 Feb 2012 3:10] Lixun Peng
Description:
We have some requirements of Multi-Master Replication.

For example, we have 100 instances. All of them must have online-backup, if one slave can only have one master, we must have 100 slave instances to do online-backup.

Our applications will not modified the same rows in different instances, for example, Instance A have the data of ID in 1~100, Instance B have the data of ID in 101~200, never conflict.

On the other hand, we can use multi-master do HA in different IDC .For example, We  have IDC A  And IDC B . The IDC A is dual-master, and IDC B 
is dual-master too. if we have to synchronize data between IDC A   and IDC B , we can  only use 3rd-party scripts or programs.

       IDC A           |            IDC B
  instance A-1     |       instance B-1
        ^                 |             ^
        |                  |             |
      VIP<----Scripts---->VIP
        |                  |             |
        V                 |             V
  instance A-2     |       instance B-2 
  ( The architecture without Multi-Master Replication)

If we have multi-Master, we can do it like this:
       IDC A            |            IDC B
  instance A-1  <--->   instance B-1
        ^                  |             ^
        |                   |             |
        |                   |             |
        |                   |             |
        V                  |             V
  instance A-2   <--->   instance B-2 
  ( The architecture with Multi-Master Replication)

How to repeat:
my patch usage:

root@localhost : (none) 10:25:54> CHANGE MASTER 'plx2' TO MASTER_HOST='10.20.147.142',MASTER_PORT=3308,MASTER_USER='test',MASTER_PASSWORD='test',LOG_FILE='mysql-bin.000241',MASTER_LOG_POS=238108499;

root@localhost : (none) 10:25:54> slave 'plx2' start;

root@localhost : (none) 10:25:54> slave 'plx2' stop;

root@localhost : (none) 10:51:47> show slave 'plx1' status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 10.20.147.142
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.001992
          Read_Master_Log_Pos: 135672840
               Relay_Log_File: mysql-relay-bin-plx1.000012
                Relay_Log_Pos: 8988514
        Relay_Master_Log_File: mysql-bin.001992
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 135672840
              Relay_Log_Space: 8988674
              Until_Condition: None
               Until_Log_File: 
                Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File: 
           Master_SSL_CA_Path: 
              Master_SSL_Cert: 
            Master_SSL_Cipher: 
               Master_SSL_Key: 
        Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error: 
               Last_SQL_Errno: 0
               Last_SQL_Error: 
1 row in set (0.00 sec)

Suggested fix:
This patch implement multi-master by pass different master_info to change_master/start_slave/stop_slave function.
I implement a class MASTER_INFO_INDEX using which to manage master.info index file(master.info.index) and a hash table. The correspondence between channel identification and master_info will store in the hash table and the channel name store in the index file(master.info.index).
The sake of convenience, I change the syntax of START SLAVE ,  STOP SLAVE ,  CHANGE MASTER  TO, SHOW SLAVE  STATUS to support channel identification like this: START SLAVE 'channel identification ',  STOP SLAVE 'channel identification',  CHANGE MASTER 'channel identification' TO, SHOW SLAVE 'channel identification' STATUS .
In CHANGE MASTER situation, mi will create and insert the point into the hash table if there are no mi correspond to the 'channel identification' in it. otherwise, the point of mi will get from hash table for operating.
[14 Feb 2012 3:12] Lixun Peng
my patch

Attachment: 5.1_mutil_master_repl.patch (application/octet-stream, text), 20.71 KiB.

[14 Feb 2012 14:51] Valeriy Kravchuk
Thank you for the feature request and patch contributed.
[16 Feb 2012 10:48] Lixun Peng
pre patch is base on Percona 5.1.60, this is based on MySQL 5.1.61

Attachment: multi_master_for_5.1.61.patch (application/octet-stream, text), 20.86 KiB.

[21 May 2012 6:59] Lixun Peng
I fix some bugs of my patch, and add "reset slave 'replication name' " command, it's like "reset slave" command.

Attachment: 5.1_mutil_master_repl.patch (application/octet-stream, text), 25.80 KiB.

[3 Dec 2012 2:10] Lixun Peng
Monty has merged it into MariaDB 10.x, could MySQL team merge/implement it, too?

https://code.launchpad.net/~maria-captains/maria/10.0-mdev253
https://kb.askmonty.org/en/multi-source-replication/
[18 Jan 2018 14:22] Margaret Fisher
Posted by developer:
 
The Replication team is currently sorting through outstanding bug reports on our files. Multi-source replication functionality was implemented in MySQL 5.7, which we hope has resolved your needs from this feature request, although we did not use your design and patch. This bug report is accordingly being closed off to indicate that the patch was not accepted into the codebase, but thanks again for your contribution, interest and involvement.