Add syncname to sequences table, to prevent errors when one sequence from one databas...
authorJoshua Tolley <josh@endpoint.com>
Tue, 22 Dec 2009 22:46:59 +0000 (15:46 -0700)
committerJoshua Tolley <josh@endpoint.com>
Tue, 22 Dec 2009 22:46:59 +0000 (15:46 -0700)
Bucardo.pm
bucardo.schema
t/BucardoTesting.pm

index 32d3eefab3511c1d06e2278cc44aaa561831614a..cc823384c4fa760ed9b0beea92046fb4d00e3646 100644 (file)
@@ -4496,9 +4496,9 @@ sub start_kid {
                                        my ($lastval, $iscalled) = @{$sourcedbh->selectall_arrayref($SQL)->[0]};
 
                                        ## Check our internal table to see if we really need to propagate this sequence
-                                       $SQL = 'SELECT value, iscalled FROM bucardo.bucardo_sequences WHERE tablename = ?';
+                                       $SQL = 'SELECT value, iscalled FROM bucardo.bucardo_sequences WHERE tablename = ? AND syncname = ?';
                                        $sth = $sourcedbh->prepare($SQL);
-                                       $count = $sth->execute($g->{oid});
+                                       $count = $sth->execute($g->{oid}, $sync->{name});
                                        my $newval = 0;
                                        if ($count < 1) {
                                                $newval = 1; ## Never before seen, so add to the table
@@ -4520,14 +4520,15 @@ sub start_kid {
 
                                                ## Copy the change to our internal table
                                                if ($newval == 1) {
-                                                       $SQL = 'INSERT INTO bucardo.bucardo_sequences (tablename, value, iscalled) VALUES (?,?,?)';
+                                                       $SQL = 'INSERT INTO bucardo.bucardo_sequences (tablename, syncname, value, iscalled) VALUES (?,?,?,?)';
                                                        $sth = $sourcedbh->prepare($SQL);
-                                                       $sth->execute($g->{oid},$lastval,$iscalled);
+                            $sth->execute($g->{oid},$sync->{name},$lastval,$iscalled);
                                                }
                                                else {
-                                                       $SQL = 'UPDATE bucardo.bucardo_sequences SET value=?, iscalled=? WHERE tablename=?';
+                            $self->glog('block 2');
+                                                       $SQL = 'UPDATE bucardo.bucardo_sequences SET value=?, iscalled=? WHERE tablename=? AND syncname=?';
                                                        $sth = $sourcedbh->prepare($SQL);
-                                                       $sth->execute($lastval,$iscalled,$g->{oid});
+                                                       $sth->execute($lastval,$iscalled,$g->{oid}, $sync->{name});
                                                }
 
                                                ## Internal note so we know things have changed
@@ -5211,7 +5212,7 @@ sub start_kid {
                                        $deltacount{sequences}++;
 
                                        ## Get the last seen value
-                                       my $LASTSEQUENCESQL = 'SELECT value, iscalled FROM bucardo.bucardo_sequences WHERE tablename = ?';
+                                       my $LASTSEQUENCESQL = 'SELECT value, iscalled FROM bucardo.bucardo_sequences WHERE tablename = ? AND syncname = ?';
 
                                        ## Source wins - copy its value to the target
                                        if (1 == $action) {
@@ -5227,7 +5228,7 @@ sub start_kid {
 
                                                ## Has it changed since last visit?
                                                $sth = $sourcedbh->prepare($LASTSEQUENCESQL);
-                                               $count = $sth->execute($g->{oid});
+                                               $count = $sth->execute($g->{oid}, $sync->{name});
                                                my $newval = 0;
                                                if ($count < 1) {
                                                        $newval = 1; ## Never before seen, so add to the table
@@ -5252,12 +5253,12 @@ sub start_kid {
 
                                                ## Save to the target's internal table
                                                ## Rather than worry about upserts, we'll just delete/insert every time
-                                               $SQL = 'DELETE FROM bucardo.bucardo_sequences WHERE tablename = ?';
+                                               $SQL = 'DELETE FROM bucardo.bucardo_sequences WHERE tablename = ? AND syncname = ?';
                                                $sth = $sourcedbh->prepare($SQL);
-                                               $sth->execute($g->{targetoid}{$targetdb});
-                                               $SQL = 'INSERT INTO bucardo.bucardo_sequences (tablename, value, iscalled) VALUES (?,?,?)';
+                                               $sth->execute($g->{targetoid}{$targetdb}, $sync->{name});
+                                               $SQL = 'INSERT INTO bucardo.bucardo_sequences (tablename, syncname, value, iscalled) VALUES (?,?,?,?)';
                                                $sth = $sourcedbh->prepare($SQL);
-                                               $sth->execute($g->{targetoid}{$targetdb},$lastval,$iscalled);
+                                               $sth->execute($g->{targetoid}{$targetdb},$lastval,$iscalled, $sync->{name});
 
                                                ## Internal note so we know things have changed
                                                $deltacount{sequences}++;
@@ -5279,7 +5280,7 @@ sub start_kid {
 
                                        ## Has it changed since last visit?
                                        $sth = $sourcedbh->prepare($LASTSEQUENCESQL);
-                                       $count = $sth->execute($g->{oid});
+                                       $count = $sth->execute($g->{oid}, $sync->{name});
                                        my $newval = 0;
                                        if ($count < 1) {
                                                $newval = 1; ## Never before seen, so add to the table
@@ -5304,12 +5305,12 @@ sub start_kid {
 
                                        ## Save to the source's internal table
                                        ## Rather than worry about upserts, we'll just delete/insert every time
-                                       $SQL = 'DELETE FROM bucardo.bucardo_sequences WHERE tablename = ?';
+                                       $SQL = 'DELETE FROM bucardo.bucardo_sequences WHERE tablename = ? AND syncname = ?';
                                        $sth = $targetdbh->prepare($SQL);
-                                       $sth->execute($g->{oid});
-                                       $SQL = 'INSERT INTO bucardo.bucardo_sequences (tablename, value, iscalled) VALUES (?,?,?)';
+                                       $sth->execute($g->{oid}, $sync->{name});
+                                       $SQL = 'INSERT INTO bucardo.bucardo_sequences (tablename, syncname, value, iscalled) VALUES (?,?,?,?)';
                                        $sth = $targetdbh->prepare($SQL);
-                                       $sth->execute($g->{oid},$lastval,$iscalled);
+                                       $sth->execute($g->{oid},$sync->{name},$lastval,$iscalled);
 
                                        ## Proceed to the next goat
                                        next;
index d722291342507305f41549674dd38550ddaf6e7b..5e9482b8f313922fbe40c221cd8fd074f593795f 100644 (file)
@@ -1748,6 +1748,7 @@ $bc$
                 $SQL = qq{
                     CREATE TABLE bucardo.bucardo_sequences (
                         tablename   OID         NOT NULL,
+                        syncname    TEXT        NOT NULL,
                         value       BIGINT      NOT NULL,
                         iscalled    BOOL        NOT NULL
                     );
@@ -1755,7 +1756,7 @@ $bc$
                 run_sql($SQL,$dbh);
 
                 $SQL = q{CREATE UNIQUE INDEX bucardo_sequences_tablename ON }
-                     . q{bucardo.bucardo_sequences (tablename)};
+                     . q{bucardo.bucardo_sequences (tablename, syncname)};
                 run_sql($SQL,$dbh);
             }
             if ($force) {
index a91079816a46ad0fafeb1e9bfe93530071b8e2e6..280962a2f96a073a225e006d723d0c01fad9e2b4 100644 (file)
@@ -1130,7 +1130,11 @@ sub wait_for_notice {
                alarm $timeout;
          N: {
                        while ($n = $dbh->func('pg_notifies')) {
-                               last N if $n->[0] eq $text;
+                               if ($n->[0] eq $text) {
+                    last N;
+                } else {
+                    print "$n->[0]\n" if $DEBUG;
+                }
                        }
                        sleep $sleep;
                        redo;