CVS User Account cvsuser
Wed Feb 23 20:30:55 PST 2005
Log Message:
-----------
Added support for sets originating on different nodes.  The default
remains the $MASTERNODE, but you can now add an "origin" attribute in
the configuration file to designate that the set originates on some
other node.

Removed the requirement that each node have a parent.  This is now an
optional attribute in the configuration file -- otherwise, it is
assumed that the node can contact any other node that doesn't have a
parent, plus any node where it is the parent.

Modified init_cluster.pl so that it only writes "store path" commands
for paths that exist.

Fixed a couple of bugs in init_cluster.pl that were preventing it from
choosing the most efficient listen path between a given pair of nodes.

Modified Files:
--------------
    slony1-engine/tools/altperl:
        create_set.pl (r1.14 -> r1.15)
        drop_set.pl (r1.9 -> r1.10)
        init_cluster.pl (r1.11 -> r1.12)
        move_set.pl (r1.8 -> r1.9)
        slon-tools.pm (r1.18 -> r1.19)
        slon_tools.conf-sample (r1.3 -> r1.4)
        subscribe_set.pl (r1.9 -> r1.10)

-------------- next part --------------
Index: slon-tools.pm
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon-tools.pm,v
retrieving revision 1.18
retrieving revision 1.19
diff -Ltools/altperl/slon-tools.pm -Ltools/altperl/slon-tools.pm -u -w -r1.18 -r1.19
--- tools/altperl/slon-tools.pm
+++ tools/altperl/slon-tools.pm
@@ -10,7 +10,7 @@
 		user => 'postgres',
 		node => undef,
 		password => undef,
-		parent => 1,
+		parent => undef,
 		noforward => undef,
 		sslmode => undef
 	       );
@@ -237,6 +237,7 @@
     }
 
     # Set the variables for this set.
+    $SET_ORIGIN   = ($match->{"origin"} or $MASTERNODE);
     $TABLE_ID     = $match->{"table_id"};
     $SEQUENCE_ID  = $match->{"sequence_id"};
     @PKEYEDTABLES = @{$match->{"pkeyedtables"}};
Index: create_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/create_set.pl,v
retrieving revision 1.14
retrieving revision 1.15
diff -Ltools/altperl/create_set.pl -Ltools/altperl/create_set.pl -u -w -r1.14 -r1.15
--- tools/altperl/create_set.pl
+++ tools/altperl/create_set.pl
@@ -44,7 +44,7 @@
     $table = ensure_namespace($table);
     print SLONIK "  echo '  Adding unique key to table $table...';\n";
     print SLONIK "  table add key (\n";
-    print SLONIK "    node id=$MASTERNODE,\n";
+    print SLONIK "    node id = $SET_ORIGIN,\n";
     print SLONIK "    full qualified name='$table'\n";
     print SLONIK "  );\n";
 }
@@ -53,7 +53,7 @@
 print SLONIK "\n";
 print SLONIK "# CREATE SET\n";
 print SLONIK "  try {\n";
-print SLONIK "    create set (id = $SET_ID, origin = $MASTERNODE, comment = 'Set $SET_ID for $CLUSTER_NAME');\n";
+print SLONIK "    create set (id = $SET_ID, origin = $SET_ORIGIN, comment = 'Set $SET_ID for $CLUSTER_NAME');\n";
 print SLONIK "  } on error {\n";
 print SLONIK "    echo 'Could not create subscription set $SET_ID for $CLUSTER_NAME!';\n";
 print SLONIK "    exit -1;\n";
@@ -69,7 +69,7 @@
 
 foreach my $table (@SERIALTABLES) {
     $table = ensure_namespace($table);
-    print SLONIK "  set add table (set id = $SET_ID, origin = $MASTERNODE, id = $TABLE_ID,\n";
+    print SLONIK "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
     print SLONIK "                 full qualified name = '$table', key=serial,\n";
     print SLONIK "                 comment = 'Table $table without primary key');\n";
     print SLONIK "  echo 'Add unkeyed table $table';\n";
@@ -78,7 +78,7 @@
 
 foreach my $table (@PKEYEDTABLES) {
     $table = ensure_namespace($table);
-    print SLONIK "  set add table (set id = $SET_ID, origin = $MASTERNODE, id = $TABLE_ID,\n";
+    print SLONIK "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
     print SLONIK "                 full qualified name = '$table',\n";
     print SLONIK "                 comment = 'Table $table with primary key');\n";
     print SLONIK "  echo 'Add primary keyed table $table';\n";
@@ -88,7 +88,7 @@
 foreach my $table (keys %KEYEDTABLES) {
     my $key = $KEYEDTABLES{$table};
     $table = ensure_namespace($table);
-    print SLONIK "  set add table (set id = $SET_ID, origin = $MASTERNODE, id = $TABLE_ID,\n";
+    print SLONIK "  set add table (set id = $SET_ID, origin = $SET_ORIGIN, id = $TABLE_ID,\n";
     print SLONIK "                 full qualified name = '$table', key='$key'\n";
     print SLONIK "                 comment = 'Table $table with candidate primary key $key');\n";
     print SLONIK "  echo 'Add candidate primary keyed table $table';\n";
@@ -103,7 +103,7 @@
 $SEQUENCE_ID = 1 if $SEQUENCE_ID < 1;
 foreach my $seq (@SEQUENCES) {
     $seq = ensure_namespace($seq);
-    print SLONIK "  set add sequence (set id = $SET_ID, origin = $MASTERNODE, id = $SEQUENCE_ID,\n";
+    print SLONIK "  set add sequence (set id = $SET_ID, origin = $SET_ORIGIN, id = $SEQUENCE_ID,\n";
     print SLONIK "                    full qualified name = '$seq',\n";
     print SLONIK "                    comment = 'Sequence $seq');\n";
     print SLONIK "  echo 'Add sequence $seq';\n";
Index: subscribe_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/subscribe_set.pl,v
retrieving revision 1.9
retrieving revision 1.10
diff -Ltools/altperl/subscribe_set.pl -Ltools/altperl/subscribe_set.pl -u -w -r1.9 -r1.10
--- tools/altperl/subscribe_set.pl
+++ tools/altperl/subscribe_set.pl
@@ -43,23 +43,25 @@
   die $USAGE;
 }
 
+get_set($set) or die "Non-existent set specified.\n";
+
 $FILE="/tmp/slonik-subscribe.$$";
 open(SLONIK, ">$FILE");
 print SLONIK genheader();
 print SLONIK "  try {\n";
 
 if ($DSN[$node]) {
-  my $parent = 1;
+  my $provider = $SET_ORIGIN;
   my $forward;
   if ($PARENT[$node]) {
-    $parent = $PARENT[$node];
+    $provider = $PARENT[$node];
   }
   if ($NOFORWARD[$node] eq "yes") {
     $forward = "no";
   } else {
     $forward = "yes";
   }
-  print SLONIK "    subscribe set (id = $set, provider = $parent, receiver = $node, forward = $forward);\n";
+  print SLONIK "    subscribe set (id = $set, provider = $provider, receiver = $node, forward = $forward);\n";
 } else {
   die "Node $node not found\n";
 }
Index: init_cluster.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/init_cluster.pl,v
retrieving revision 1.11
retrieving revision 1.12
diff -Ltools/altperl/init_cluster.pl -Ltools/altperl/init_cluster.pl -u -w -r1.11 -r1.12
--- tools/altperl/init_cluster.pl
+++ tools/altperl/init_cluster.pl
@@ -65,15 +65,14 @@
       my $dsnb = $DSN[$nodeb];
       my $providerba = $VIA[$nodea][$nodeb];
       my $providerab = $VIA[$nodeb][$nodea];
-      if (!$printed[$nodea][$nodeb]) {
+      if (!$printed[$nodea][$nodeb] and $providerab == $nodea) {
 	print SLONIK "  store path (server = $nodea, client = $nodeb, conninfo = '$dsna');\n";
 	$printed[$nodea][$nodeb] = "done";
       }
-      if (!$printed[$nodeb][$nodea]) {
+      if (!$printed[$nodeb][$nodea] and $providerba == $nodea) {
 	print SLONIK "  store path (server = $nodeb, client = $nodea, conninfo = '$dsnb');\n";
 	$printed[$nodeb][$nodea] = "done";
       }
-      print SLONIK "  echo 'configured path between $nodea and $nodeb';\n";
     }
   }
 }
@@ -111,7 +110,9 @@
     $VIA[$node1][$node1] = 0;
     foreach my $node2 (@NODES) {
       if ($node2 != $node1) {
-	if ($PARENT[$node1] == $node2) {
+	if ((not ($PARENT[$node1] or $PARENT[$node2])) or
+	    ($PARENT[$node1] and $PARENT[$node1] == $node2) or
+	    ($PARENT[$node2] and $PARENT[$node2] == $node1)) {
 	  $PATH[$node1][$node2] = 1;
 	  $PATH[$node2][$node1] = 1;
 	  # Set up a cost 1 path between them
@@ -156,6 +157,9 @@
 				# So we go via node 2
 		$VIA[$node3][$node1] = $node2;
 		$COST[$node3][$node1] = $newcost;
+
+		$VIA[$node1][$node3] = $node2;
+		$COST[$node1][$node3] = $newcost;
 	      }
 	    }
 	  }
Index: slon_tools.conf-sample
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/slon_tools.conf-sample,v
retrieving revision 1.3
retrieving revision 1.4
diff -Ltools/altperl/slon_tools.conf-sample -Ltools/altperl/slon_tools.conf-sample -u -w -r1.3 -r1.4
--- tools/altperl/slon_tools.conf-sample
+++ tools/altperl/slon_tools.conf-sample
@@ -47,7 +47,6 @@
              password => '');
 
     add_node(node     => 2,
-	     parent   => 1,
 	     host     => 'server2',
 	     dbname   => 'database',
 	     port     => 5432,
@@ -55,12 +54,25 @@
              password => '');
 
     add_node(node     => 3,
-	     parent   => 1,
 	     host     => 'server3',
 	     dbname   => 'database',
 	     port     => 5432,
 	     user     => 'postgres',
              password => '');
+
+    # If the node should only receive event notifications from a
+    # single node (e.g. if it can't access the other nodes), you can
+    # specify a single parent.  The downside to this approach is that
+    # if the parent goes down, your node becomes stranded.
+
+    add_node(node     => 4,
+	     parent   => 3,
+	     host     => 'server4',
+	     dbname   => 'database',
+	     port     => 5432,
+	     user     => 'postgres',
+             password => '');
+
 }
 
 # The $SLONY_SETS variable contains information about all of the sets
@@ -74,6 +86,11 @@
 	# The set_id, also unique
 	"set_id" => 1,
 
+	# Uncomment the following line to change the origin
+	# (a.k.a. master) for the set.  The default is $MASTERNODE.
+	#
+	# "origin" => 1,
+
 	# The first ID to use for tables and sequences that are added
 	# to the replication cluster.  This must be unique across the
 	# cluster.
Index: move_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/move_set.pl,v
retrieving revision 1.8
retrieving revision 1.9
diff -Ltools/altperl/move_set.pl -Ltools/altperl/move_set.pl -u -w -r1.8 -r1.9
--- tools/altperl/move_set.pl
+++ tools/altperl/move_set.pl
@@ -64,6 +64,8 @@
 print SLONIK "      unlock set (id = $set, origin = $node1);\n";
 print SLONIK "      exit 1;\n";
 print SLONIK "  }\n";
-print SLONIK "  echo 'Replication set $set moved from node $node1 to $node2';\n";
+print SLONIK "  echo 'Replication set $set moved from node $node1 to $node2.  Remember to';\n";
+print SLONIK "  echo 'update your configuration file, if necessary, to note the new location';\n";
+print SLONIK "  echo 'for the set.';\n";
 close SLONIK;
 run_slonik_script("/tmp/slonik.$$");
Index: drop_set.pl
===================================================================
RCS file: /usr/local/cvsroot/slony1/slony1-engine/tools/altperl/drop_set.pl,v
retrieving revision 1.9
retrieving revision 1.10
diff -Ltools/altperl/drop_set.pl -Ltools/altperl/drop_set.pl -u -w -r1.9 -r1.10
--- tools/altperl/drop_set.pl
+++ tools/altperl/drop_set.pl
@@ -36,11 +36,13 @@
   die $USAGE;
 }
 
+get_set($set) or die "Non-existent set specified.\n";
+
 $FILE = "/tmp/dropset.$$";
 open(SLONIK, ">", $FILE);
 print SLONIK genheader();
 print SLONIK "  try {\n";
-print SLONIK "        drop set (id = $set, origin = $MASTERNODE);\n";
+print SLONIK "        drop set (id = $set, origin = $SET_ORIGIN);\n";
 print SLONIK "  } on error {\n";
 print SLONIK "        exit 1;\n";
 print SLONIK "  }\n";


More information about the Slony1-commit mailing list