1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
# ==== Purpose ====
#
# Sync all servers in an arbitrary replication topology. This works
# only if the servers have been configured with rpl_init.inc (and
# possibly rpl_change_topology.inc).
#
#
# ==== Usage ====
#
# [--let $rpl_only_running_threads= 1]
# [--let $rpl_debug= 1]
# [--let $slave_timeout= NUMBER]
# --source include/rpl_sync.inc
#
# Parameters:
# $rpl_only_running_threads
# By default, this script assumes that both the IO thread and the
# SQL thread are running and fails if one of them is stopped. If
# $rpl_only_running_threads is set, this script first checks
# which slave threads are running:
# - If both threads are running, sync both threads with master.
# - If only IO thread is running, sync IO thread with master.
# - If only SQL thread is running, sync SQL thread with IO thread.
# - If no thread is running, don't sync.
#
# $slave_timeout
# Set the timeout when waiting for threads to sync. See
# include/wait_for_slave_param.inc
#
# $rpl_debug
# See include/rpl_init.inc
#
#
# ==== Side effects ====
#
# Does not change the current connection (note that this is different
# from mysqltest's built-in sync_slave_with_master command).
--let $include_filename= rpl_sync.inc
--source include/begin_include_file.inc
# Compute $rpl_sync_chain if needed. We could have done this in
# rpl_change_topology.inc, but instead we do it here because that
# means we only compute $rpl_sync_chain when it is needed.
if ($rpl_sync_chain_dirty)
{
--source include/rpl_generate_sync_chain.inc
--let $rpl_sync_chain_dirty= 0
}
if ($rpl_debug)
{
--echo \$rpl_sync_chain = '$rpl_sync_chain' \$rpl_only_running_threads= $rpl_only_running_threads
}
if (!$rpl_server_count_length)
{
--die \$rpl_server_count_length is not set. Did you call rpl_init.inc?
}
--let $_rpl_i= 1
--let $_rpl_connect= 0
while ($_rpl_i) {
# $rpl_sync_chain consists of a sequence of sync chains. Each sync
# chain has the form:
#
# <space><server1_1><server1_2>...<server1_N>
#
# So the space character indicates that a new sync chain starts.
--let $_rpl_server= `SELECT TRIM(SUBSTR('$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
if ($_rpl_server)
{
if ($rpl_debug)
{
--echo [sync server_$_rpl_prev_server -> server_$_rpl_server]
}
if ($rpl_only_running_threads)
{
disable_connect_log;
--connection server_$_rpl_server
enable_connect_log;
--let $_rpl_slave_io_running= query_get_value(SHOW SLAVE STATUS, Slave_IO_Running, 1)
--let $_rpl_slave_sql_running= query_get_value(SHOW SLAVE STATUS, Slave_SQL_Running, 1)
if ($rpl_debug)
{
--echo Sync IO: $_rpl_slave_io_running; Sync SQL: $_rpl_slave_sql_running
}
--let $_rpl_slave_io_running= `SELECT IF('$_rpl_slave_io_running' != 'No', 1, '')`
--let $_rpl_slave_sql_running= `SELECT IF('$_rpl_slave_sql_running' = 'Yes', 1, '')`
if ($_rpl_slave_io_running)
{
disable_query_log;
--connection server_$_rpl_prev_server
enable_query_log;
if ($_rpl_slave_sql_running)
{
if ($rpl_debug)
{
--let $_rpl_master_file= query_get_value("SHOW MASTER STATUS", File, 1)
--let $_rpl_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
--echo syncing master_file='$_rpl_master_file' master_pos='$_rpl_master_pos'
}
disable_connect_log;
--sync_slave_with_master server_$_rpl_server
enable_connect_log;
}
if (!$_rpl_slave_sql_running)
{
--let $sync_slave_connection= server_$_rpl_server
--source include/sync_slave_io_with_master.inc
}
}
if (!$_rpl_slave_io_running)
{
if ($_rpl_slave_sql_running)
{
--source include/sync_slave_sql_with_io.inc
}
}
}
if (!$rpl_only_running_threads)
{
disable_connect_log;
--connection server_$_rpl_prev_server
if ($rpl_debug)
{
--let $_rpl_master_file= query_get_value("SHOW MASTER STATUS", File, 1)
--let $_rpl_master_pos= query_get_value("SHOW MASTER STATUS", Position, 1)
--echo syncing master_file='$_rpl_master_file' master_pos='$_rpl_master_pos'
}
--sync_slave_with_master server_$_rpl_server
enable_connect_log;
}
}
# This happens at the beginning of a new sync subchain and at the
# end of the full sync chain.
if (!$_rpl_server)
{
--inc $_rpl_i
--let $_rpl_server= `SELECT TRIM(SUBSTR('$rpl_sync_chain', 1 + ($_rpl_i - 1) * $rpl_server_count_length, $rpl_server_count_length))`
if (!$_rpl_server)
{
# terminate loop
--let $_rpl_i= -1
}
}
--let $_rpl_prev_server= $_rpl_server
--inc $_rpl_i
}
--let $include_filename= rpl_sync.inc
--source include/end_include_file.inc
|