Merge lp:~percona-toolkit-dev/percona-toolkit/fix-v-c-5.0-port into lp:percona-toolkit/2.1

Proposed by Daniel Nichter
Status: Merged
Merged at revision: 390
Proposed branch: lp:~percona-toolkit-dev/percona-toolkit/fix-v-c-5.0-port
Merge into: lp:percona-toolkit/2.1
Diff against target: 90 lines (+47/-11)
2 files modified
lib/Pingback.pm (+24/-3)
t/lib/Pingback.t (+23/-8)
To merge this branch: bzr merge lp:~percona-toolkit-dev/percona-toolkit/fix-v-c-5.0-port
Reviewer Review Type Date Requested Status
Daniel Nichter Approve
Review via email: mp+122316@code.launchpad.net
To post a comment you must log in.
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 'lib/Pingback.pm'
--- lib/Pingback.pm 2012-08-28 21:28:34 +0000
+++ lib/Pingback.pm 2012-08-31 16:14:20 +0000
@@ -307,10 +307,31 @@
307 my $dbh = $instance->{dbh};307 my $dbh = $instance->{dbh};
308 my $dsn = $instance->{dsn};308 my $dsn = $instance->{dsn};
309309
310 my $sql = q{SELECT CONCAT(@@hostname, @@port)};310 # MySQL 5.1+ has @@hostname and @@port
311 # MySQL 5.0 has @@hostname but port only in SHOW VARS
312 # MySQL 4.x has nothing, so we use the dsn
313 my $sql = q{SELECT CONCAT(@@hostname, @@port)};
314 PTDEBUG && _d($sql);
311 my ($name) = eval { $dbh->selectrow_array($sql) };315 my ($name) = eval { $dbh->selectrow_array($sql) };
312 if ( $EVAL_ERROR ) { # assume that it's MySQL 4.x316 if ( $EVAL_ERROR ) {
313 $name = ($dsn->{h} || 'localhost') . ($dsn->{P} || 3306);317 # MySQL 4.x or 5.0
318 PTDEBUG && _d($EVAL_ERROR);
319 $sql = q{SELECT @@hostname};
320 PTDEBUG && _d($sql);
321 ($name) = eval { $dbh->selectrow_array($sql) };
322 if ( $EVAL_ERROR ) {
323 # MySQL 4.x
324 PTDEBUG && _d($EVAL_ERROR);
325 $name = ($dsn->{h} || 'localhost') . ($dsn->{P} || 3306);
326 }
327 else {
328 # MySQL 5.0
329 $sql = q{SHOW VARIABLES LIKE 'port'};
330 PTDEBUG && _d($sql);
331 my (undef, $port) = eval { $dbh->selectrow_array($sql) };
332 PTDEBUG && _d('port:', $port);
333 $name .= $port || '';
334 }
314 }335 }
315 my $id = md5_hex($name);336 my $id = md5_hex($name);
316337
317338
=== modified file 't/lib/Pingback.t'
--- t/lib/Pingback.t 2012-08-28 21:28:34 +0000
+++ t/lib/Pingback.t 2012-08-31 16:14:20 +0000
@@ -35,11 +35,10 @@
35 (undef, $mysql_distro)35 (undef, $mysql_distro)
36 = $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");36 = $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");
3737
38 my $sql = q{SELECT CONCAT(@@hostname, @@port)};38 (undef, $master_id) = Pingback::_generate_identifier(
39 my ($name) = $master_dbh->selectrow_array($sql);39 { dbh => $master_dbh, dsn => { h => '127.1', P => 12345 }});
40 $master_id = md5_hex($name);40 (undef, $slave1_id) = Pingback::_generate_identifier(
4141 { dbh => $slave1_dbh, dsn => { h => '127.1', P => 12346 }});
42 (undef, $slave1_id) = Pingback::_generate_identifier( { dbh => $slave1_dbh } );
4342
44 $master_inst = {43 $master_inst = {
45 id => $master_id,44 id => $master_id,
@@ -283,12 +282,28 @@
283282
284SKIP: {283SKIP: {
285 skip 'Cannot connect to sandbox master', 2 unless $master_dbh;284 skip 'Cannot connect to sandbox master', 2 unless $master_dbh;
286 skip 'Requires MySQL 5.0.38 or newer', unless $sandbox_version ge '5.0.38';
287285
286 my $expect_master_id;
287 if ( $sandbox_version ge '5.1' ) {
288 my $sql = q{SELECT CONCAT(@@hostname, @@port)};
289 my ($name) = $master_dbh->selectrow_array($sql);
290 $expect_master_id = md5_hex($name);
291 }
292 elsif ( $sandbox_version eq '5.0' ) {
293 my $sql = q{SELECT @@hostname};
294 my ($hostname) = $master_dbh->selectrow_array($sql);
295 $sql = q{SHOW VARIABLES LIKE 'port'};
296 my (undef, $port) = $master_dbh->selectrow_array($sql);
297 $expect_master_id = md5_hex($hostname . $port);
298 }
299 else {
300 $expect_master_id = md5_hex("localhost", 12345);
301 }
302
288 is(303 is(
289 Pingback::_generate_identifier( { dbh => $master_dbh, dsn => undef } ),
290 $master_id,304 $master_id,
291 "_generate_identifier() works with a dbh"305 $expect_master_id,
306 "_generate_identifier() for MySQL $sandbox_version"
292 );307 );
293308
294 # The time limit file already exists (see previous tests), but this is309 # The time limit file already exists (see previous tests), but this is

Subscribers

People subscribed via source and target branches