From 3ecf171fdbbe9e1473c431f1feb8c400f71f8ec5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Su=C3=A1rez?= Date: Tue, 1 Aug 2023 18:14:11 -0600 Subject: [PATCH] Ignore disabled nodes --- pandora_server/util/pandora_ha.pl | 45 +++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/pandora_server/util/pandora_ha.pl b/pandora_server/util/pandora_ha.pl index 941b6dc854..be54f8d0ca 100755 --- a/pandora_server/util/pandora_ha.pl +++ b/pandora_server/util/pandora_ha.pl @@ -361,7 +361,7 @@ sub ha_load_databases($) { return unless defined($conf->{'ha_hosts'}); @HA_DB_Hosts = grep { !/^#/ } map { s/^\s+|\s+$//g; $_; } split(/,/, $conf->{'ha_hosts'}); - log_message($conf, 'DEBUG', "Loaded databases from disk (@HA_DB_Hosts)"); + log_message($conf, 'DEBUG', "Loaded databases from disk (@HA_DB_Hosts)"); } ############################################################################### @@ -388,9 +388,20 @@ sub ha_database_connect_pandora($) { # Load the list of HA databases. ha_load_databases($conf); - + # Select a new master database. my ($dbh, $utimestamp, $max_utimestamp) = (undef, undef, -1); + + my @disabled_nodes = get_disabled_nodes($conf); + + # If there are disabled nodes ignore them from the HA_DB_Hosts. + if(scalar @disabled_nodes ne 0){ + @HA_DB_Hosts = grep { my $item = $_; !grep { $_ eq $item } @disabled_nodes } @HA_DB_Hosts; + + my $data = join(",", @disabled_nodes); + log_message($conf, 'LOG', "Ignoring disabled hosts: " . $data); + } + foreach my $ha_dbhost (@HA_DB_Hosts) { # Retry each database ha_connect_retries times. @@ -481,6 +492,36 @@ sub ha_restart_pandora($) { `$config->{'pandora_service_cmd'} $control_command 2>/dev/null`; } +############################################################################### +# Get ip of the disabled nodes. +############################################################################### +sub get_disabled_nodes($) { + my ($conf) = @_; + + my $dbh = db_connect('mysql', + $conf->{'dbname'}, + $conf->{'dbhost'}, + $conf->{'dbport'}, + $conf->{'ha_dbuser'}, + $conf->{'ha_dbpass'}); + + my $disabled_nodes = get_db_value($dbh, "SELECT value FROM tconfig WHERE token = 'ha_disabled_nodes'"); + + if(!defined($disabled_nodes) || $disabled_nodes eq ""){ + $disabled_nodes = ','; + } + + my @disabled_nodes = split(',', $disabled_nodes); + + if(scalar @disabled_nodes ne 0){ + $disabled_nodes = join(",", @disabled_nodes); + @disabled_nodes = get_db_rows($dbh, "SELECT host FROM tdatabase WHERE id IN ($disabled_nodes)"); + @disabled_nodes = map { $_->{host} } @disabled_nodes; + } + + return @disabled_nodes; +} + ############################################################################### # Main (Pacemaker) ###############################################################################