chiark / gitweb /
Infra: Improve db retry handling
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 23 Jun 2015 12:26:43 +0000 (13:26 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Tue, 23 Jun 2015 13:14:10 +0000 (14:14 +0100)
Use theh new poldb_setup hook to (a) set up HandleError and (b) run
the DGIT_RPD_TEST_DBLOOP_HOOK.

This is needed because the PRAGMA in poldb_setup can cause a
SQLITE_BUSY error in newer sqlite3, and we want both the HandleError
setup and the hook (which sets a timeout, amongst other things) to
occur before sqlite3 tries to take its lock.

infra/dgit-repos-policy-debian

index 4af7551c512014b0224f348ac44603415cc0b48c..b21f797643a76ea27e19c93e6202c103ec644c21 100755 (executable)
@@ -461,17 +461,18 @@ my @orgargv = @ARGV;
 for (;;) {
     @ARGV = @orgargv;
     eval {
-       poldb_setup(poldb_path($repos));
-       $stderr = '';
+       poldb_setup(poldb_path($repos), sub {
+           $poldbh->{HandleError} = sub {
+               return 0 unless $poldbh->err == 5; # SQLITE_BUSY, not in .pm :-(
+               die bless { }, $db_busy_exception;
+           };
 
-       eval ($ENV{'DGIT_RPD_TEST_DBLOOP_HOOK'}//'');
-       die $@ if length $@;
-       # used by tests/tests/debpolicy-dbretry
+           eval ($ENV{'DGIT_RPD_TEST_DBLOOP_HOOK'}//'');
+           die $@ if length $@;
+           # used by tests/tests/debpolicy-dbretry
+        });
 
-       $poldbh->{HandleError} = sub {
-           return 0 unless $poldbh->err == 5; # SQLITE_BUSY, not in .pm :-(
-           die bless { }, $db_busy_exception;
-       };
+       $stderr = '';
 
        $rcode = $fn->();
        die unless defined $rcode;