More fullcopy/onetimecopy changes.
authorGreg Sabino Mullane <greg@endpoint.com>
Sat, 25 Feb 2012 05:31:01 +0000 (00:31 -0500)
committerGreg Sabino Mullane <greg@endpoint.com>
Sat, 25 Feb 2012 05:31:01 +0000 (00:31 -0500)
bucardo
bucardo.schema

diff --git a/bucardo b/bucardo
index ce9fe2b0a9828d4e5b1d00db719ee1ac22c425b9..d7f8f5aa5020e947746d4ce1c41b0c582ff55751 100755 (executable)
--- a/bucardo
+++ b/bucardo
@@ -3811,7 +3811,6 @@ sub add_sync {
     ## Inputs and aliases, database column name, flags, default
     my $validcols = qq{
         name                     name                 0                $item_name
-        synctype|type            synctype             0                null
         herd                     herd                 0                null
         dbs                      dbs                  0                null
         stayalive                stayalive            TF               null
@@ -3947,6 +3946,8 @@ sub add_sync {
     }
 
     ## Can be a database group, or a list of databases
+    ## We want to keep track of how many of each role we have
+    my %rolecount;
     if ($dbcols->{dbs} =~ /,/) {
         my @dbs = split /\s*,\s*/ => $dbcols->{dbs};
         my %db;
@@ -3968,6 +3969,7 @@ sub add_sync {
                 die "Invalid database type: must be source, target, or fullcopy (not $type)\n";
             }
             $db{$db} = $type;
+            $rolecount{$type}++;
         }
         ## Do any existing groups match this list exactly?
         my $newlist = join ',' => map { "$_=".$db{$_} } sort keys %db;
@@ -4023,11 +4025,32 @@ sub add_sync {
     } ## end of multiple databases specified
     else {
         my $dbg = $dbcols->{dbs};
-        if (! exists $global{dbgroup}{$dbg}) {
+        if (! exists $DBGROUP->{$dbg}) {
             warn "No such database group: $dbg\n";
             warn "To list all database groups, use: list dbgroups\n";
             exit 1;
         }
+        for my $db (values %{ $DBGROUP->{$dbg}{db} }) {
+            $rolecount{$db->{role}}++;
+        }
+    }
+
+    ## If this is a pure fullcopy sync, we want to turn stayalive and kidsalive off
+    if ($rolecount{'source'} == 1
+            and $rolecount{'fullcopy'}
+                and ! $rolecount{'target'}) {
+        if ($cols !~ /stayalive/) {
+            $vals->{stayalive} = 0;
+            $phs .= ',?';
+            my @cols = split /,/ => $cols;
+            $cols = join ',' => sort @cols, 'stayalive';
+        }
+        if ($cols !~ /kidsalive/) {
+            $vals->{kidsalive} = 0;
+            $phs .= ',?';
+            my @cols = split /,/ => $cols;
+            $cols = join ',' => sort @cols, 'kidsalive';
+        }
     }
 
     $dbh->commit();
@@ -4283,12 +4306,11 @@ sub list_syncs {
         my $maxdbline = 50;
 
         ## Show basic information
-        printf "Sync: %-*s  Herd: %-*s %s[%s]%s\n",
+        printf "Sync: %-*s  Herd: %-*s %s[%s]\n",
             $maxname, $name,
             $maxherd, $s->{herd}{name},
             $maxdbs > $maxdbline ? '' : "$s->{d}  ",
-            ucfirst $s->{status},
-            $s->{synctype} eq 'fullcopy' ? ' (fullcopy)' : '';
+            ucfirst $s->{status};
 
         ## Print the second line if needed
         if ($maxdbs > $maxdbline) {
index 32d2d51d03ecc1d9cd4d930d1d16edf6951a35a5..9ae888b0bfca27c782c2abc6e2636a1c9b7aa836 100644 (file)
@@ -389,7 +389,6 @@ CREATE TRIGGER herdcheck
 CREATE TABLE bucardo.sync (
   name               TEXT        NOT NULL UNIQUE,
                        CONSTRAINT sync_name_pk PRIMARY KEY (name),
-  synctype           TEXT        NOT NULL DEFAULT 'delta',
   herd               TEXT            NULL,
                        CONSTRAINT sync_herd_fk FOREIGN KEY (herd) REFERENCES bucardo.herd(name) ON UPDATE CASCADE ON DELETE RESTRICT,
   dbs                TEXT            NULL,
@@ -1224,7 +1223,7 @@ if ($role{source} < 1) {
 }
 
 ## Unless we are fullcopy, we must have PKs on each table
-my $is_fullcopy = $info->{synctype} eq 'fullcopy' ? 1 : 0;
+my $is_fullcopy = (! $role{target} and $role{fullcopy}) ? 1 : 0;
 if (! $is_fullcopy) {
     for my $schema (sort keys %goat) {
         for my $table (sort keys %{$goat{$schema}}) {
@@ -2434,7 +2433,7 @@ AS $bc$
     }
     else {
         my $old = $_TD->{old};
-        for my $x (qw(name source targetdb targetgroup synctype ping)) {
+        for my $x (qw(name source targetdb targetgroup ping)) {
             elog(DEBUG, "Checking on $x");
             if (! defined $old->{$x}) {
                 next if ! defined $new->{$x};