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
1=== modified file 'lib/Pingback.pm'
2--- lib/Pingback.pm 2012-08-28 21:28:34 +0000
3+++ lib/Pingback.pm 2012-08-31 16:14:20 +0000
4@@ -307,10 +307,31 @@
5 my $dbh = $instance->{dbh};
6 my $dsn = $instance->{dsn};
7
8- my $sql = q{SELECT CONCAT(@@hostname, @@port)};
9+ # MySQL 5.1+ has @@hostname and @@port
10+ # MySQL 5.0 has @@hostname but port only in SHOW VARS
11+ # MySQL 4.x has nothing, so we use the dsn
12+ my $sql = q{SELECT CONCAT(@@hostname, @@port)};
13+ PTDEBUG && _d($sql);
14 my ($name) = eval { $dbh->selectrow_array($sql) };
15- if ( $EVAL_ERROR ) { # assume that it's MySQL 4.x
16- $name = ($dsn->{h} || 'localhost') . ($dsn->{P} || 3306);
17+ if ( $EVAL_ERROR ) {
18+ # MySQL 4.x or 5.0
19+ PTDEBUG && _d($EVAL_ERROR);
20+ $sql = q{SELECT @@hostname};
21+ PTDEBUG && _d($sql);
22+ ($name) = eval { $dbh->selectrow_array($sql) };
23+ if ( $EVAL_ERROR ) {
24+ # MySQL 4.x
25+ PTDEBUG && _d($EVAL_ERROR);
26+ $name = ($dsn->{h} || 'localhost') . ($dsn->{P} || 3306);
27+ }
28+ else {
29+ # MySQL 5.0
30+ $sql = q{SHOW VARIABLES LIKE 'port'};
31+ PTDEBUG && _d($sql);
32+ my (undef, $port) = eval { $dbh->selectrow_array($sql) };
33+ PTDEBUG && _d('port:', $port);
34+ $name .= $port || '';
35+ }
36 }
37 my $id = md5_hex($name);
38
39
40=== modified file 't/lib/Pingback.t'
41--- t/lib/Pingback.t 2012-08-28 21:28:34 +0000
42+++ t/lib/Pingback.t 2012-08-31 16:14:20 +0000
43@@ -35,11 +35,10 @@
44 (undef, $mysql_distro)
45 = $master_dbh->selectrow_array("SHOW VARIABLES LIKE 'version_comment'");
46
47- my $sql = q{SELECT CONCAT(@@hostname, @@port)};
48- my ($name) = $master_dbh->selectrow_array($sql);
49- $master_id = md5_hex($name);
50-
51- (undef, $slave1_id) = Pingback::_generate_identifier( { dbh => $slave1_dbh } );
52+ (undef, $master_id) = Pingback::_generate_identifier(
53+ { dbh => $master_dbh, dsn => { h => '127.1', P => 12345 }});
54+ (undef, $slave1_id) = Pingback::_generate_identifier(
55+ { dbh => $slave1_dbh, dsn => { h => '127.1', P => 12346 }});
56
57 $master_inst = {
58 id => $master_id,
59@@ -283,12 +282,28 @@
60
61 SKIP: {
62 skip 'Cannot connect to sandbox master', 2 unless $master_dbh;
63- skip 'Requires MySQL 5.0.38 or newer', unless $sandbox_version ge '5.0.38';
64
65+ my $expect_master_id;
66+ if ( $sandbox_version ge '5.1' ) {
67+ my $sql = q{SELECT CONCAT(@@hostname, @@port)};
68+ my ($name) = $master_dbh->selectrow_array($sql);
69+ $expect_master_id = md5_hex($name);
70+ }
71+ elsif ( $sandbox_version eq '5.0' ) {
72+ my $sql = q{SELECT @@hostname};
73+ my ($hostname) = $master_dbh->selectrow_array($sql);
74+ $sql = q{SHOW VARIABLES LIKE 'port'};
75+ my (undef, $port) = $master_dbh->selectrow_array($sql);
76+ $expect_master_id = md5_hex($hostname . $port);
77+ }
78+ else {
79+ $expect_master_id = md5_hex("localhost", 12345);
80+ }
81+
82 is(
83- Pingback::_generate_identifier( { dbh => $master_dbh, dsn => undef } ),
84 $master_id,
85- "_generate_identifier() works with a dbh"
86+ $expect_master_id,
87+ "_generate_identifier() for MySQL $sandbox_version"
88 );
89
90 # The time limit file already exists (see previous tests), but this is

Subscribers

People subscribed via source and target branches