Merge lp:~sergei.glushchenko/percona-xtrabackup/xb2.0-bug483827 into lp:percona-xtrabackup/2.0

Proposed by Sergei Glushchenko
Status: Merged
Approved by: Alexey Kopytov
Approved revision: no longer in the source branch.
Merged at revision: 431
Proposed branch: lp:~sergei.glushchenko/percona-xtrabackup/xb2.0-bug483827
Merge into: lp:percona-xtrabackup/2.0
Prerequisite: lp:~sergei.glushchenko/percona-xtrabackup/xb2.0-bug996493
Diff against target: 325 lines (+108/-19)
6 files modified
doc/source/how-tos.rst (+1/-0)
doc/source/innobackupex/innobackupex_option_reference.rst (+4/-0)
doc/source/xtrabackup_bin/xbk_option_reference.rst (+4/-0)
innobackupex (+34/-16)
src/xtrabackup.c (+20/-3)
test/t/bug483827.sh (+45/-0)
To merge this branch: bzr merge lp:~sergei.glushchenko/percona-xtrabackup/xb2.0-bug483827
Reviewer Review Type Date Requested Status
Alexey Kopytov (community) Approve
Review via email: mp+106348@code.launchpad.net

This proposal supersedes a proposal from 2012-03-29.

Description of the change

Bug #483827. Support for mysqld_multi.
Fix based on work of Daniël van Eeden (lp:~dveeden/percona-xtrabackup/lp483827)
--section option added to innobackupex, specifying which section of my.cnf to handle.
--mysqld-section option added to xtrabackup for the same purpose.
Tescase does not run mysqld_multi, it just tests correctness of --section option.

http://jenkins.percona.com/view/XtraBackup/job/percona-xtrabackup-2.0-param/197/

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

Sergei,

   - sections in my.cnf are called groups in MySQL documentation. So
     let's be consistent and call them groups as well, and name the
     options (both the innobackupex and the xtrabackup one)
     --defaults-group, rather than --section and --mysqld-section

   - it looks like get_option is always passed the same value as its
     second argument, so I wonder if it really needs that argument, or
     rather just use $option_mysqld_section (or whatever it will be
     renamed to, i.e. $option_defaults_group) internally.

   - s/laod/load/
   - s/accetps/accepts/
   - s/rstore_args/restore_args/. Though you don't really need that
     function, as tests are executed in a separate shell process, so
     modifications to variables have no effect on other tests anyway.

   - I know that code in main() that scan options for "--mysqld-section"
     was copy-pasted, but please format it according to InnoDB
     style. Because currently it's a terrible mix of all possible
     formatting styles.

   - in the same code, I don't think strstr() is necessary, because you
     already have the pointer to '=' (or terminating zero) in optend.

review: Needs Fixing
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

--defaults-group option instead of --section and --mysql-section

kept group name argument for has_option.
fixed typos.

reformatted code to be more InnoDB-style (if there are other requirements, I'm ready for the next iteration).

removed unnecessary strstr.

Revision history for this message
Alexey Kopytov (akopytov) wrote :

Sergei,

As discussed on IRC, --defaults-group does not necessarily have to be the first option, so docs should be corrected.

And, while you are at it would be good to correct built-in help for --defaults-group in innobackupex.

Help text for other options either have units or some description of possible values after the '=' sign, e.g.:

--ibbackup=IBBACKUP-BINARY
--remote-host=HOSTNAME

So the text for --defaults-group should be something like "--defaults-group=GROUP-NAME" rather thatn "--defaults-group=mysqld".

review: Needs Fixing
Revision history for this message
Sergei Glushchenko (sergei.glushchenko) wrote :

Docs fixed

Revision history for this message
Alexey Kopytov (akopytov) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'doc/source/how-tos.rst'
--- doc/source/how-tos.rst 2011-07-07 05:32:50 +0000
+++ doc/source/how-tos.rst 2012-05-18 11:25:23 +0000
@@ -13,6 +13,7 @@
13 howtos/recipes_ibkx_local13 howtos/recipes_ibkx_local
14 howtos/recipes_ibkx_stream14 howtos/recipes_ibkx_stream
15 howtos/recipes_ibkx_inc15 howtos/recipes_ibkx_inc
16 howtos/recipes_ibkx_multi
1617
1718
18.. _recipes-xbk:19.. _recipes-xbk:
1920
=== modified file 'doc/source/innobackupex/innobackupex_option_reference.rst'
--- doc/source/innobackupex/innobackupex_option_reference.rst 2012-05-15 09:30:50 +0000
+++ doc/source/innobackupex/innobackupex_option_reference.rst 2012-05-18 11:25:23 +0000
@@ -70,6 +70,10 @@
7070
71 This option accepts a string argument that specifies the port to use when connecting to the database server with TCP/IP. It is passed to the :command:`mysql` child process. It is passed to the :command:`mysql` child process without alteration. See :command:`mysql --help` for details.71 This option accepts a string argument that specifies the port to use when connecting to the database server with TCP/IP. It is passed to the :command:`mysql` child process. It is passed to the :command:`mysql` child process without alteration. See :command:`mysql --help` for details.
7272
73.. option:: --defaults-group
74
75 This option accepts a string argument that specifies the group which should be read from the configuration file. This is needed if you use mysqld_multi.
76
73.. option:: --socket77.. option:: --socket
7478
75 This option accepts a string argument that specifies the socket to use when connecting to the local database server with a UNIX domain socket. It is passed to the mysql child process without alteration. See :command:`mysql --help` for details.79 This option accepts a string argument that specifies the socket to use when connecting to the local database server with a UNIX domain socket. It is passed to the mysql child process without alteration. See :command:`mysql --help` for details.
7680
=== modified file 'doc/source/xtrabackup_bin/xbk_option_reference.rst'
--- doc/source/xtrabackup_bin/xbk_option_reference.rst 2012-04-21 07:12:28 +0000
+++ doc/source/xtrabackup_bin/xbk_option_reference.rst 2012-05-18 11:25:23 +0000
@@ -101,6 +101,10 @@
101 --innodb-read-io-threads101 --innodb-read-io-threads
102 --innodb-write-io-threads102 --innodb-write-io-threads
103103
104.. option:: --defaults-group
105
106 This option is to set the group which should be read from the configuration file. This is used by innobackupex if you use the `--defaults-group` option. It is needed for mysqld_multi deployments.
107
104.. option:: --log-stream108.. option:: --log-stream
105109
106 Makes xtrabackup not copy data files, and output the contents of the InnoDB log files to STDOUT until the :option:`--suspend-at-end` file is deleted. This option enables :option:`--suspend-at-end` automatically.110 Makes xtrabackup not copy data files, and output the contents of the InnoDB log files to STDOUT until the :option:`--suspend-at-end` file is deleted. This option enables :option:`--suspend-at-end` automatically.
107111
=== modified file 'innobackupex'
--- innobackupex 2012-05-18 11:25:23 +0000
+++ innobackupex 2012-05-18 11:25:23 +0000
@@ -84,6 +84,7 @@
84my $option_mysql_port = '';84my $option_mysql_port = '';
85my $option_mysql_socket = '';85my $option_mysql_socket = '';
86my $option_mysql_host = '';86my $option_mysql_host = '';
87my $option_defaults_group = 'mysqld';
87my $option_no_timestamp = '';88my $option_no_timestamp = '';
88my $option_slave_info = '';89my $option_slave_info = '';
89my $option_galera_info = '';90my $option_galera_info = '';
@@ -377,7 +378,7 @@
377# process.378# process.
378#379#
379sub backup {380sub backup {
380 my $orig_datadir = get_option(\%config, 'mysqld', 'datadir');381 my $orig_datadir = get_option(\%config, $option_defaults_group, 'datadir');
381382
382 # check that we can connect to the database. This done by383 # check that we can connect to the database. This done by
383 # connecting, issuing a query, and closing the connection.384 # connecting, issuing a query, and closing the connection.
@@ -626,13 +627,13 @@
626# back to their original locations.627# back to their original locations.
627#628#
628sub copy_back {629sub copy_back {
629 my $orig_datadir = get_option(\%config, 'mysqld', 'datadir');630 my $orig_datadir = get_option(\%config, $option_defaults_group, 'datadir');
630 my $orig_ibdata_dir = 631 my $orig_ibdata_dir =
631 get_option(\%config, 'mysqld', 'innodb_data_home_dir');632 get_option(\%config, $option_defaults_group, 'innodb_data_home_dir');
632 my $orig_innodb_data_file_path = 633 my $orig_innodb_data_file_path =
633 get_option(\%config, 'mysqld', 'innodb_data_file_path');634 get_option(\%config, $option_defaults_group, 'innodb_data_file_path');
634 my $orig_iblog_dir =635 my $orig_iblog_dir =
635 get_option(\%config, 'mysqld', 'innodb_log_group_home_dir');636 get_option(\%config, $option_defaults_group, 'innodb_log_group_home_dir');
636 my $iblog_files = 'ib_logfile.*';637 my $iblog_files = 'ib_logfile.*';
637 my $excluded_files = 638 my $excluded_files =
638 '\.\.?|backup-my\.cnf|xtrabackup_logfile|' .639 '\.\.?|backup-my\.cnf|xtrabackup_logfile|' .
@@ -740,6 +741,10 @@
740 $options = $options . " --defaults-file=\"${backup_dir}/backup-my.cnf\" ";741 $options = $options . " --defaults-file=\"${backup_dir}/backup-my.cnf\" ";
741 }742 }
742743
744 if ($option_defaults_group) {
745 $options = $options . " --defaults-group=\"$option_defaults_group\" ";
746 }
747
743 $options = $options . "--prepare --target-dir=$backup_dir";748 $options = $options . "--prepare --target-dir=$backup_dir";
744749
745 if ($option_uncompress) {750 if ($option_uncompress) {
@@ -863,6 +868,10 @@
863 $options = $options . " --defaults-file=\"$option_defaults_file\" ";868 $options = $options . " --defaults-file=\"$option_defaults_file\" ";
864 }869 }
865870
871 if ($option_defaults_group) {
872 $options = $options . " --defaults-group=\"$option_defaults_group\" ";
873 }
874
866 $options = $options . "--backup --suspend-at-end";875 $options = $options . "--backup --suspend-at-end";
867876
868 if (!$option_remote_host && !$option_stream) {877 if (!$option_remote_host && !$option_stream) {
@@ -925,13 +934,13 @@
925934
926 if($option_remote_host) {935 if($option_remote_host) {
927 #direct copy to remote936 #direct copy to remote
928 my $orig_datadir = get_option(\%config, 'mysqld', 'datadir');937 my $orig_datadir = get_option(\%config, $option_defaults_group, 'datadir');
929 my $orig_ibdata_dir =938 my $orig_ibdata_dir =
930 get_option(\%config, 'mysqld', 'innodb_data_home_dir');939 get_option(\%config, $option_defaults_group, 'innodb_data_home_dir');
931 my $orig_innodb_data_file_path =940 my $orig_innodb_data_file_path =
932 get_option(\%config, 'mysqld', 'innodb_data_file_path');941 get_option(\%config, $option_defaults_group, 'innodb_data_file_path');
933 my $innodb_flush_method = 942 my $innodb_flush_method =
934 get_option(\%config, 'mysqld', 'innodb_flush_method');943 get_option(\%config, $option_defaults_group, 'innodb_flush_method');
935 my $innodb_use_odirect;944 my $innodb_use_odirect;
936 $innodb_use_odirect = 1 if $innodb_flush_method =~ m/^(ALL_)?O_DIRECT$/i;945 $innodb_use_odirect = 1 if $innodb_flush_method =~ m/^(ALL_)?O_DIRECT$/i;
937946
@@ -1582,7 +1591,7 @@
1582 read_config_file(\%config);1591 read_config_file(\%config);
15831592
1584 if(!$option_tmpdir) {1593 if(!$option_tmpdir) {
1585 $option_tmpdir = get_option(\%config, 'mysqld', 'tmpdir');1594 $option_tmpdir = get_option(\%config, $option_defaults_group, 'tmpdir');
1586 }1595 }
15871596
1588 # get innodb log home directory from options file1597 # get innodb log home directory from options file
@@ -1658,8 +1667,8 @@
16581667
1659 my $option_name;1668 my $option_name;
1660 foreach $option_name (@option_names) {1669 foreach $option_name (@option_names) {
1661 if (has_option(\%config, 'mysqld', $option_name)) {1670 if (has_option(\%config, $option_defaults_group, $option_name)) {
1662 my $option_value = get_option(\%config, 'mysqld', $option_name);1671 my $option_value = get_option(\%config, $option_defaults_group, $option_name);
1663 $options_dump .= "$option_name=$option_value\n";1672 $options_dump .= "$option_name=$option_value\n";
1664 }1673 }
1665 }1674 }
@@ -1725,6 +1734,7 @@
1725 'user=s' => \$option_mysql_user,1734 'user=s' => \$option_mysql_user,
1726 'host=s' => \$option_mysql_host,1735 'host=s' => \$option_mysql_host,
1727 'port=s' => \$option_mysql_port,1736 'port=s' => \$option_mysql_port,
1737 'defaults-group=s' => \$option_defaults_group,
1728 'slave-info' => \$option_slave_info,1738 'slave-info' => \$option_slave_info,
1729 'galera-info' => \$option_galera_info,1739 'galera-info' => \$option_galera_info,
1730 'socket=s' => \$option_mysql_socket,1740 'socket=s' => \$option_mysql_socket,
@@ -1840,7 +1850,7 @@
1840sub make_backup_dir {1850sub make_backup_dir {
1841 my $dir;1851 my $dir;
1842 my $innodb_data_file_path = 1852 my $innodb_data_file_path =
1843 get_option(\%config, 'mysqld', 'innodb_data_file_path');1853 get_option(\%config, $option_defaults_group, 'innodb_data_file_path');
18441854
1845 # create backup directory1855 # create backup directory
1846 $dir = $backup_root;1856 $dir = $backup_root;
@@ -1932,7 +1942,7 @@
1932#1942#
1933sub backup_files {1943sub backup_files {
1934 my $prep_mode = shift;1944 my $prep_mode = shift;
1935 my $source_dir = get_option(\%config, 'mysqld', 'datadir');1945 my $source_dir = get_option(\%config, $option_defaults_group, 'datadir');
1936 my @list;1946 my @list;
1937 my $file;1947 my $file;
1938 my $database;1948 my $database;
@@ -2211,6 +2221,10 @@
2211 $options = $options . " --defaults-file=\"${backup_dir}/backup-my.cnf\" ";2221 $options = $options . " --defaults-file=\"${backup_dir}/backup-my.cnf\" ";
2212 }2222 }
22132223
2224 if ($option_defaults_group) {
2225 $options = $options . " --defaults-group=\"$option_defaults_group\" ";
2226 }
2227
2214 $options = $options . "--print-param";2228 $options = $options . "--print-param";
22152229
22162230
@@ -2616,7 +2630,7 @@
2616 [--no-timestamp] [--ibbackup=IBBACKUP-BINARY]2630 [--no-timestamp] [--ibbackup=IBBACKUP-BINARY]
2617 [--slave-info] [--stream=tar|xbstream]2631 [--slave-info] [--stream=tar|xbstream]
2618 [--scpopt=OPTIONS-FOR-SCP] [--sshopt=OPTIONS-FOR-SSH]2632 [--scpopt=OPTIONS-FOR-SCP] [--sshopt=OPTIONS-FOR-SSH]
2619 [--defaults-file=MY.CNF]2633 [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME]
2620 [--databases=LIST] [--remote-host=HOSTNAME] [--no-lock] 2634 [--databases=LIST] [--remote-host=HOSTNAME] [--no-lock]
2621 [--tmpdir=DIRECTORY] [--tables-file=FILE]2635 [--tmpdir=DIRECTORY] [--tables-file=FILE]
2622 [--incremental] [--incremental-basedir]2636 [--incremental] [--incremental-basedir]
@@ -2628,7 +2642,7 @@
2628 [--export] [--redo-only] [--ibbackup=IBBACKUP-BINARY]2642 [--export] [--redo-only] [--ibbackup=IBBACKUP-BINARY]
2629 BACKUP-DIR2643 BACKUP-DIR
26302644
2631innobackupex --copy-back [--defaults-file=MY.CNF] BACKUP-DIR2645innobackupex --copy-back [--defaults-file=MY.CNF] [--defaults-group=GROUP-NAME] BACKUP-DIR
26322646
2633=head1 DESCRIPTION2647=head1 DESCRIPTION
26342648
@@ -2811,6 +2825,10 @@
28112825
2812This option specifies the MySQL username used when connecting to the server, if that's not the current user. The option accepts a string argument. It is passed to the mysql child process without alteration. See mysql --help for details.2826This option specifies the MySQL username used when connecting to the server, if that's not the current user. The option accepts a string argument. It is passed to the mysql child process without alteration. See mysql --help for details.
28132827
2828=item --defaults-group=GROUP-NAME
2829
2830This option specifies the group name in my.cnf which should be used. This is needed for mysqld_multi deployments.
2831
2814=item --version2832=item --version
28152833
2816This option displays the xtrabackup version and copyright notice and then exits.2834This option displays the xtrabackup version and copyright notice and then exits.
28172835
=== modified file 'src/xtrabackup.c'
--- src/xtrabackup.c 2012-05-18 11:25:23 +0000
+++ src/xtrabackup.c 2012-05-18 11:25:23 +0000
@@ -769,6 +769,8 @@
769char *opt_mysql_tmpdir = NULL;769char *opt_mysql_tmpdir = NULL;
770MY_TMPDIR mysql_tmpdir_list;770MY_TMPDIR mysql_tmpdir_list;
771771
772const char *defaults_group = "mysqld";
773
772/* === static parameters in ha_innodb.cc */774/* === static parameters in ha_innodb.cc */
773775
774#define HA_INNOBASE_ROWS_IN_TABLE 10000 /* to get optimization right */776#define HA_INNOBASE_ROWS_IN_TABLE 10000 /* to get optimization right */
@@ -994,7 +996,8 @@
994 OPT_INNODB_SYNC_SPIN_LOOPS,996 OPT_INNODB_SYNC_SPIN_LOOPS,
995 OPT_INNODB_THREAD_CONCURRENCY,997 OPT_INNODB_THREAD_CONCURRENCY,
996 OPT_INNODB_THREAD_SLEEP_DELAY,998 OPT_INNODB_THREAD_SLEEP_DELAY,
997 OPT_XTRA_DEBUG_SYNC999 OPT_XTRA_DEBUG_SYNC,
1000 OPT_DEFAULTS_GROUP
998};1001};
9991002
1000static struct my_option my_long_options[] =1003static struct my_option my_long_options[] =
@@ -1278,6 +1281,9 @@
1278 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},1281 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1279#endif1282#endif
12801283
1284 {"defaults_group", OPT_DEFAULTS_GROUP, "defaults group in config file (default \"mysqld\").",
1285 (G_PTR*) &defaults_group, (G_PTR*) &defaults_group,
1286 0, GET_STR, REQUIRED_ARG, 0, 0, 0, 0, 0, 0},
1281 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}1287 { 0, 0, 0, 0, 0, 0, GET_NO_ARG, NO_ARG, 0, 0, 0, 0, 0, 0}
1282};1288};
12831289
@@ -1337,7 +1343,7 @@
1337#endif1343#endif
1338}1344}
13391345
1340static const char *load_default_groups[]= { "mysqld","xtrabackup",0 };1346static const char *load_default_groups[]= { "mysqld","xtrabackup",0,0 };
13411347
1342static void print_version(void)1348static void print_version(void)
1343{1349{
@@ -6280,6 +6286,17 @@
6280 MY_INIT(argv[0]);6286 MY_INIT(argv[0]);
6281 xb_regex_init();6287 xb_regex_init();
62826288
6289 /* scan options for group to load defaults from */
6290 {
6291 int i;
6292 char* optend;
6293 for (i=1; i < argc; i++) {
6294 optend = strcend(argv[i], '=');
6295 if (strncmp(argv[i], "--defaults-group", optend - argv[i]) == 0) {
6296 load_default_groups[2] = defaults_group = optend + 1;
6297 }
6298 }
6299 }
6283 load_defaults("my",load_default_groups,&argc,&argv);6300 load_defaults("my",load_default_groups,&argc,&argv);
62846301
6285 /* ignore unsupported options */6302 /* ignore unsupported options */
@@ -6518,7 +6535,7 @@
6518 exit(EXIT_FAILURE);6535 exit(EXIT_FAILURE);
65196536
6520 printf("# This MySQL options file was generated by XtraBackup.\n");6537 printf("# This MySQL options file was generated by XtraBackup.\n");
6521 printf("[mysqld]\n");6538 printf("[%s]\n", defaults_group);
6522 printf("datadir = \"%s\"\n", mysql_data_home);6539 printf("datadir = \"%s\"\n", mysql_data_home);
6523 printf("tmpdir = \"%s\"\n", mysql_tmpdir_list.list[0]);6540 printf("tmpdir = \"%s\"\n", mysql_tmpdir_list.list[0]);
6524 printf("innodb_data_home_dir = \"%s\"\n",6541 printf("innodb_data_home_dir = \"%s\"\n",
65256542
=== added file 'test/t/bug483827.sh'
--- test/t/bug483827.sh 1970-01-01 00:00:00 +0000
+++ test/t/bug483827.sh 2012-05-18 11:25:23 +0000
@@ -0,0 +1,45 @@
1########################################################################
2# Bug #483827: support for mysqld_multi
3########################################################################
4
5function modify_args()
6{
7 XB_ARGS=`echo $XB_ARGS | sed -e 's/my.cnf/my_multi.cnf/'`
8 IB_ARGS=`echo $IB_ARGS | sed -e 's/my.cnf/my_multi.cnf/'`
9}
10
11. inc/common.sh
12
13init
14mv ${mysql_datadir} ${mysql_datadir}1
15run_mysqld --datadir=${mysql_datadir}1
16
17backup_dir=$topdir/backup
18rm -rf $backup_dir
19
20# change defaults file from my.cnf to my_multi.cnf
21modify_args
22
23# make my_multi.cnf
24echo "
25[mysqld1]
26datadir=${mysql_datadir}1
27tmpdir=$mysql_tmpdir" > $topdir/my_multi.cnf
28
29# Backup
30innobackupex --no-timestamp --defaults-group=mysqld1 $backup_dir
31innobackupex --apply-log $backup_dir
32
33stop_mysqld
34
35# clean datadir
36rm -rf ${mysql_datadir}1/*
37
38# restore backup
39innobackupex --copy-back --defaults-group=mysqld1 $backup_dir
40
41# make sure that data are in correct place
42if [ ! -f ${mysql_datadir}1/ibdata1 ] ; then
43 vlog "Data not found in ${mysql_datadir}1"
44 exit -1
45fi

Subscribers

People subscribed via source and target branches