Listen for autokicks on sources for the sync, not all sources.
authorDavid E. Wheeler <david@justatheory.com>
Wed, 24 Jul 2013 17:45:50 +0000 (19:45 +0200)
committerDavid E. Wheeler <david@justatheory.com>
Wed, 24 Jul 2013 17:45:50 +0000 (19:45 +0200)
I had a database in two dbgroups (and syncs), once as a target and once as a
source. On startup, `validate_sync()` was processing the sync where it was a
target, first, and that was the role saved for it in `$self->{sdb}`. Then,
when `validate_sync()` iterated over `$self->{sdb}`, it thought it was a role,
and so did not have the MCP listen for kicks.

Not only that, but sources from other, previously-validated syncs were
unnecessarily listening for kicks!

So change the code to iterate over the list of DBs for the current call to
`validate_sync()`, not all dbs for all syncs, when figuring out whereq to listen
to for kicks.

Note that the use of the same db object in multiple db groups and syncs *may*
cause issues in other places. It would be smart to audit all code that checks
the value in `{role}` for each hash in `$self->{sdb}` and figure out if it is
appropriate. Since the same db can have different roles in differnt syncs, it
might make sense to record all of its roles and to check all of them, rather
than just rely on the first role found.

Bucardo.pm

index ee20796572865373078c0ec407c41e528dff4338..839dc03f9e46e3ffbeb635d31a0bef79048c4806 100644 (file)
@@ -6340,12 +6340,13 @@ sub validate_sync {
     ## If autokick, listen for a triggerkick on all source databases
     if ($s->{autokick}) {
         my $l = "kick_sync_$syncname";
-        for my $dbname (sort keys %{ $self->{sdb} }) {
-            $x = $self->{sdb}{$dbname};
+        for my $dbname (sort keys %{ $s->{db} }) {
+            $x = $s->{db}{$dbname};
+            $self->glog("Listen for $l on $dbname ($x->{role})");
             next if $x->{role} ne 'source';
-
-            $self->db_listen($x->{dbh}, $l, $dbname, 0);
-            $x->{dbh}->commit();
+            my $dbh = $self->{sdb}{$dbname}{dbh};
+            $self->db_listen($dbh, $l, $dbname, 0);
+            $dbh->commit;
         }
     }