1
********************************
2
Replication Slave Administration
3
********************************
5
This page walks you through some common administration tasks when using
6
the replication slave plugin.
14
If you want to determine which slave machines are connected to your
15
master, use the *SHOW PROCESSLIST* command. Slave connections will show
16
up in the output of this command.
18
InnoDB Transaction Log
19
**********************
21
The slave plugin uses the InnoDB transaction log (see
22
:ref:`innodb_transaction_log`) on the master to retrieve replication
23
messages. This transaction log, though stored as an internal table within
24
InnoDB, offers two different views to the table contents. Two tables in
25
the DATA_DICTIONARY schema provide the different views into the transaction
26
log: the SYS_REPLICATION_LOG table and the INNODB_REPLICATION_LOG table.
28
The SYS_REPLICATION_LOG table is read directly by the slave plugin.
29
This table is described as below::
31
drizzle> SHOW CREATE TABLE data_dictionary.sys_replication_log\G
32
*************************** 1. row ***************************
33
Table: SYS_REPLICATION_LOG
34
Create Table: CREATE TABLE `SYS_REPLICATION_LOG` (
38
`END_TIMESTAMP` BIGINT,
41
PRIMARY KEY (`ID`,`SEGID`) USING BTREE,
42
KEY `COMMIT_IDX` (`COMMIT_ID`,`ID`) USING BTREE
43
) ENGINE=InnoDB COLLATE = binary
45
The INNODB_REPLICATION_LOG is similar to the SYS_REPLICATION_LOG, the
46
main difference being that the Google Protobuffer message representing
47
the changed rows is converted to plain text before being output::
49
drizzle> SHOW CREATE TABLE data_dictionary.innodb_replication_log\G
50
*************************** 1. row ***************************
51
Table: INNODB_REPLICATION_LOG
52
Create Table: CREATE TABLE `INNODB_REPLICATION_LOG` (
53
`TRANSACTION_ID` BIGINT NOT NULL,
54
`TRANSACTION_SEGMENT_ID` BIGINT NOT NULL,
55
`COMMIT_ID` BIGINT NOT NULL,
56
`END_TIMESTAMP` BIGINT NOT NULL,
57
`TRANSACTION_MESSAGE_STRING` TEXT COLLATE utf8_general_ci NOT NULL,
58
`TRANSACTION_LENGTH` BIGINT NOT NULL
59
) ENGINE=FunctionEngine COLLATE = utf8_general_ci REPLICATE = FALSE
61
The INNODB_REPLICATION_LOG table is read-only due to the way it is
62
implemented. The SYS_REPLICATION_LOG table, on the other hand, allows you
63
to modify the contents of the transaction log. You would use this table
64
to trim the transaction log.
69
The slave plugin has two types of threads doing all of the work:
71
* An IO (or producer) thread
72
* An applier (or consumer) thread
74
The status of each thread is stored in tables in the *sys_replication*
75
schema. The IO thread status is contained in the *io_state* table, and
76
the applier thread status is in the *applier_state* table. You may query
77
these tables just like any other table. For example::
79
drizzle> SELECT * FROM sys_replication.io_state\G
80
*************************** 1. row ***************************
84
The above shows that the IO thread is **RUNNING**. If there had been
85
an error on the IO thread, the status value would be **STOPPED** and
86
the error_msg column would contain information about the error.
88
We can check the state of the applier thread in a similar manner::
90
drizzle> SELECT * FROM sys_replication.applier_state\G
91
*************************** 1. row ***************************
92
last_applied_commit_id: 4
96
The status and error_msg columns are similar to the ones in the *io_state*
97
table. Also available is the last_applied_commit_id, which contains the
98
value of the COMMIT_ID from the master's replication log (see definition
99
of the data_dictionary.sys_replication_log table above) of the most
100
recently executed transaction.
102
Transaction Log Maintenance
103
###########################
105
Currently, the InnoDB transaction log grows without bounds and is never
106
trimmed of unneeded entries. This can present a problem for long running
107
replication setups. You may trim the log manually, but you must make certain
108
to not remove any entries that are needed by slave servers.
110
Follow these steps to trim the InnoDB transaction without affecting slave
113
#. Query each slave for the *last_applied_commit_id* value from the *sys_replication.applier_state* table.
114
#. Choose the **minimum** value obtained from step one. This will be the marker for the slave that is the furthest behind the master.
115
#. Using this marker value from the previous step, delete all entries from the master's transaction log that has a COMMIT_ID less than the marker value.
117
Below is an example of the steps defined above. First, step 1 and 2. Assume
118
that we have two slave hosts connected to the master (slave-1 and slave-2).
119
We need to query both to check their relationship with the master transaction
122
slave-1> SELECT last_applied_commit_id FROM sys_replication.applier_state\G
123
*************************** 1. row ***************************
124
last_applied_commit_id: 3000
126
slave-2> SELECT last_applied_commit_id FROM sys_replication.applier_state\G
127
*************************** 1. row ***************************
128
last_applied_commit_id: 2877
130
We see that slave-2 has the smallest value for *last_applied_commit_id*. We
131
will use this value in the next step to trim the transaction log on the
134
master> DELETE FROM data_dictionary.sys_replication_log WHERE commit_id < 2877;
136
This will remove all old, unneeded entries from the InnoDB transaction log. Note that the SYS_REPLICATION_LOG table is used for this maintenance task.