From: glyn Date: Tue, 13 Jan 2015 13:45:58 +0000 (+0000) Subject: Add an initial state to cluster hash, this way we can tell the difference between... X-Git-Url: https://git.8kb.co.uk/?a=commitdiff_plain;h=4a6aee131dcf5b05a2ae04d4f4b65c0a6c4c5495;p=slony-i%2Fpgbouncer_follower Add an initial state to cluster hash, this way we can tell the difference between a cluster that has no suitable target nodes and where the previous cluster state has not yet been initialized. We also want to register that things have changed and there is now no suitable node, that way we can write nothing and effectively shut off the pool. --- diff --git a/pgbouncer_follower.pl b/pgbouncer_follower.pl index c721385..c6b6ede 100755 --- a/pgbouncer_follower.pl +++ b/pgbouncer_follower.pl @@ -288,11 +288,11 @@ sub generateConfig { sub checkCluster { my $infile = shift; my $changed = false; - my $current_cluster; - my $previous_cluster; + my $current_state = md5_hex('INIT'); + my $previous_state; foreach (@g_cluster) { if (!$g_origins_only || defined($_->[3])) { - $current_cluster = md5_hex(($current_cluster // "") . $_->[0] . $_->[2] . (defined($_->[3]) ? 't' : 'f') . $_->[6] . $_->[11]); + $current_state = md5_hex(($current_state // "") . $_->[0] . $_->[2] . (defined($_->[3]) ? 't' : 'f') . $_->[6] . $_->[11]); if ($g_debug) { printLogLn($g_logfile, "DEBUG: Node " . $_->[0] . " detail = " . $_->[2] . (defined($_->[3]) ? 't' : 'f') . $_->[6] . $_->[11]); } @@ -301,7 +301,7 @@ sub checkCluster { if (-f $infile) { if (open(CLUSTERFILE, "<", $infile)) { - $previous_cluster = ; + $previous_state = ; close(CLUSTERFILE); } else { @@ -309,12 +309,12 @@ sub checkCluster { } } - unless (-f $infile && ($current_cluster eq $previous_cluster)) { + unless (-f $infile && ($current_state eq $previous_state)) { if ($g_debug) { printLogLn($g_logfile, "DEBUG: Writing to status file"); } if (open(CLUSTERFILE, ">", $infile)) { - print CLUSTERFILE $current_cluster; + print CLUSTERFILE $current_state; close(CLUSTERFILE); } else { @@ -322,7 +322,7 @@ sub checkCluster { } } - if ((($previous_cluster // "") ne "") && (($current_cluster // "") ne "") && ($current_cluster ne $previous_cluster)){ + if ((($previous_state // "") ne "") && ($current_state ne $previous_state)){ $changed = true; }