Multi-source Replication
MariaDB starting with 10.0.1
Multi-source replication means that one server has many masters from which it replicates. This feature was added in MariaDB 10.0.
New Syntax
You specify which master connection you want to work with by either specifying the connection name in the command or setting default_master_connection to the connection you want to work with.
The connection name may include any characters and should be less than 64 characters. Connection names are compared without regard to case (case insensitive). You should preferably keep the connection name short as it will be used as a suffix for relay logs and master info index files.
The new syntax introduced to handle many connections:
CHANGE MASTER ['connection_name'] TO .... This creates or modifies a connection to a master.FLUSH RELAY LOGS ['connection_name']MASTER_POS_WAIT(....,['connection_name'])RESET SLAVE ['connection_name'] [ALL]. This is used to reset slave replication position or to remove a slave permanently.SHOW RELAYLOG ['connection_name'] EVENTSSHOW SLAVE ['connection_name'] STATUSSHOW ALL SLAVES STATUSSTART SLAVE ['connection_name'...]]START ALL SLAVES ...STOP SLAVE ['connection_name'] ...STOP ALL SLAVES ...
The original old-style connection is an empty string ''. You don't have to use this connection if you don't want to.
You create new master connections with CHANGE MASTER.
You delete the connection permanently with RESET SLAVE 'connection_name' ALL.
Replication variables for multi-source
The new replication variable default_master_connection
specifies which connection will be used for commands and variables if you don't
specify a connection. By default this is '' (the default
connection name).
The following replication variables are local for the connection. (In other
words, they show the value for the
@@default_master_connection connection). We are working on
making all the important ones local for the connection.
| Type | Name | Description |
|---|---|---|
| Variable | max_relay_log_size | Max size of relay log. Is set at startup to max_binlog_size if 0 |
| Variable | replicate_do_db | Tell the slave to restrict replication to updates of tables whose names appear in the comma-separated list. For statement-based replication, only the default database (that is, the one selected by USE) is considered, not any explicitly mentioned tables in the query. For row-based replication, the actual names of table(s) being updated are checked. |
| Variable | replicate_do_table | Tells the slave to restrict replication to tables in the comma-separated list |
| Variable | replicate_ignore_db | Tell the slave to restrict replication to updates of tables whose names do not appear in the comma-separated list. For statement-based replication, only the default database (that is, the one selected by USE) is considered, not any explicitly mentioned tables in the query. For row-based replication, the actual names of table(s) being updated are checked. |
| Variable | replicate_ignore_table | Tells the slave thread to not replicate any statement that updates the specified table, even if any other tables might be updated by the same statement. |
| Variable | replicate_wild_do_table | Tells the slave thread to restrict replication to statements where any of the updated tables match the specified database and table name patterns. |
| Variable | replicate_wild_ignore_table | Tells the slave thread to not replicate to the tables that match the given wildcard pattern. |
| Status | Slave_heartbeat_period | How often to request a heartbeat packet from the master (in seconds). |
| Status | Slave_received_heartbeats | How many heartbeats we have got from the master. |
| Status | Slave_running | Shows if the slave is running. YES means that the sql thread and the IO thread are active. No means either one is not running. '' means that @@default_master_connection doesn't exist. |
| Variable | Sql_slave_skip_counter | How many entries in the replication log that should be skipped (mainly used in case of errors in the log). |
You can access all of the above variables with either
SESSION or GLOBAL.
Note that the replicate_... variables were added in MariaDB 10.0.2
Note that in contrast to MySQL, all variables always show the correct active
value!
Example:
set @@default_master_connection='';
show status like 'Slave_running';
set @@default_master_connection='other_connection';
show status like 'Slave_running';
If @@default_master_connection contains a non existing name, you will get a warning.
All other master-related variables are global and affect either only the '' connections or all connections. For example, Slave_retried_transactions now shows the total number of retried transactions over all slaves.
If you need to set gtid_slave_pos you need to set this for all masters at the same time.
New status variables:
| Name | Description |
|---|---|
Com_start_all_slaves |
Number of executed START ALL SLAVES commands. |
Com_start_slave |
Number of executed START SLAVE commands. This replaces Com_slave_start. |
Com_stop_slave |
Number of executed STOP SLAVE commands. This replaces Com_slave_stop. |
Com_stop_all_slaves |
Number of executed STOP ALL SLAVES commands. |
SHOW ALL SLAVES STATUS has the following new columns:
| Name | Description |
|---|---|
Connection_name |
Name of the master connection. This is the first variable. |
Slave_SQL_State |
State of SQL thread. |
Retried_transactions |
Number of retried transactions for this connection. |
Max_relay_log_size |
Max relay log size for this connection. |
Executed_log_entries |
How many log entries the slave has executed. |
Slave_received_heartbeats |
How many heartbeats we have got from the master. |
Slave_heartbeat_period |
How often to request a heartbeat packet from the master (in seconds). |
New files
The basic principle of the new files used by multi source replication is that they have the same name as the original relay log files suffixed with connection_name before the extension. The main exception is the file that holds all connection is named as the normal master-info-file with a multi- prefix.
When you are using multi source, the following new files are created:
| Name | Description |
|---|---|
multi-master-info-file |
The master-info-file (normally master.info) with a multi- prefix. This contains all master connections in use. |
master-info-file-connection_name.extension |
Contains the current master position for what's applied to in the slave. Extension is normally .info |
relay-log-connection_name.xxxxx |
The relay-log name with a connection_name suffix. The xxxxx is the relay log number. This contains the replication data read from the master. |
relay-log-index-connection_name.extension |
Contains the name of the active relay-log-connection_name.xxxxx files. Extension is normally .index |
relay-log-info-file-connection_name.extension |
Contains the current master position for the relay log. Extension is normally .info |
When creating the file, the connection name is converted to lower case and all special characters in the connection name are converted, the same way as MySQL table names are converted. This is done to make the file name portable across different systems.
Hint:
Instead of specifying names for mysqld with --relay-log, --relay-log-index, --relay-log-index, --general-log, --slow-log, --log-bin, --log-bin-index you can just specify --log-base-name and all the other variables are set with this as a prefix.
Other things
- All error messages from a slave with a connection name, that are written to the error log, are prefixed with
Master 'connection_name':. This makes it easy to see from where an error originated. - Errors
ER_MASTER_INFOandWARN_NO_MASTER_INFOnow includes connection_name. - There is no conflict resolution. The assumption is that there are no conflicts in data between the different masters.
- All executed commands are stored in the normal binary log (nothing new here).
- If the server variable
log_warnings> 1 then you will get some information in the log about how the multi-master-info file is updated (mainly for debugging). - SHOW [FULL] SLAVE STATUS has one line per connection and more columns than before. Note that the first column is the
connection_name! RESET SLAVEnow deletes all relay-log files.
replicate-... variables
- The support for
replicate-...variables was added in MariaDB 10.0.2 - One can set the values for the
replicate-...variables from the command line or inmy.cnffor a given connection by prefixing the variable with the connection name. - If one doesn't use any connection name prefix for a
replicate..variable, then the value will be used as the default value for all connections that don't have a value set for this variable.
Example:
mysqld --main_connection.replicate_do_db=main_database --replicate_do_db=other_database
The have sets the replicate_do_db variable to main_database for the connection named main_connection. All other connections will use the value other_database.
One can also use this syntax to set replicate-rewrite-db for a given connection.
Typical use cases
- You are partitioning your data over many masters and would like to get it all together on one machine to do analytical queries on all data.
- You have many databases spread over many MariaDB/MySQL servers and would like to have all of them on one machine as an extra backup.
Limitations
- You can for now only have 64 masters (trivial to increase if necessary).
- Each active connection will create 2 threads (as is normal for MariaDB replication).
- You should ensure that all master have different
server-id's. If you don't do this, you will get into trouble if you try to replicate from the multi-source slave back to your masters. - One can change max_relay_log_size for any active connection, but new connections will always use the server startup value for
max_relay_log_size, which can't be changed at runtime. - Option innodb-recovery-update-relay-log (xtradb feature to store and restore relay log position for slaves) only works for the default connection ''. As this option is not really safe and can easily cause loss of data if you use storage engines other than InnoDB, we don't recommend this option to be used.
- slave_net_timeout affects all connections. We don't check anymore if it's less than Slave_heartbeat_period, as this doesn't make sense in a multi-source setup.
TODO
- Semisync replication ('semisync_slave.so') doesn't yet work with multi-source.
- All open tasks and known bugs for multi-source can be found here.
- Allow replication from one master to one slave in many threads
Incompatibilities with MariaDB/MySQL 5.5
- max_relay_log_size is now (almost) a normal variable and not automatically changed if max_binlog_size is changed. To keep things compatible with old config files, we set it to
max_binlog_sizeat startup if its value is 0. - You can now access replication variables that depend on the active connection with either
GLOBALorSESSION. - We only write information about relay log positions for recovery if innodb-recovery-update-relay-log is set.
- Slave_retried_transactions now shows the total count of retried transactions over all slaves.
- The status variable
Com_slave_startis replaced with Com_start_slave. - The status variable
Com_slave_stopis replaced with Com_stop_slave. FLUSH RELAY LOGSare not replicated anymore. This is not safe as connection names may be different on the slave.
See also
- Using multi-source with global transaction id
- The work in MariaDB is based on the project description at MDEV-253.
- The original code base comes from Taobao, developed by Peng Lixun. A big thanks to them for this important feature!
Comments
HOW TO START A SINGLE MULTI SOURCE REPLICATION WITH WINDOWS + MARIADB 10.0.0
1)Install MariaDB 10.x
2)Open 3 MariaDB terminals
3)Run 3 MariaDB instances, example:
"C:/Program Files/MariaDB 10.0/bin/mysqld" --datadir="C:/Program Files/MariaDB 10.0/data1" --log-error="C:/Program Files/MariaDB 10.0/log/1.log" --port=3306 --server-id=1 --relay_log_space_limit=1024000000 --log-bin=bin1 --binlog-do-db=t1
"C:/Program Files/MariaDB 10.0/bin/mysqld" --datadir="C:/Program Files/MariaDB 10.0/data2" --log-error="C:/Program Files/MariaDB 10.0/log/2.log" --port=3307 --server-id=2 --relay_log_space_limit=1024000000 --log-bin=bin2 --binlog-do-db=t2
"C:/Program Files/MariaDB 10.0/bin/mysqld" --datadir="C:/Program Files/MariaDB 10.0/data3" --log-error="C:/Program Files/MariaDB 10.0/log/3.log" --port=3308 --server-id=3
Here server-id 1 and 2 are masters, and 3 is slave
4)Create database t1 in server-id=1, and t2 in server-id=2, like:
CREATE TABLE t1; CREATE TABLE t2;
5)Check if t1 and t2 exists in server-id=3 (slave), if not create it
6)Configure Masters in server-id=3:
SET @@default_master_connection='t1';
CHANGE MASTER 't1' TO MASTER_HOST = '127.0.0.1', MASTER_USER = 'user', MASTER_PASSWORD = 'password', MASTER_PORT = 3306;
SET @@default_master_connection='t2';
CHANGE MASTER 't2' TO MASTER_HOST = '127.0.0.1', MASTER_USER = 'user', MASTER_PASSWORD = 'password', MASTER_PORT = 3307;
7)Here Slave is up, now let's check status: (at server-id=3) SHOW ALL SLAVES STATUS you will see two connection (if everything is ok)
8)Check Masters: (at server-id=1 and 2)
SHOW MASTER STATUS;
you will see log files and positions
9)Start replications: (at server-id=3)
START ALL SLAVES;
10)TEST IT! =D (open server-id=1)
CREATE TABLE t (a int);
INSERT INTO t VALUES (0),(1),(2),(3);
11)CHECK REPLICATION (open server-id=3)
USE t1;
SELECT * FROM t;
you will see 0,1,2,3 rows! :D
12) BE HAPPY =D
Multi-source Replication的更多相关文章
- mariadb多源复制 muiltil source replication
环境:centos-6.5 Mariadb:10.1.13-MariaDB 多源复制:企业数据库中写的需求较大,以至于I/O负载比较大,那么就必须把写的操作分摊到多台主服务器上进行,然后在将 ...
- mysql-multi source replication 配置
1.关键步骤 change master to master_host='172.16.192.201', master_port, master_user='repl', master_passwo ...
- MYSQL 5.7 新增150多个新功能
http://www.thecompletelistoffeatures.com/ There are over 150 new features in MySQL 5.7. The MySQL ma ...
- 资源list:Github上关于大数据的开源项目、论文等合集
Awesome Big Data A curated list of awesome big data frameworks, resources and other awesomeness. Ins ...
- Awesome Big Data List
https://github.com/onurakpolat/awesome-bigdata A curated list of awesome big data frameworks, resour ...
- Oracle Created Database Users: Password, Usage and Files References (文档 ID 160861.1)
This document is no longer actively maintained, for info on specific (new) users in recent product e ...
- js监控视频播放的事件并打印log
html代码: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" ...
- XtraBackup应用说明(支持TokuDB)
背景: 关于物理备份工具xtrabackup的一些说明可以先看之前写过的文章说明:XtraBackup 安装使用和xtrabackup 使用说明(续),本篇文章将介绍xtrabackup在使用中的注意 ...
- (转)Awsome Domain-Adaptation
Awsome Domain-Adaptation 2018-08-06 19:27:54 This blog is copied from: https://github.com/zhaoxin94/ ...
随机推荐
- Android java取得当前日期增加一天或多天
SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd"); Calendar c = Calendar.getInstanc ...
- [转]【android studio】解决layout预览出现Rendering Problems Exception Unable to find the layout for Action Bar.
在android studio中打开layout文件,发现不能预览布局,提示以下错误: Rendering Problems Exception raised during rendering: Un ...
- (Command Pattern)命令模式
定义 将“请求”封装成对象,以便使用不同的请求.队列或者日志来参数化其他对象.命令模式也支持可撤销的操作. 结构图: 命令模式的角色划分: Reciever(命令的接收者):接收命令,并知道如何进行必 ...
- Excel公式无法重算,暂无法解决
一份复杂的excel报表,某些单元格是用求和公式算出来的值,但生成之后,用excel打开,无法显示公式结果,按F9也没有用,只能在单元格公式双击后回车才会显示.而在WPS2010按F9就可以重算,WP ...
- 一个想了好几天的问题——关于8086cpu自己编写9号中断不能单步的问题
在<汇编语言>第十五章中我们可能遇到这样的问题:程序运行正确,但是debug单步调试,却无法运行,修改int 9h中断例程入口地址的指令,虚拟模式下,debug提示指令无效, ...
- ViewController 的代码规范
1.#pragma mark - life cycle viewDidLoad viewWillAppear 2.#pragma mark - delegate #pragma mark collec ...
- 序列变换(hdu5248)
序列变换 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- 入门训练 A+B问题
http://lx.lanqiao.org/problemset.page?code=BEGIN-&userid=34549 入门训练 A+B问题 时间限制:1.0s 内存限制:2 ...
- CentOs5.2中PHP的升级
最近一个项目中需要使用到PHP5.2的版本,而服务器上使用了官方的yum源进行安装,默认的版本是5.1.6,需要升级.但是因为不是一个非常 正式的服务器环境,所以想通过简单的yum update一下了 ...
- ls -l 列表信息详解
我们平时用ls -l 命令查看一个目录下的文件和子目录的详悉信息时,会得到一个详细的文件和目录名列表.这个列表包含了文件的属性,所属用户,所属组,创建时间,文件大小等等信息.这些信息到底是什么意思呢? ...