Try harder to collect and emit errors on validation failures.
authorDavid E. Wheeler <david@justatheory.com>
Wed, 16 Oct 2013 20:39:09 +0000 (13:39 -0700)
committerDavid E. Wheeler <david@justatheory.com>
Wed, 16 Oct 2013 20:39:09 +0000 (13:39 -0700)
There's no need to wait for a NOTIFY, as `validate_sync()` runs synchronously.
So just check the return value for errors, and use excpetion handling to catch
other kinds of errors. This allows us to catch and emit all errors and also
allow execution to finish validating all syncs (should it be validating
multiples). Closes #65.

bucardo

diff --git a/bucardo b/bucardo
index 5ef59628b458110a763adaf45eca8ff34e1a0e07..94c30328ed1b871cfd07ec999c31f90688e1c1f6 100755 (executable)
--- a/bucardo
+++ b/bucardo
@@ -1026,26 +1026,38 @@ sub validate {
 
     ## Loop through and validate each in turn,
     ## waiting for a positive response from the MCP
+    my $exitval = 0;
     for my $name (@synclist) {
 
-        printf "Validating sync $name%s",
+        printf "Validating sync $name %s ",
             '.' x ($maxsize - length $name);
 
-        my $done = "bucardo_validated_sync_$name";
-        $dbh->do(qq{LISTEN "$done"});
+        my ($evalok, $success);
+        eval {
+            my ($msg) = $dbh->selectrow_array(
+                'SELECT validate_sync(?)',
+                undef, $name
+            );
+            $dbh->commit;
+            if ($msg eq 'MODIFY') {
+                $success = 1;
+            } else {
+                warn "$msg\n";
+                $exitval++;
+            }
+            $evalok = 1;
+        };
 
-        $SQL = 'SELECT validate_sync(?)';
-        $sth = $dbh->prepare($SQL);
-        $sth->execute($name);
-        $dbh->commit();
+        if ($evalok) {
+            print "OK\n" if $success;
+        } else {
+            warn $dbh->errstr || $@;
+            $exitval++;
+        }
 
-        ## Wait a bit, then hang out until the MCP confirms the validation
-        sleep 0.1;
-        wait_for_notice($dbh, $done);
-        print "DONE!\n";
     }
 
-    exit 0;
+    exit $exitval;
 
 } ## end of validate
 
@@ -10918,6 +10930,9 @@ C<STDOUT>. The supported types include:
 Validates one or more syncs. Use the keyword "all" to validate all syncs, or
 specify one or more syncs to validate.
 
+Note that this command executes a subset of all the validation done when a
+sync is started or activated.
+
 =head2 purge
 
   bucardo purge all|<table> [<table>...]