~ubuntu-branches/ubuntu/maverick/mysql-5.1/maverick-proposed

« back to all changes in this revision

Viewing changes to mysql-test/include/rpl_sync.inc

  • Committer: Package Import Robot
  • Author(s): Marc Deslauriers
  • Date: 2012-02-22 14:16:05 UTC
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: package-import@ubuntu.com-20120222141605-nxlu9yzc6attylc2
Tags: upstream-5.1.61
ImportĀ upstreamĀ versionĀ 5.1.61

Show diffs side-by-side

added added

removed removed

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