Skip to content

Commit bdf7904

Browse files
Merge pull request #425 from mbenshoof/mbenshoof-slave-dsn
PT-1776: Adding in slave-user and slave-password for dsn table based …
2 parents 9a8e662 + edd7719 commit bdf7904

17 files changed

Lines changed: 439 additions & 103 deletions

File tree

bin/pt-archiver

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4525,6 +4525,9 @@ sub get_cxn_from_dsn_table {
45254525
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
45264526
PTDEBUG && _d($sql);
45274527
my @cxn;
4528+
my $o = $self->{OptionParser};
4529+
my $my_dsn;
4530+
my $lcxn;
45284531
use Data::Dumper;
45294532
DSN:
45304533
do {
@@ -4533,21 +4536,33 @@ sub get_cxn_from_dsn_table {
45334536
if ( $dsn_strings ) {
45344537
foreach my $dsn_string ( @$dsn_strings ) {
45354538
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
4536-
if ($args{wait_no_die}) {
4537-
my $lcxn;
4538-
eval {
4539-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
4540-
};
4541-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
4542-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
4539+
4540+
my $raw_dsn = $dp->parse($dsn_string);
4541+
my $dsn_defaults = $dp->parse_options($o);
4542+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
4543+
4544+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
4545+
PTDEBUG && _d('DSN - username set from --replica-user');
4546+
$my_dsn->{u} = $o->get('replica-user');
4547+
}
4548+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
4549+
PTDEBUG && _d('DSN - password set from --replica-password');
4550+
$my_dsn->{p} = $o->get('replica-password');
4551+
}
4552+
4553+
eval {
4554+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
4555+
};
4556+
if ( $EVAL_ERROR ) {
4557+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
4558+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
45434559
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
45444560
sleep(1);
45454561
goto DSN;
45464562
}
4547-
push @cxn, $lcxn;
4548-
} else {
4549-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
4563+
die $EVAL_ERROR;
45504564
}
4565+
push @cxn, $lcxn;
45514566
}
45524567
}
45534568
$done = 1;

bin/pt-heartbeat

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,9 @@ sub get_cxn_from_dsn_table {
981981
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
982982
PTDEBUG && _d($sql);
983983
my @cxn;
984+
my $o = $self->{OptionParser};
985+
my $my_dsn;
986+
my $lcxn;
984987
use Data::Dumper;
985988
DSN:
986989
do {
@@ -989,21 +992,33 @@ sub get_cxn_from_dsn_table {
989992
if ( $dsn_strings ) {
990993
foreach my $dsn_string ( @$dsn_strings ) {
991994
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
992-
if ($args{wait_no_die}) {
993-
my $lcxn;
994-
eval {
995-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
996-
};
997-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
998-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
995+
996+
my $raw_dsn = $dp->parse($dsn_string);
997+
my $dsn_defaults = $dp->parse_options($o);
998+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
999+
1000+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
1001+
PTDEBUG && _d('DSN - username set from --replica-user');
1002+
$my_dsn->{u} = $o->get('replica-user');
1003+
}
1004+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
1005+
PTDEBUG && _d('DSN - password set from --replica-password');
1006+
$my_dsn->{p} = $o->get('replica-password');
1007+
}
1008+
1009+
eval {
1010+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
1011+
};
1012+
if ( $EVAL_ERROR ) {
1013+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
1014+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
9991015
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
10001016
sleep(1);
10011017
goto DSN;
10021018
}
1003-
push @cxn, $lcxn;
1004-
} else {
1005-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
1019+
die $EVAL_ERROR;
10061020
}
1021+
push @cxn, $lcxn;
10071022
}
10081023
}
10091024
$done = 1;

bin/pt-kill

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4799,6 +4799,9 @@ sub get_cxn_from_dsn_table {
47994799
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
48004800
PTDEBUG && _d($sql);
48014801
my @cxn;
4802+
my $o = $self->{OptionParser};
4803+
my $my_dsn;
4804+
my $lcxn;
48024805
use Data::Dumper;
48034806
DSN:
48044807
do {
@@ -4807,21 +4810,33 @@ sub get_cxn_from_dsn_table {
48074810
if ( $dsn_strings ) {
48084811
foreach my $dsn_string ( @$dsn_strings ) {
48094812
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
4810-
if ($args{wait_no_die}) {
4811-
my $lcxn;
4812-
eval {
4813-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
4814-
};
4815-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
4816-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
4813+
4814+
my $raw_dsn = $dp->parse($dsn_string);
4815+
my $dsn_defaults = $dp->parse_options($o);
4816+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
4817+
4818+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
4819+
PTDEBUG && _d('DSN - username set from --replica-user');
4820+
$my_dsn->{u} = $o->get('replica-user');
4821+
}
4822+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
4823+
PTDEBUG && _d('DSN - password set from --replica-password');
4824+
$my_dsn->{p} = $o->get('replica-password');
4825+
}
4826+
4827+
eval {
4828+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
4829+
};
4830+
if ( $EVAL_ERROR ) {
4831+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
4832+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
48174833
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
48184834
sleep(1);
48194835
goto DSN;
48204836
}
4821-
push @cxn, $lcxn;
4822-
} else {
4823-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
4837+
die $EVAL_ERROR;
48244838
}
4839+
push @cxn, $lcxn;
48254840
}
48264841
}
48274842
$done = 1;

bin/pt-online-schema-change

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5090,6 +5090,9 @@ sub get_cxn_from_dsn_table {
50905090
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
50915091
PTDEBUG && _d($sql);
50925092
my @cxn;
5093+
my $o = $self->{OptionParser};
5094+
my $my_dsn;
5095+
my $lcxn;
50935096
use Data::Dumper;
50945097
DSN:
50955098
do {
@@ -5098,21 +5101,33 @@ sub get_cxn_from_dsn_table {
50985101
if ( $dsn_strings ) {
50995102
foreach my $dsn_string ( @$dsn_strings ) {
51005103
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
5101-
if ($args{wait_no_die}) {
5102-
my $lcxn;
5103-
eval {
5104-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
5105-
};
5106-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
5107-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
5104+
5105+
my $raw_dsn = $dp->parse($dsn_string);
5106+
my $dsn_defaults = $dp->parse_options($o);
5107+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
5108+
5109+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
5110+
PTDEBUG && _d('DSN - username set from --replica-user');
5111+
$my_dsn->{u} = $o->get('replica-user');
5112+
}
5113+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
5114+
PTDEBUG && _d('DSN - password set from --replica-password');
5115+
$my_dsn->{p} = $o->get('replica-password');
5116+
}
5117+
5118+
eval {
5119+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
5120+
};
5121+
if ( $EVAL_ERROR ) {
5122+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
5123+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
51085124
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
51095125
sleep(1);
51105126
goto DSN;
51115127
}
5112-
push @cxn, $lcxn;
5113-
} else {
5114-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
5128+
die $EVAL_ERROR;
51155129
}
5130+
push @cxn, $lcxn;
51165131
}
51175132
}
51185133
$done = 1;

bin/pt-query-digest

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11396,6 +11396,9 @@ sub get_cxn_from_dsn_table {
1139611396
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
1139711397
PTDEBUG && _d($sql);
1139811398
my @cxn;
11399+
my $o = $self->{OptionParser};
11400+
my $my_dsn;
11401+
my $lcxn;
1139911402
use Data::Dumper;
1140011403
DSN:
1140111404
do {
@@ -11404,21 +11407,33 @@ sub get_cxn_from_dsn_table {
1140411407
if ( $dsn_strings ) {
1140511408
foreach my $dsn_string ( @$dsn_strings ) {
1140611409
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
11407-
if ($args{wait_no_die}) {
11408-
my $lcxn;
11409-
eval {
11410-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
11411-
};
11412-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
11413-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
11410+
11411+
my $raw_dsn = $dp->parse($dsn_string);
11412+
my $dsn_defaults = $dp->parse_options($o);
11413+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
11414+
11415+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
11416+
PTDEBUG && _d('DSN - username set from --replica-user');
11417+
$my_dsn->{u} = $o->get('replica-user');
11418+
}
11419+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
11420+
PTDEBUG && _d('DSN - password set from --replica-password');
11421+
$my_dsn->{p} = $o->get('replica-password');
11422+
}
11423+
11424+
eval {
11425+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
11426+
};
11427+
if ( $EVAL_ERROR ) {
11428+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
11429+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
1141411430
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
1141511431
sleep(1);
1141611432
goto DSN;
1141711433
}
11418-
push @cxn, $lcxn;
11419-
} else {
11420-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
11434+
die $EVAL_ERROR;
1142111435
}
11436+
push @cxn, $lcxn;
1142211437
}
1142311438
}
1142411439
$done = 1;

bin/pt-replica-find

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,9 @@ sub get_cxn_from_dsn_table {
31283128
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
31293129
PTDEBUG && _d($sql);
31303130
my @cxn;
3131+
my $o = $self->{OptionParser};
3132+
my $my_dsn;
3133+
my $lcxn;
31313134
use Data::Dumper;
31323135
DSN:
31333136
do {
@@ -3136,21 +3139,33 @@ sub get_cxn_from_dsn_table {
31363139
if ( $dsn_strings ) {
31373140
foreach my $dsn_string ( @$dsn_strings ) {
31383141
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
3139-
if ($args{wait_no_die}) {
3140-
my $lcxn;
3141-
eval {
3142-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
3143-
};
3144-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
3145-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
3142+
3143+
my $raw_dsn = $dp->parse($dsn_string);
3144+
my $dsn_defaults = $dp->parse_options($o);
3145+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
3146+
3147+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
3148+
PTDEBUG && _d('DSN - username set from --replica-user');
3149+
$my_dsn->{u} = $o->get('replica-user');
3150+
}
3151+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
3152+
PTDEBUG && _d('DSN - password set from --replica-password');
3153+
$my_dsn->{p} = $o->get('replica-password');
3154+
}
3155+
3156+
eval {
3157+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
3158+
};
3159+
if ( $EVAL_ERROR ) {
3160+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
3161+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
31463162
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
31473163
sleep(1);
31483164
goto DSN;
31493165
}
3150-
push @cxn, $lcxn;
3151-
} else {
3152-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
3166+
die $EVAL_ERROR;
31533167
}
3168+
push @cxn, $lcxn;
31543169
}
31553170
}
31563171
$done = 1;

bin/pt-replica-restart

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3542,6 +3542,9 @@ sub get_cxn_from_dsn_table {
35423542
my $sql = "SELECT dsn FROM $dsn_table ORDER BY id";
35433543
PTDEBUG && _d($sql);
35443544
my @cxn;
3545+
my $o = $self->{OptionParser};
3546+
my $my_dsn;
3547+
my $lcxn;
35453548
use Data::Dumper;
35463549
DSN:
35473550
do {
@@ -3550,21 +3553,33 @@ sub get_cxn_from_dsn_table {
35503553
if ( $dsn_strings ) {
35513554
foreach my $dsn_string ( @$dsn_strings ) {
35523555
PTDEBUG && _d('DSN from DSN table:', $dsn_string);
3553-
if ($args{wait_no_die}) {
3554-
my $lcxn;
3555-
eval {
3556-
$lcxn = $make_cxn->(dsn_string => $dsn_string);
3557-
};
3558-
if ( $EVAL_ERROR && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
3559-
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/)) {
3556+
3557+
my $raw_dsn = $dp->parse($dsn_string);
3558+
my $dsn_defaults = $dp->parse_options($o);
3559+
$my_dsn = $dp->parse($dsn_string, undef, $dsn_defaults);
3560+
3561+
if ( $o->got('replica-user') && !defined $raw_dsn->{u} ) {
3562+
PTDEBUG && _d('DSN - username set from --replica-user');
3563+
$my_dsn->{u} = $o->get('replica-user');
3564+
}
3565+
if ( $o->got('replica-password') && !defined $raw_dsn->{p} ) {
3566+
PTDEBUG && _d('DSN - password set from --replica-password');
3567+
$my_dsn->{p} = $o->get('replica-password');
3568+
}
3569+
3570+
eval {
3571+
$lcxn = $make_cxn->(dsn => $my_dsn, parent => $parent);
3572+
};
3573+
if ( $EVAL_ERROR ) {
3574+
if ( $args{wait_no_die} && ($dsn_tbl_cxn->lost_connection($EVAL_ERROR)
3575+
|| $EVAL_ERROR =~ m/Can't connect to MySQL server/) ) {
35603576
PTDEBUG && _d("Server is not accessible, waiting when it is online again");
35613577
sleep(1);
35623578
goto DSN;
35633579
}
3564-
push @cxn, $lcxn;
3565-
} else {
3566-
push @cxn, $make_cxn->(dsn_string => $dsn_string, parent => $parent);
3580+
die $EVAL_ERROR;
35673581
}
3582+
push @cxn, $lcxn;
35683583
}
35693584
}
35703585
$done = 1;

0 commit comments

Comments
 (0)