Amend how comments are used as aliases. sl_node and sl_set treated differently which...
authorglyn <glyn@8kb.co.uk>
Wed, 7 May 2014 11:34:32 +0000 (12:34 +0100)
committerglyn <glyn@8kb.co.uk>
Wed, 7 May 2014 11:34:32 +0000 (12:34 +0100)
README.md
slony_failover.conf
slony_failover.pl

index 15ab927..e138da6 100644 (file)
--- 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
index 177f365..f1be52a 100644 (file)
@@ -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
index 073b428..32c938d 100644 (file)
@@ -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