Merge lp:~akopytov/percona-xtrabackup/i25625-bug1037379-2.0 into lp:percona-xtrabackup/2.0

Proposed by Alexey Kopytov
Status: Merged
Approved by: Laurynas Biveinis
Approved revision: no longer in the source branch.
Merged at revision: 472
Proposed branch: lp:~akopytov/percona-xtrabackup/i25625-bug1037379-2.0
Merge into: lp:percona-xtrabackup/2.0
Diff against target: 205 lines (+131/-9)
3 files modified
innobackupex (+21/-9)
test/inc/common.sh (+41/-0)
test/t/bug1037379.sh (+69/-0)
To merge this branch: bzr merge lp:~akopytov/percona-xtrabackup/i25625-bug1037379-2.0
Reviewer Review Type Date Requested Status
Laurynas Biveinis (community) Approve
Review via email: mp+129931@code.launchpad.net

Description of the change

  Bug #1037379: SQL_THREAD left in stopped state of
                safe-slave-backup-timeout is reached

  Bug #887803: innobackupex --safe-slave-backup-timeout option doesn't
               work

  The problem in bug #1037379 was that wait_for_safe_slave() in
  innobackupex ran START/STOP SLAVE SQL_THREAD in a loop. If it succeeded
  in getting slave_open_temp_tables to 0 in a specified time out, the
  SQL thread was then started later after copying non-transactional
  data. However, when it reached the timeout it did not restart the SQL
  thread before terminating with an error.

  Another problem was that if wait_for_safe_slave() succeeded,
  innobackupex would start the SQL thread regardless of its initial
  state. Which might be an undesired side effect.

  Fixed by:

  1. Checking the initial SQL thread state and starting it before
  terminating with a timeout error in wait_for_safe_slave().

  2. Starting the SQL thread only if it was running initially in backup()

  Additionally, this revision also fixes bug #887803, because the test
  case for bug #1037379 requires a working --safe-slave-backup-timeout
  option.

To post a comment you must log in.
Revision history for this message
Alexey Kopytov (akopytov) wrote :

Issue #25625.

Revision history for this message
Alexey Kopytov (akopytov) wrote :
Revision history for this message
Laurynas Biveinis (laurynas-biveinis) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'innobackupex'
2--- innobackupex 2012-09-21 12:32:30 +0000
3+++ innobackupex 2012-10-16 15:41:24 +0000
4@@ -137,8 +137,8 @@
5 # backup my.cnf file
6 my $backup_config_file = '';
7
8-# whether host is detected as slave in safe slave backup mode
9-my $host_is_slave = 0;
10+# whether slave SQL thread is running when wait_for_safe_slave() is called
11+my $sql_thread_started = 0;
12
13 # options from the options file
14 my %config;
15@@ -431,7 +431,7 @@
16 # release read locks on all tables
17 mysql_unlockall() if !$option_no_lock;
18
19- if ( $option_safe_slave_backup && $host_is_slave ) {
20+ if ( $option_safe_slave_backup && $sql_thread_started) {
21 print STDERR "$prefix: Starting slave SQL thread\n";
22 mysql_send('START SLAVE SQL_THREAD;');
23 }
24@@ -1825,7 +1825,7 @@
25 'sshopt=s' => \$option_ssh_opt,
26 'parallel=i' => \$option_parallel,
27 'safe-slave-backup' => \$option_safe_slave_backup,
28- 'safe-slave-backup-timeout' => $option_safe_slave_backup_timeout,
29+ 'safe-slave-backup-timeout=i' => \$option_safe_slave_backup_timeout,
30 );
31
32 if (!$rcode) {
33@@ -2630,22 +2630,28 @@
34 # Slave_open_temp_tables has to be zero. Dies on timeout.
35 sub wait_for_safe_slave {
36 my @lines;
37-
38- $host_is_slave = 0;
39+ # whether host is detected as slave in safe slave backup mode
40+ my $host_is_slave = 0;
41+
42+ $sql_thread_started = 0;
43+
44 mysql_send 'SHOW SLAVE STATUS\G;';
45 file_to_array($mysql_stdout, \@lines);
46 foreach my $line ( @lines ) {
47 if ( $line =~ m/Read_Master_Log_Pos/ ) {
48 $host_is_slave = 1;
49- last;
50- }
51+ } elsif ( $line =~ m/Slave_SQL_Running:.*Yes/ ) {
52+ $sql_thread_started = 1;
53+ }
54 }
55 if ( !$host_is_slave ) {
56 print STDERR "$prefix: Not checking slave open temp tables for --safe-slave-backup because host is not a slave\n";
57 return;
58 }
59
60- mysql_send 'STOP SLAVE SQL_THREAD;';
61+ if ($sql_thread_started) {
62+ mysql_send 'STOP SLAVE SQL_THREAD;';
63+ }
64
65 my $open_temp_tables = get_slave_open_temp_tables();
66 print STDERR "$prefix: Slave open temp tables: $open_temp_tables\n";
67@@ -2669,6 +2675,12 @@
68 }
69 }
70
71+ # Restart the slave if it was running at start
72+ if ($sql_thread_started) {
73+ print STDERR "Restarting slave SQL thread.\n";
74+ mysql_send 'START SLAVE SQL_THREAD;';
75+ }
76+
77 Die "Slave_open_temp_tables did not become zero after waiting $option_safe_slave_backup_timeout seconds";
78 }
79
80
81=== modified file 'test/inc/common.sh'
82--- test/inc/common.sh 2012-06-19 06:00:44 +0000
83+++ test/inc/common.sh 2012-10-16 15:41:24 +0000
84@@ -359,6 +359,47 @@
85 }
86
87 ########################################################################
88+# Wait until slave catches up with master.
89+# The timeout is hardcoded to 300 seconds
90+#
91+# Synopsis:
92+# sync_slave_with_master <slave_id> <master_id>
93+#########################################################################
94+function sync_slave_with_master()
95+{
96+ local slave_id=$1
97+ local master_id=$2
98+ local count
99+ local master_file
100+ local master_pos
101+
102+ vlog "Syncing slave (id=#$slave_id) with master (id=#$master_id)"
103+
104+ # Get master log pos
105+ switch_server $master_id
106+ count=0
107+ while read line; do
108+ if [ $count -eq 1 ] # File:
109+ then
110+ master_file=`echo "$line" | sed s/File://`
111+ elif [ $count -eq 2 ] # Position:
112+ then
113+ master_pos=`echo "$line" | sed s/Position://`
114+ fi
115+ count=$((count+1))
116+ done <<< "`run_cmd $MYSQL $MYSQL_ARGS -Nse 'SHOW MASTER STATUS\G' mysql`"
117+
118+ echo "master_file=$master_file, master_pos=$master_pos"
119+
120+ # Wait for the slave SQL thread to catch up
121+ switch_server $slave_id
122+
123+ run_cmd $MYSQL $MYSQL_ARGS <<EOF
124+SELECT MASTER_POS_WAIT('$master_file', $master_pos, 300);
125+EOF
126+}
127+
128+########################################################################
129 # Prints checksum for a given table.
130 # Expects 2 arguments: $1 is the DB name and $2 is the table to checksum
131 ########################################################################
132
133=== added file 'test/t/bug1037379.sh'
134--- test/t/bug1037379.sh 1970-01-01 00:00:00 +0000
135+++ test/t/bug1037379.sh 2012-10-16 15:41:24 +0000
136@@ -0,0 +1,69 @@
137+################################################################################
138+# Bug #1037379: SQL_THREAD left in stopped state of safe-slave-backup-timeout is
139+# reached
140+# Bug #887803: innobackupex --safe-slave-backup-timeout option doesn't work
141+################################################################################
142+
143+. inc/common.sh
144+
145+################################################################################
146+# Create a temporary table and pause "indefinitely" to keep the connection open
147+################################################################################
148+function create_temp_table()
149+{
150+ switch_server $master_id
151+ run_cmd $MYSQL $MYSQL_ARGS test <<EOF
152+CREATE TEMPORARY TABLE tmp(a INT);
153+INSERT INTO tmp VALUES (1);
154+SELECT SLEEP(10000);
155+EOF
156+}
157+
158+master_id=1
159+slave_id=2
160+
161+start_server_with_id $master_id
162+start_server_with_id $slave_id
163+
164+setup_slave $slave_id $master_id
165+
166+create_temp_table &
167+job_master=$!
168+
169+sync_slave_with_master $slave_id $master_id
170+
171+switch_server $slave_id
172+
173+################################################################################
174+# First check if the SQL thread is left in the running state
175+# if it is running when taking a backup
176+################################################################################
177+
178+# The following will fail due to a timeout
179+run_cmd_expect_failure $IB_BIN $IB_ARGS --no-timestamp --safe-slave-backup \
180+ --safe-slave-backup-timeout=3 $topdir/backup1
181+
182+grep -q "Slave_open_temp_tables did not become zero" $OUTFILE
183+
184+# Check that the SQL thread is running
185+run_cmd $MYSQL $MYSQL_ARGS -e "SHOW SLAVE STATUS\G" |
186+ egrep 'Slave_SQL_Running:[[:space:]]+Yes'
187+
188+################################################################################
189+# Now check if the SQL thread is left in the stopped state
190+# if it is stopped when taking a backup
191+################################################################################
192+
193+run_cmd $MYSQL $MYSQL_ARGS -e "STOP SLAVE SQL_THREAD"
194+
195+# The following will fail due to a timeout
196+run_cmd_expect_failure $IB_BIN $IB_ARGS --no-timestamp --safe-slave-backup \
197+ --safe-slave-backup-timeout=3 $topdir/backup2
198+
199+grep -c "Slave_open_temp_tables did not become zero" $OUTFILE | grep -w 2
200+
201+# Check that the SQL thread is stopped
202+run_cmd $MYSQL $MYSQL_ARGS -e "SHOW SLAVE STATUS\G" |
203+ egrep 'Slave_SQL_Running:[[:space:]]+No'
204+
205+kill -SIGKILL $job_master

Subscribers

People subscribed via source and target branches