## 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
}
## 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;
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;
} ## 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();
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) {
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,
}
## 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}}) {
}
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};