PT-1829 Fixed reconnection in heartbeat

This commit is contained in:
Carlos Salguero
2020-05-20 10:53:24 -03:00
parent 8e7113d457
commit 5efb3bd6f1

View File

@@ -6386,19 +6386,6 @@ sub main {
sleep $next_interval - $time;
PTDEBUG && _d('Woke up at', ts(time));
if ( $o->get('check-read-only') && $o->get('update') ) {
my $read_only_interval = $o->get('read-only-interval') || $interval;
while (server_is_readonly($dbh)) {
PTDEBUG && _d("Server is read only. Sleeping for $read_only_interval seconds...");
sleep($read_only_interval);
if (
-f $sentinel
) {
return 0;
}
}
}
# Connect or reconnect if necessary.
if ( !$dbh->ping() ) {
$dbh = $dp->get_dbh($dp->get_cxn_params($dsn), { AutoCommit => 1 });
@@ -6409,6 +6396,17 @@ sub main {
$heartbeat_sth = undef;
}
if ( $o->get('check-read-only') && $o->get('update') ) {
my $read_only_interval = $o->get('read-only-interval') || $interval;
while (server_is_readonly($dbh)) {
PTDEBUG && _d("Server is read only. Sleeping for $read_only_interval seconds...");
sleep($read_only_interval);
if (-f $sentinel) {
return 0;
}
}
}
if ( $o->get('monitor') ) {
$heartbeat_sth ||= $dbh->prepare($heartbeat_sql);
my ($delay) = $get_delay->($heartbeat_sth);