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
=== modified file 'innobackupex'
--- innobackupex 2012-09-21 12:32:30 +0000
+++ innobackupex 2012-10-16 15:41:24 +0000
@@ -137,8 +137,8 @@
137# backup my.cnf file137# backup my.cnf file
138my $backup_config_file = '';138my $backup_config_file = '';
139139
140# whether host is detected as slave in safe slave backup mode140# whether slave SQL thread is running when wait_for_safe_slave() is called
141my $host_is_slave = 0;141my $sql_thread_started = 0;
142142
143# options from the options file143# options from the options file
144my %config;144my %config;
@@ -431,7 +431,7 @@
431 # release read locks on all tables431 # release read locks on all tables
432 mysql_unlockall() if !$option_no_lock;432 mysql_unlockall() if !$option_no_lock;
433433
434 if ( $option_safe_slave_backup && $host_is_slave ) {434 if ( $option_safe_slave_backup && $sql_thread_started) {
435 print STDERR "$prefix: Starting slave SQL thread\n";435 print STDERR "$prefix: Starting slave SQL thread\n";
436 mysql_send('START SLAVE SQL_THREAD;');436 mysql_send('START SLAVE SQL_THREAD;');
437 }437 }
@@ -1825,7 +1825,7 @@
1825 'sshopt=s' => \$option_ssh_opt,1825 'sshopt=s' => \$option_ssh_opt,
1826 'parallel=i' => \$option_parallel,1826 'parallel=i' => \$option_parallel,
1827 'safe-slave-backup' => \$option_safe_slave_backup,1827 'safe-slave-backup' => \$option_safe_slave_backup,
1828 'safe-slave-backup-timeout' => $option_safe_slave_backup_timeout,1828 'safe-slave-backup-timeout=i' => \$option_safe_slave_backup_timeout,
1829 );1829 );
1830 1830
1831 if (!$rcode) {1831 if (!$rcode) {
@@ -2630,22 +2630,28 @@
2630# Slave_open_temp_tables has to be zero. Dies on timeout.2630# Slave_open_temp_tables has to be zero. Dies on timeout.
2631sub wait_for_safe_slave {2631sub wait_for_safe_slave {
2632 my @lines;2632 my @lines;
26332633 # whether host is detected as slave in safe slave backup mode
2634 $host_is_slave = 0;2634 my $host_is_slave = 0;
2635
2636 $sql_thread_started = 0;
2637
2635 mysql_send 'SHOW SLAVE STATUS\G;';2638 mysql_send 'SHOW SLAVE STATUS\G;';
2636 file_to_array($mysql_stdout, \@lines);2639 file_to_array($mysql_stdout, \@lines);
2637 foreach my $line ( @lines ) {2640 foreach my $line ( @lines ) {
2638 if ( $line =~ m/Read_Master_Log_Pos/ ) {2641 if ( $line =~ m/Read_Master_Log_Pos/ ) {
2639 $host_is_slave = 1;2642 $host_is_slave = 1;
2640 last;2643 } elsif ( $line =~ m/Slave_SQL_Running:.*Yes/ ) {
2641 }2644 $sql_thread_started = 1;
2645 }
2642 }2646 }
2643 if ( !$host_is_slave ) {2647 if ( !$host_is_slave ) {
2644 print STDERR "$prefix: Not checking slave open temp tables for --safe-slave-backup because host is not a slave\n";2648 print STDERR "$prefix: Not checking slave open temp tables for --safe-slave-backup because host is not a slave\n";
2645 return;2649 return;
2646 }2650 }
26472651
2648 mysql_send 'STOP SLAVE SQL_THREAD;';2652 if ($sql_thread_started) {
2653 mysql_send 'STOP SLAVE SQL_THREAD;';
2654 }
26492655
2650 my $open_temp_tables = get_slave_open_temp_tables();2656 my $open_temp_tables = get_slave_open_temp_tables();
2651 print STDERR "$prefix: Slave open temp tables: $open_temp_tables\n";2657 print STDERR "$prefix: Slave open temp tables: $open_temp_tables\n";
@@ -2669,6 +2675,12 @@
2669 }2675 }
2670 } 2676 }
26712677
2678 # Restart the slave if it was running at start
2679 if ($sql_thread_started) {
2680 print STDERR "Restarting slave SQL thread.\n";
2681 mysql_send 'START SLAVE SQL_THREAD;';
2682 }
2683
2672 Die "Slave_open_temp_tables did not become zero after waiting $option_safe_slave_backup_timeout seconds";2684 Die "Slave_open_temp_tables did not become zero after waiting $option_safe_slave_backup_timeout seconds";
2673}2685}
26742686
26752687
=== modified file 'test/inc/common.sh'
--- test/inc/common.sh 2012-06-19 06:00:44 +0000
+++ test/inc/common.sh 2012-10-16 15:41:24 +0000
@@ -359,6 +359,47 @@
359}359}
360360
361########################################################################361########################################################################
362# Wait until slave catches up with master.
363# The timeout is hardcoded to 300 seconds
364#
365# Synopsis:
366# sync_slave_with_master <slave_id> <master_id>
367#########################################################################
368function sync_slave_with_master()
369{
370 local slave_id=$1
371 local master_id=$2
372 local count
373 local master_file
374 local master_pos
375
376 vlog "Syncing slave (id=#$slave_id) with master (id=#$master_id)"
377
378 # Get master log pos
379 switch_server $master_id
380 count=0
381 while read line; do
382 if [ $count -eq 1 ] # File:
383 then
384 master_file=`echo "$line" | sed s/File://`
385 elif [ $count -eq 2 ] # Position:
386 then
387 master_pos=`echo "$line" | sed s/Position://`
388 fi
389 count=$((count+1))
390 done <<< "`run_cmd $MYSQL $MYSQL_ARGS -Nse 'SHOW MASTER STATUS\G' mysql`"
391
392 echo "master_file=$master_file, master_pos=$master_pos"
393
394 # Wait for the slave SQL thread to catch up
395 switch_server $slave_id
396
397 run_cmd $MYSQL $MYSQL_ARGS <<EOF
398SELECT MASTER_POS_WAIT('$master_file', $master_pos, 300);
399EOF
400}
401
402########################################################################
362# Prints checksum for a given table.403# Prints checksum for a given table.
363# Expects 2 arguments: $1 is the DB name and $2 is the table to checksum404# Expects 2 arguments: $1 is the DB name and $2 is the table to checksum
364########################################################################405########################################################################
365406
=== added file 'test/t/bug1037379.sh'
--- test/t/bug1037379.sh 1970-01-01 00:00:00 +0000
+++ test/t/bug1037379.sh 2012-10-16 15:41:24 +0000
@@ -0,0 +1,69 @@
1################################################################################
2# Bug #1037379: SQL_THREAD left in stopped state of safe-slave-backup-timeout is
3# reached
4# Bug #887803: innobackupex --safe-slave-backup-timeout option doesn't work
5################################################################################
6
7. inc/common.sh
8
9################################################################################
10# Create a temporary table and pause "indefinitely" to keep the connection open
11################################################################################
12function create_temp_table()
13{
14 switch_server $master_id
15 run_cmd $MYSQL $MYSQL_ARGS test <<EOF
16CREATE TEMPORARY TABLE tmp(a INT);
17INSERT INTO tmp VALUES (1);
18SELECT SLEEP(10000);
19EOF
20}
21
22master_id=1
23slave_id=2
24
25start_server_with_id $master_id
26start_server_with_id $slave_id
27
28setup_slave $slave_id $master_id
29
30create_temp_table &
31job_master=$!
32
33sync_slave_with_master $slave_id $master_id
34
35switch_server $slave_id
36
37################################################################################
38# First check if the SQL thread is left in the running state
39# if it is running when taking a backup
40################################################################################
41
42# The following will fail due to a timeout
43run_cmd_expect_failure $IB_BIN $IB_ARGS --no-timestamp --safe-slave-backup \
44 --safe-slave-backup-timeout=3 $topdir/backup1
45
46grep -q "Slave_open_temp_tables did not become zero" $OUTFILE
47
48# Check that the SQL thread is running
49run_cmd $MYSQL $MYSQL_ARGS -e "SHOW SLAVE STATUS\G" |
50 egrep 'Slave_SQL_Running:[[:space:]]+Yes'
51
52################################################################################
53# Now check if the SQL thread is left in the stopped state
54# if it is stopped when taking a backup
55################################################################################
56
57run_cmd $MYSQL $MYSQL_ARGS -e "STOP SLAVE SQL_THREAD"
58
59# The following will fail due to a timeout
60run_cmd_expect_failure $IB_BIN $IB_ARGS --no-timestamp --safe-slave-backup \
61 --safe-slave-backup-timeout=3 $topdir/backup2
62
63grep -c "Slave_open_temp_tables did not become zero" $OUTFILE | grep -w 2
64
65# Check that the SQL thread is stopped
66run_cmd $MYSQL $MYSQL_ARGS -e "SHOW SLAVE STATUS\G" |
67 egrep 'Slave_SQL_Running:[[:space:]]+No'
68
69kill -SIGKILL $job_master

Subscribers

People subscribed via source and target branches