From 9f3302219520eae18c8fdf84ea746ff8f6865925 Mon Sep 17 00:00:00 2001 From: glyn Date: Wed, 7 May 2014 12:34:32 +0100 Subject: [PATCH] Amend how comments are used as aliases. sl_node and sl_set treated differently which isn't right but can stay for now --- README.md | 5 +++-- slony_failover.conf | 2 +- slony_failover.pl | 10 +++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 15ab927..e138da6 100644 --- a/README.md +++ b/README.md @@ -70,8 +70,9 @@ $ ./failover.pl [options] | General |**pid_filename** | /path/to/pidfile | *'/var/run/slony_failover.pid'* | Pid file to use when running in autofailover mode | General |**enable_try_blocks** | boolean | *false* | Write slonik script with try blocks where possible to aid error handling | General |**lockset_method** | single/multiple | *'multiple'* | Write slonik script that locks all sets -| General |**pull_aliases_from_comments** | boolean | *false* | If true, script will pull text from between parentheses in comments fields -| | | | | and use to generate (possibly) meaningful aliases for nodes and sets. +| General |**pull_aliases_from_comments** | boolean | *false* | If true, script will pull text from comment fields and use to generate +| | | | | possibly meaningful aliases for nodes and sets. +| | | | | For sl_set this uses the entire comment, and sl_node text in parentheses. | General |**log_line_prefix** | text | *null* | Prefix to add to log lines, special values: | | | | | %p = process ID | | | | | %t = timestamp without milliseconds diff --git a/slony_failover.conf b/slony_failover.conf index 177f365..f1be52a 100644 --- a/slony_failover.conf +++ b/slony_failover.conf @@ -25,7 +25,7 @@ lockset_method = multiple # Used for MOVE SET pull_aliases_from_comments = false # Try to generate aliases in the # slonik scripts based on comments within - # sl_node/set comments in parentheses + # sl_set and comments in parentheses in sl_node log_line_prefix = [%t PID=%p] # Special values: # %p = process ID diff --git a/slony_failover.pl b/slony_failover.pl index 073b428..32c938d 100644 --- 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 E'\\\\((.+)\\\\)'), ' ','')), '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 E'\\\\((.+)\\\\)'), ' ','')), '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 E'\\\\((.+)\\\\)'), ' ','')), 'node' || b.no_id) || ')<->' - || a.st_received || ' (' || coalesce(trim(replace(substring(c.no_comment from E'\\\\((.+)\\\\)'), ' ','')), '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 -- 2.39.2