From 1f9ba2a4640995dff17803edc7d4c3e3f5812888 Mon Sep 17 00:00:00 2001 From: Mike Benshoof Date: Fri, 25 Oct 2019 15:14:46 +0000 Subject: [PATCH 1/2] PT-1776: Adding in slave-user and slave-password for dsn table based recursion --- bin/pt-table-checksum | 22 ++++++++++++++++++++++ bin/pt-table-sync | 23 +++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 00ed47f73..89927bc55 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -5888,9 +5888,31 @@ sub get_cxn_from_dsn_table { PTDEBUG && _d($sql); my $dsn_strings = $dbh->selectcol_arrayref($sql); my @cxn; + my $o = $self->{OptionParser}; + if ( $dsn_strings ) { foreach my $dsn_string ( @$dsn_strings ) { PTDEBUG && _d('DSN from DSN table:', $dsn_string); + + if ($o->got('slave-user') || $o->got('slave-password')) { + + my $slave_user = ''; + my $slave_password = ''; + + if ($o->got('slave-user')) { + my $slave_user_raw = $o->get('slave-user'); + $slave_user = "u=$slave_user_raw"; + } + + if ($o->got('slave-password')) { + my $slave_pass_raw = $o->get('slave-password'); + $slave_password = "p=$slave_pass_raw"; + } + + $dsn_string = "$slave_user,$slave_password,$dsn_string"; + PTDEBUG && _d('DSN from DSN table (modified with slave creds):', $dsn_string); + } + push @cxn, $make_cxn->(dsn_string => $dsn_string); } } diff --git a/bin/pt-table-sync b/bin/pt-table-sync index 44b094890..b49f10a2a 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -7418,12 +7418,35 @@ sub get_cxn_from_dsn_table { PTDEBUG && _d($sql); my $dsn_strings = $dbh->selectcol_arrayref($sql); my @cxn; + my $o = $self->{OptionParser}; + if ( $dsn_strings ) { foreach my $dsn_string ( @$dsn_strings ) { PTDEBUG && _d('DSN from DSN table:', $dsn_string); + + if ($o->got('slave-user') || $o->got('slave-password')) { + + my $slave_user = ''; + my $slave_password = ''; + + if ($o->got('slave-user')) { + my $slave_user_raw = $o->get('slave-user'); + $slave_user = "u=$slave_user_raw"; + } + + if ($o->got('slave-password')) { + my $slave_pass_raw = $o->get('slave-password'); + $slave_password = "p=$slave_pass_raw"; + } + + $dsn_string = "$slave_user,$slave_password,$dsn_string"; + PTDEBUG && _d('DSN from DSN table (modified with slave creds):', $dsn_string); + } + push @cxn, $make_cxn->(dsn_string => $dsn_string); } } + return \@cxn; } From f4d102d1239a7eac5ad4c7c0920ed63c140878fb Mon Sep 17 00:00:00 2001 From: Mike Benshoof Date: Wed, 20 Dec 2023 10:07:23 -0600 Subject: [PATCH 2/2] Moving slave-password and slave-user logic into MasterSlave lib. Also making them not overwrite what is specified in DSN table. --- bin/pt-table-checksum | 21 --------------------- bin/pt-table-sync | 21 --------------------- lib/MasterSlave.pm | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 42 deletions(-) diff --git a/bin/pt-table-checksum b/bin/pt-table-checksum index 89927bc55..a8d54c7c2 100755 --- a/bin/pt-table-checksum +++ b/bin/pt-table-checksum @@ -5888,31 +5888,10 @@ sub get_cxn_from_dsn_table { PTDEBUG && _d($sql); my $dsn_strings = $dbh->selectcol_arrayref($sql); my @cxn; - my $o = $self->{OptionParser}; if ( $dsn_strings ) { foreach my $dsn_string ( @$dsn_strings ) { PTDEBUG && _d('DSN from DSN table:', $dsn_string); - - if ($o->got('slave-user') || $o->got('slave-password')) { - - my $slave_user = ''; - my $slave_password = ''; - - if ($o->got('slave-user')) { - my $slave_user_raw = $o->get('slave-user'); - $slave_user = "u=$slave_user_raw"; - } - - if ($o->got('slave-password')) { - my $slave_pass_raw = $o->get('slave-password'); - $slave_password = "p=$slave_pass_raw"; - } - - $dsn_string = "$slave_user,$slave_password,$dsn_string"; - PTDEBUG && _d('DSN from DSN table (modified with slave creds):', $dsn_string); - } - push @cxn, $make_cxn->(dsn_string => $dsn_string); } } diff --git a/bin/pt-table-sync b/bin/pt-table-sync index b49f10a2a..00ffcb59b 100755 --- a/bin/pt-table-sync +++ b/bin/pt-table-sync @@ -7418,31 +7418,10 @@ sub get_cxn_from_dsn_table { PTDEBUG && _d($sql); my $dsn_strings = $dbh->selectcol_arrayref($sql); my @cxn; - my $o = $self->{OptionParser}; if ( $dsn_strings ) { foreach my $dsn_string ( @$dsn_strings ) { PTDEBUG && _d('DSN from DSN table:', $dsn_string); - - if ($o->got('slave-user') || $o->got('slave-password')) { - - my $slave_user = ''; - my $slave_password = ''; - - if ($o->got('slave-user')) { - my $slave_user_raw = $o->get('slave-user'); - $slave_user = "u=$slave_user_raw"; - } - - if ($o->got('slave-password')) { - my $slave_pass_raw = $o->get('slave-password'); - $slave_password = "p=$slave_pass_raw"; - } - - $dsn_string = "$slave_user,$slave_password,$dsn_string"; - PTDEBUG && _d('DSN from DSN table (modified with slave creds):', $dsn_string); - } - push @cxn, $make_cxn->(dsn_string => $dsn_string); } } diff --git a/lib/MasterSlave.pm b/lib/MasterSlave.pm index 062862681..3ffbf7f69 100644 --- a/lib/MasterSlave.pm +++ b/lib/MasterSlave.pm @@ -978,9 +978,43 @@ sub get_cxn_from_dsn_table { PTDEBUG && _d($sql); my $dsn_strings = $dbh->selectcol_arrayref($sql); my @cxn; + my $o = $self->{OptionParser}; + if ( $dsn_strings ) { foreach my $dsn_string ( @$dsn_strings ) { PTDEBUG && _d('DSN from DSN table:', $dsn_string); + + my $dsn_tmp = $dp->parse($dsn_string); + + my $slave_user = ''; + my $dsn_user = $dsn_tmp->{u}; + + if (!defined $dsn_user) { + if ($o->got('slave-user')) { + my $slave_user_raw = $o->get('slave-user'); + $slave_user = "u=$slave_user_raw,"; + PTDEBUG && _d('DSN - username set from --slave-user: ', $slave_user); + } else{ + PTDEBUG && _d('DSN - Try to use an old username from prior DSN'); + } + } + + my $slave_pass = ''; + my $dsn_pass = $dsn_tmp->{p}; + + if (!defined $dsn_pass) { + if ($o->got('slave-password')) { + my $slave_pass_raw = $o->get('slave-password'); + $slave_pass = "p=$slave_pass_raw,"; + PTDEBUG && _d('DSN - password set from --slave-password: ', $slave_pass); + } else{ + PTDEBUG && _d('DSN - Try to use an old password from prior DSN'); + } + } + + $dsn_string = "$slave_user$slave_pass$dsn_string"; + PTDEBUG && _d('DSN : Finalized DSN connection string:', $dsn_string); + push @cxn, $make_cxn->(dsn_string => $dsn_string); } }