revision of node_is_subscribing function
authorLuiz K. Matsumura <luiz.matsumura@gmail.com>
Thu, 25 Oct 2012 12:58:54 +0000 (10:58 -0200)
committerLuiz K. Matsumura <luiz.matsumura@gmail.com>
Thu, 8 Nov 2012 22:03:25 +0000 (20:03 -0200)
- Type cast bug
- Space on qq and { causing sintax error
- initializing $nodenum parameter
- Creating a workaround in case of password for conection is defined to allow psql to connect
  Used PGPASSWORD enviroment variable.

tools/altperl/slon-tools.pm

index 4fedd2e2f3c2b1aefb7db37f5567a55ba796edc3..49eb78e84025131f0565b1c18733374d95f950d8 100644 (file)
@@ -292,20 +292,25 @@ sub get_set {
 # It does so by looking to see if there is a SUBSCRIBE_SET event corresponding
 # to a sl_subscribe entry that is not yet active.
 sub node_is_subscribing {
-  my $see_if_subscribing = qq {
+  my ($nodenum) = @_;
+  my $query = qq{
 select * from "_$CLUSTER_NAME".sl_event e, "_$CLUSTER_NAME".sl_subscribe s
 where ev_origin = "_$CLUSTER_NAME".getlocalnodeid('_$CLUSTER_NAME') and  -- Event on local node
       ev_type = 'SUBSCRIBE_SET' and                            -- Event is SUBSCRIBE SET
       --- Then, match criteria against sl_subscribe
-      sub_set = ev_data1 and sub_provider = ev_data2 and sub_receiver = ev_data3 and
+      sub_set::text = ev_data1 and sub_provider::text = ev_data2 and sub_receiver::text = ev_data3 and
       (case sub_forward when 'f' then 'f'::text when 't' then 't'::text end) = ev_data4
-
       --- And we're looking for a subscription that is not yet active
       and not sub_active
 limit 1;   --- One such entry is sufficient...
 };
-  my ($port, $host, $dbname, $dbuser)= ($PORT[$nodenum], $HOST[$nodenum], $DBNAME[$nodenum], $USER[$nodenum]);
-  my $result=`@@PGBINDIR@@/psql -p $port -h $host -c "$query" --tuples-only -U $dbuser $dbname`;
+  my ($port, $host, $dbname, $dbuser, $passwd)= ($PORT[$nodenum], $HOST[$nodenum], $DBNAME[$nodenum], $USER[$nodenum], $PASSWORD[$nodenum]);
+  my $result;
+  if ($passwd) {
+     $result=`PGPASSWORD=$passwd @@PGBINDIR@@/psql -p $port -h $host -c "$query" --tuples-only -U $dbuser $dbname`;
+  } else {
+     $result=`@@PGBINDIR@@/psql -p $port -h $host -c "$query" --tuples-only -U $dbuser $dbname`;
+  }
   chomp $result;
   #print "Query was: $query\n";
   #print "Result was: $result\n";