Merge lp:~percona-toolkit-dev/percona-toolkit/fix-950294-ptc-if-not-exists into lp:percona-toolkit/2.1

Proposed by Brian Fraser
Status: Merged
Approved by: Daniel Nichter
Approved revision: 333
Merged at revision: 335
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-950294-ptc-if-not-exists
Merge into: lp:percona-toolkit/2.1
Diff against target: 242 lines (+143/-18) (has conflicts)
2 files modified
bin/pt-table-checksum (+63/-15)
t/pt-table-checksum/privs.t (+80/-3)
Text conflict in bin/pt-table-checksum
Text conflict in t/pt-table-checksum/privs.t
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-950294-ptc-if-not-exists
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+117303@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

1) "--no-create-replicate-table was passed in." -> ""--no-create-replicate-table was specified."

2)

29 + print STDERR "CREATE DATABASE IF NOT EXISTS $db failed, but the "
30 + . "db already exists. This is harmless unless the "
31 + . "slaves don't have the database. $EVAL_ERROR"; # kb link?

I think we need to make this fatal because we must avoid breaking replication. So:

die "Error executing $sql: $EVAL_ERROR\nThe database exists on the master, but replication will break if it does not also exist on all replicas. If the --replicate database and table already exist on the master and all replicas, or if you create them manually, then specify --no-create-replicate-table to avoid this error."

How does that ^ sound? Better to force the user to think/do a little manual work than break their replication.

3) 49 +<<<<<<< TREE -- why is there a merge conflict?

4) 63 + . "--no-create-replicate-table was passed in. " -- "passed id" -> "specified"

5) 73 + print STDERR "CREATE TABLE IF NOT EXISTS $args{repl_table} " -- Same as above with the db: make fatal, change error message, etc.

6) 142 +isnt($exit_status, 0, "");

i) Let's never use isnt() because 1) it amounts to "yes we have no bananas" ("yes, $got is not $bar") and 2) it's dangerously close to isn't() which is just crazy.

ii) Test has no name.

review: Needs Fixing
333. By Brian Fraser <email address hidden>

Resolved a pending merge conflict.

The fix for https://bugs.launchpad.net/percona-toolkit/+bug/916168
was affecting the same code as this fix.
This commit mimicks that fix, and removes the privs checks.

Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/pt-table-checksum'
--- bin/pt-table-checksum 2012-07-30 14:30:05 +0000
+++ bin/pt-table-checksum 2012-07-31 15:30:27 +0000
@@ -8152,17 +8152,38 @@
8152 my $sql = "SHOW DATABASES LIKE '$db'";8152 my $sql = "SHOW DATABASES LIKE '$db'";
8153 PTDEBUG && _d($sql);8153 PTDEBUG && _d($sql);
8154 my @db_exists = $dbh->selectrow_array($sql);8154 my @db_exists = $dbh->selectrow_array($sql);
8155 if ( !@db_exists && $o->get('create-replicate-table') ) {8155 if ( !@db_exists && !$o->get('create-replicate-table') ) {
8156 $sql = "CREATE DATABASE " . $q->quote($db) . " /* pt-table-checksum */";8156 die "--replicate database $db does not exist and "
8157 . "--no-create-replicate-table was specified. You need "
8158 . "to create the database.\n";
8159 }
8160
8161 if ( $o->get('create-replicate-table') ) {
8162 $sql = "CREATE DATABASE IF NOT EXISTS "
8163 . $q->quote($db)
8164 . " /* pt-table-checksum */";
8165 local $@;
8166 PTDEBUG && _d($sql);
8157 eval {8167 eval {
8158 $dbh->do($sql);8168 $dbh->do($sql);
8159 };8169 };
8160 if ( $EVAL_ERROR ) {8170 if ( $EVAL_ERROR ) {
8161 die "--replicate database $db does not exist and it cannot be "8171 if ( @db_exists ) {
8162 . "created automatically. You need to create the database.\n";8172 die "Error executing $sql: $EVAL_ERROR\n"
8173 . "The database exists on the master, but replication will "
8174 . "break if it does not also exist on all replicas. If the "
8175 . "--replicate database and table already exist on the master "
8176 . "and all replicas, or if you created them manually, then "
8177 . "specify --no-create-replicate-table to avoid this error."
8178 }
8179 else {
8180 die "--replicate database $db does not exist and it cannot be "
8181 . "created automatically. You need to create the database. "
8182 . $EVAL_ERROR;
8183 }
8163 }8184 }
8164 }8185 }
81658186
8166 # USE the correct db (probably the repl db, but maybe --replicate-database).8187 # USE the correct db (probably the repl db, but maybe --replicate-database).
8167 use_repl_db(%args);8188 use_repl_db(%args);
81688189
@@ -8172,20 +8193,47 @@
8172 db => $db,8193 db => $db,
8173 tbl => $tbl,8194 tbl => $tbl,
8174 );8195 );
8196
8197 # Always create the table, unless --no-create-replicate-table
8198 # was passed in; see https://bugs.launchpad.net/percona-toolkit/+bug/950294
8175 if ( !$tbl_exists ) {8199 if ( !$tbl_exists ) {
8176 if ( $o->get('create-replicate-table') ) {8200 if ( !$o->get('create-replicate-table') ) {
8177 create_repl_table(%args)8201 die "--replicate table $repl_table does not exist and "
8178 }8202 . "--no-create-replicate-table was specified. "
8179 else {8203 . "You need to create the table.\n";
8180 die "--replicate table $repl_table does not exist; "
8181 . "read the documentation or use --create-replicate-table "
8182 . "to create it.\n";
8183 }8204 }
8184 }8205 }
8185 else {8206 else {
8186 PTDEBUG && _d('--replicate table', $repl_table, 'already exists');8207 PTDEBUG && _d('--replicate table', $repl_table, 'already exists');
8187 # We used to check the table privs here, but:8208<<<<<<< TREE
8188 # https://bugs.launchpad.net/percona-toolkit/+bug/9161688209 # We used to check the table privs here, but:
8210 # https://bugs.launchpad.net/percona-toolkit/+bug/916168
8211=======
8212 # We used to check the table privs here, but:
8213 # https://bugs.launchpad.net/percona-toolkit/+bug/916168
8214 }
8215
8216 if ( $o->get('create-replicate-table') ) {
8217 local $@;
8218 eval {
8219 create_repl_table(%args);
8220 };
8221 if ( $EVAL_ERROR ) {
8222 if ( $tbl_exists ) {
8223 die "Error executing $sql: $EVAL_ERROR\n"
8224 . "The table exists on the master, but replication will "
8225 . "break if it does not also exist on all replicas. If the "
8226 . "--replicate database and table already exist on the master "
8227 . "and all replicas, or if you created them manually, then "
8228 . "specify --no-create-replicate-table to avoid this error."
8229 }
8230 else {
8231 die "--replicate table $tbl does not exist and it cannot be "
8232 . "created automatically. You need to create the table. "
8233 . $EVAL_ERROR;
8234 }
8235 }
8236>>>>>>> MERGE-SOURCE
8189 }8237 }
81908238
8191 # Check and wait for the repl table to appear on all slaves.8239 # Check and wait for the repl table to appear on all slaves.
@@ -8327,7 +8375,7 @@
8327 my ($dbh, $repl_table, $o) = @args{@required_args};8375 my ($dbh, $repl_table, $o) = @args{@required_args};
8328 PTDEBUG && _d('Creating --replicate table', $repl_table); 8376 PTDEBUG && _d('Creating --replicate table', $repl_table);
8329 my $sql = $o->read_para_after(__FILE__, qr/MAGIC_create_replicate/);8377 my $sql = $o->read_para_after(__FILE__, qr/MAGIC_create_replicate/);
8330 $sql =~ s/CREATE TABLE checksums/CREATE TABLE $repl_table/;8378 $sql =~ s/CREATE TABLE checksums/CREATE TABLE IF NOT EXISTS $repl_table/;
8331 $sql =~ s/;$//;8379 $sql =~ s/;$//;
8332 PTDEBUG && _d($dbh, $sql);8380 PTDEBUG && _d($dbh, $sql);
8333 eval {8381 eval {
83348382
=== modified file 't/pt-table-checksum/privs.t'
--- t/pt-table-checksum/privs.t 2012-07-20 23:58:44 +0000
+++ t/pt-table-checksum/privs.t 2012-07-31 15:30:27 +0000
@@ -41,9 +41,12 @@
41elsif ( !@{$master_dbh->selectall_arrayref("show databases like 'sakila'")} ) {41elsif ( !@{$master_dbh->selectall_arrayref("show databases like 'sakila'")} ) {
42 plan skip_all => 'sakila database is not loaded';42 plan skip_all => 'sakila database is not loaded';
43}43}
44<<<<<<< TREE
44else {45else {
45 plan tests => 4;46 plan tests => 4;
46}47}
48=======
49>>>>>>> MERGE-SOURCE
4750
48# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic51# The sandbox servers run with lock_wait_timeout=3 and it's not dynamic
49# so we need to specify --lock-wait-timeout=3 else the tool will die.52# so we need to specify --lock-wait-timeout=3 else the tool will die.
@@ -55,6 +58,53 @@
55my $sample = "t/pt-table-checksum/samples/";58my $sample = "t/pt-table-checksum/samples/";
5659
57# ############################################################################60# ############################################################################
61# Should always create schema and tables with IF NOT EXISTS
62# https://bugs.launchpad.net/percona-toolkit/+bug/950294
63# ############################################################################
64
65$sb->wipe_clean($master_dbh);
66diag(`/tmp/12345/use -u root < $trunk/t/lib/samples/ro-checksum-user.sql 2>/dev/null`);
67PerconaTest::wait_for_table($slave1_dbh, "mysql.tables_priv", "user='ro_checksum_user'");
68
69($output, $exit_status) = full_output(
70 sub { pt_table_checksum::main(@args,
71 "$master_dsn,u=ro_checksum_user,p=msandbox",
72 qw(--recursion-method none)
73 ) },
74);
75
76ok(
77 $exit_status,
78 "Dies with an error status if it can't create the db/table"
79);
80
81like($output,
82 qr/\Q--replicate database percona does not exist and it cannot be created automatically/,
83 "fails if the percona db doesn't exist and the user can't create it",
84);
85
86($output, $exit_status) = full_output(
87 sub { pt_table_checksum::main(@args,
88 "$master_dsn,u=ro_checksum_user,p=msandbox",
89 qw(--recursion-method none --no-create-replicate-table)
90 ) },
91);
92
93like($output,
94 qr/\Q--replicate database percona does not exist and --no-create-replicate-table was/,
95 "fails if the percona db doesn't exist and --no-create-replicate-table",
96);
97
98diag(`/tmp/12345/use -u root -e "drop user 'ro_checksum_user'\@'%'"`);
99wait_until(
100 sub {
101 my $rows=$slave2_dbh->selectall_arrayref("SELECT user FROM mysql.user");
102 return !grep { ($_->[0] || '') ne 'ro_checksum_user' } @$rows;
103 }
104);
105$sb->wipe_clean($master_dbh);
106
107# ############################################################################
58# --recursion-method=none to avoid SHOW SLAVE HOSTS108# --recursion-method=none to avoid SHOW SLAVE HOSTS
59# https://bugs.launchpad.net/percona-toolkit/+bug/987694109# https://bugs.launchpad.net/percona-toolkit/+bug/987694
60# ############################################################################110# ############################################################################
@@ -64,7 +114,7 @@
64 "$master_dsn,u=msandbox,p=msandbox",114 "$master_dsn,u=msandbox,p=msandbox",
65 qw(-t sakila.country --quiet --quiet));115 qw(-t sakila.country --quiet --quiet));
66116
67diag(`/tmp/12345/use -u root < $trunk/t/lib/samples/ro-checksum-user.sql`);117diag(`/tmp/12345/use -u root < $trunk/t/lib/samples/ro-checksum-user.sql 2>/dev/null`);
68PerconaTest::wait_for_table($slave1_dbh, "mysql.tables_priv", "user='ro_checksum_user'");118PerconaTest::wait_for_table($slave1_dbh, "mysql.tables_priv", "user='ro_checksum_user'");
69119
70$output = output(120$output = output(
@@ -73,7 +123,7 @@
73 # Comment out this line and the tests fail because ro_checksum_user123 # Comment out this line and the tests fail because ro_checksum_user
74 # doesn't have privs to SHOW SLAVE HOSTS. This proves that124 # doesn't have privs to SHOW SLAVE HOSTS. This proves that
75 # --recursion-method none is working.125 # --recursion-method none is working.
76 qw(--recursion-method none)126 qw(--recursion-method none --no-create-replicate-table)
77 ) },127 ) },
78 stderr => 1,128 stderr => 1,
79);129);
@@ -90,6 +140,32 @@
90 "Read-only user (bug 987694): checksummed rows"140 "Read-only user (bug 987694): checksummed rows"
91);141);
92142
143($output) = full_output(
144 sub { $exit_status = pt_table_checksum::main(@args,
145 "$master_dsn,u=ro_checksum_user,p=msandbox",
146 qw(--recursion-method none)
147 ) }
148);
149
150like($output,
151 qr/\QThe database exists on the master, but replication will break/,
152 "dies if the db exists on the master but it can't CREATE DATABASE and --no-create-replicate-table was not specified",
153);
154
155diag(qx{/tmp/12345/use -u root -e 'DROP TABLE `percona`.`checksums`'});
156
157($output, $exit_status) = full_output(
158 sub { pt_table_checksum::main(@args,
159 "$master_dsn,u=ro_checksum_user,p=msandbox",
160 qw(--recursion-method none --no-create-replicate-table)
161 ) },
162);
163
164like($output,
165 qr/\Q--replicate table `percona`.`checksums` does not exist and --no/,
166 "fails if the checksums db doesn't exist and --no-create-replicate-table"
167);
168
93diag(`/tmp/12345/use -u root -e "drop user 'ro_checksum_user'\@'%'"`);169diag(`/tmp/12345/use -u root -e "drop user 'ro_checksum_user'\@'%'"`);
94wait_until(170wait_until(
95 sub {171 sub {
@@ -127,4 +203,5 @@
127# #############################################################################203# #############################################################################
128$sb->wipe_clean($master_dbh);204$sb->wipe_clean($master_dbh);
129ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");205ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox");
130exit;206
207done_testing;

Subscribers

People subscribed via source and target branches