X-Git-Url: https://git.8kb.co.uk/?p=slony-i%2Fslony_failover;a=blobdiff_plain;f=slony_failover.pl;h=19bedcfe95d7726c47bdf2cf4df6050c30492094;hp=377dfaa1e06172c37a899c024fa559c3d00b86a2;hb=2e3cbf55e453c18c327c946822662e21b62efc78;hpb=0e9f92c0400fec3285b0d7b40421e09ba001d4c1 diff --git a/slony_failover.pl b/slony_failover.pl old mode 100644 new mode 100755 index 377dfaa..19bedcf --- a/slony_failover.pl +++ b/slony_failover.pl @@ -714,10 +714,10 @@ sub loadCluster { COALESCE(c.pa_conninfo,(SELECT pa_conninfo FROM $qw_clname.sl_path WHERE pa_server = $qw_clname.getlocalnodeid(?) LIMIT 1)) AS no_conninfo, array_to_string(array(SELECT set_id FROM $qw_clname.sl_set WHERE set_origin = a.no_id ORDER BY set_id),',') AS origin_sets, string_agg(CASE WHEN b.sub_receiver = a.no_id AND b.sub_forward AND b.sub_active THEN b.sub_set::text END, ',' ORDER BY b.sub_set) AS prov_sets, - coalesce(trim(replace(substring(a.no_comment from '\\\\((.+)\\\\)'), ' ','')), 'node' || a.no_id) AS no_name, + coalesce(trim(regexp_replace(substring(a.no_comment from E'\\\\((.+)\\\\)'), '[^0-9A-Za-z]','_','g')), 'node' || a.no_id) AS no_name, 'n' || b.sub_provider || '->(' || string_agg(CASE WHEN b.sub_receiver = a.no_id THEN 's' || b.sub_set END,',' ORDER BY b.sub_set,',') || ')' AS sub_tree, - coalesce(trim(replace(substring(d.no_comment from '\\\\((.+)\\\\)'), ' ','')), 'node' || b.sub_provider, '') - || '->(' || string_agg(CASE WHEN b.sub_receiver = a.no_id THEN coalesce(trim(translate(e.set_comment, ' ,->', '____')), 'set' || b.sub_set) END,',' ORDER BY b.sub_set) || ')' AS sub_tree_name, + coalesce(trim(regexp_replace(substring(d.no_comment from E'\\\\((.+)\\\\)'), '[^0-9A-Za-z]','_','g')), 'node' || b.sub_provider, '') + || '->(' || string_agg(CASE WHEN b.sub_receiver = a.no_id THEN coalesce(trim(regexp_replace(e.set_comment, '[^0-9A-Za-z]', '_', 'g')), 'set' || b.sub_set) END,',' ORDER BY b.sub_set) || ')' AS sub_tree_name, CASE " . ((substr($version,0,3) >= 2.2) ? "WHEN a.no_failed THEN 'FAILED' " : "") . "WHEN a.no_active THEN 'ACTIVE' ELSE 'INACTIVE' END AS no_status, array_to_string(array(SELECT DISTINCT sub_set::text FROM $qw_clname.sl_subscribe WHERE sub_provider = a.no_id AND sub_active ORDER BY sub_set),',') AS prov_sets_active, string_agg(CASE WHEN b.sub_receiver = a.no_id THEN b.sub_set::text END,',' ORDER BY b.sub_set,',') AS sub_sets @@ -847,8 +847,8 @@ sub loadLag { eval { $dbh = DBI->connect($dsn, $dbuser, $dbpass, {RaiseError => 1}); $qw_clname = $dbh->quote_identifier("_" . $clname); - $query = "SELECT a.st_origin || ' (' || coalesce(trim(replace(substring(b.no_comment from '\\\\((.+)\\\\)'), ' ','')), 'node' || b.no_id) || ')<->' - || a.st_received || ' (' || coalesce(trim(replace(substring(c.no_comment from '\\\\((.+)\\\\)'), ' ','')), 'node' || c.no_id) || ') Events: ' + $query = "SELECT a.st_origin || ' (' || coalesce(trim(regexp_replace(substring(b.no_comment from E'\\\\((.+)\\\\)'), '[^0-9A-Za-z]','_', 'g')), 'node' || b.no_id) || ')<->' + || a.st_received || ' (' || coalesce(trim(regexp_replace(substring(c.no_comment from E'\\\\((.+)\\\\)'), '[^0-9A-Za-z]','_', 'g')), 'node' || c.no_id) || ') Events: ' || a.st_lag_num_events || ' Time: ' || a.st_lag_time FROM $qw_clname.sl_status a INNER JOIN $qw_clname.sl_node b on a.st_origin = b.no_id @@ -1168,7 +1168,7 @@ sub writeMoveSet { if (($subs) && ($g_resubscribe_method eq 'subscribe')) { foreach my $other_subs (@g_cluster) { - if (($other_subs->[6] ne "INACTIVE") && ($other_subs->[0] != $from) && ($other_subs->[0] != $to)) { + if (($other_subs->[6] eq "ACTIVE") && ($other_subs->[0] != $from) && ($other_subs->[0] != $to)) { if (exists $g_backups{$other_subs->[0]}) { $line_prefix = "# (Node $other_subs->[0] unavailable) "; @@ -1236,7 +1236,7 @@ sub writeMoveSet { if (($subs) && ($g_resubscribe_method eq 'resubscribe')) { foreach my $other_subs (@g_cluster) { - if (($other_subs->[6] ne "INACTIVE") && ($other_subs->[0] != $from) && ($other_subs->[0] != $to)) { + if (($other_subs->[6] eq "ACTIVE") && ($other_subs->[0] != $from) && ($other_subs->[0] != $to)) { if (exists $g_backups{$other_subs->[0]}) { $line_prefix = "# (Node $other_subs->[0] unavailable) "; } @@ -1264,7 +1264,7 @@ sub writeMoveSet { print SLONFILE ($line_prefix . "ECHO 'Issuing resubscribe for provider $to -> receiver $other_subs->[0]';\n"); print SLONFILE ($line_prefix . - "SUBSCRIBE NODE ( ORIGIN = $to, PROVIDER = $to, RECEIVER = $other_subs->[0] );\n"); + "RESUBSCRIBE NODE ( ORIGIN = $to, PROVIDER = $to, RECEIVER = $other_subs->[0] );\n"); } } else { @@ -1487,6 +1487,13 @@ sub lookupMsg { return $text; } +sub qtrim { + my $string = shift; + $string =~ s/^('|")+//; + $string =~ s/('|")+$//; + return $string; +} + sub trim($) { my $string = shift; $string =~ s/^\s+//; @@ -1704,109 +1711,112 @@ sub getConfig { my $cfgfile = shift; my @fields; my $success = false; + my $value; if (open(CFGFILE, "<", $cfgfile)) { foreach () { chomp $_; for ($_) { s/\r//; - s/\#.*//; + #s/\#.*//; + s/#(?=(?:(?:[^']|[^"]*+'){2})*+[^']|[^"]*+\z).*//; } if (length(trim($_))) { @fields = split('=', $_, 2); given(lc($fields[0])) { + $value = qtrim(trim($fields[1])); when(/\blang\b/i) { - $g_lang = trim($fields[1]); + $g_lang = $value; } when(/\bslony_database_host\b/i) { - $g_dbhost = trim($fields[1]); + $g_dbhost = $value; } when(/\bslony_database_port\b/i) { - $g_dbport = $fields[1]; + $g_dbport = checkInteger($value); } when(/\bslony_database_name\b/i) { - $g_dbname = trim($fields[1]); + $g_dbname = $value; } when(/\bslony_database_user\b/i) { - $g_dbuser = trim($fields[1]); + $g_dbuser = $value; } when(/\bslony_database_password\b/i) { - $g_dbpass = trim($fields[1]); + $g_dbpass = $value; } when(/\bslony_cluster_name\b/i) { - $g_clname = trim($fields[1]); + $g_clname = $value; } when(/\benable_debugging\b/i) { - $g_debug = checkBoolean(trim($fields[1])); + $g_debug = checkBoolean($value); } when(/\bprefix_directory\b/i) { - $g_prefix = trim($fields[1]); + $g_prefix = $value; } when(/\bseparate_working_directory\b/i) { - $g_separate_working = checkBoolean(trim($fields[1])); + $g_separate_working = checkBoolean($value); } when(/\bpid_filename\b/i) { - $g_pidfile = trim($fields[1]); + $g_pidfile = $value; } when(/\bfailover_offline_subscriber_only\b/i) { - $g_fail_subonly = checkBoolean(trim($fields[1])); + $g_fail_subonly = checkBoolean($value); } when(/\bdrop_failed_nodes\b/i) { - $g_drop_failed = checkBoolean(trim($fields[1])); + $g_drop_failed = checkBoolean($value); } when(/\blog_line_prefix\b/i) { - $g_log_prefix = trim($fields[1]); + $g_log_prefix = $value; } when(/\blog_filename\b/i) { - $g_logfile = trim($fields[1]); + $g_logfile = $value; } when(/\blog_to_postgresql\b/i) { - $g_log_to_db = checkBoolean(trim($fields[1])); + $g_log_to_db = checkBoolean($value); } when(/\blog_database_host\b/i) { - $g_logdb_host = trim($fields[1]); + $g_logdb_host = $value; } when(/\blog_database_port\b/i) { - $g_logdb_port = $fields[1]; + $g_logdb_port = checkInteger($value); } when(/\blog_database_name\b/i) { - $g_logdb_name = trim($fields[1]); + $g_logdb_name = $value; } when(/\blog_database_user\b/i) { - $g_logdb_user = trim($fields[1]); + $g_logdb_user = $value; } when(/\blog_database_password\b/i) { - $g_logdb_pass = trim($fields[1]); + $g_logdb_pass = $value; } when(/\benable_try_blocks\b/i) { - $g_use_try_blocks = checkBoolean(trim($fields[1])); + $g_use_try_blocks = checkBoolean($value); } when(/\bpull_aliases_from_comments\b/i) { - $g_use_comment_aliases = checkBoolean(trim($fields[1])); + $g_use_comment_aliases = checkBoolean($value); } when(/\bslonik_path\b/i) { - $g_slonikpath = trim($fields[1]); + $g_slonikpath = $value; } when(/\blockset_method\b/i) { - $g_lockset_method = trim($fields[1]); + $g_lockset_method = $value; } when(/\benable_autofailover\b/i) { - $g_autofailover = checkBoolean(trim($fields[1])); + $g_autofailover = checkBoolean($value); } when(/\bautofailover_poll_interval\b/i) { - $g_autofailover_poll_interval = checkInteger(trim($fields[1])); + $g_autofailover_poll_interval = checkInteger($value); } when(/\bautofailover_node_retry\b/i) { - $g_autofailover_retry = checkInteger(trim($fields[1])); + $g_autofailover_retry = checkInteger($value); } when(/\bautofailover_sleep_time\b/i) { - $g_autofailover_retry_sleep = checkInteger(trim($fields[1])); + $g_autofailover_retry_sleep = checkInteger($value); } when(/\bautofailover_forwarding_providers\b/i) { - $g_autofailover_provs = checkBoolean(trim($fields[1])); + $g_autofailover_provs = checkBoolean($value); } when(/\bautofailover_config_any_node\b/i) { - $g_autofailover_config_any = checkBoolean(trim($fields[1])); + $g_autofailover_config_any = checkBoolean($value); } } } @@ -2175,4 +2185,4 @@ sub findBackup { } } return keys(%g_backups); -} \ No newline at end of file +}