about summary refs log tree commit homepage
path: root/lib/PublicInbox/SharedKV.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-01-31 22:28:24 -1000
committerEric Wong <e@80x24.org>2021-02-01 11:38:17 +0000
commit2e8256ba1ced49a686bf5ff1c97375f8ccb30d4a (patch)
tree367f885570f711af15b59f324f553f546249ccff /lib/PublicInbox/SharedKV.pm
parent7d3917a9722e445ecb040c2c01e9665123ad5b6c (diff)
downloadpublic-inbox-2e8256ba1ced49a686bf5ff1c97375f8ccb30d4a.tar.gz
It may be possible for updates or changes to be uncommitted
until disconnect, so we'll use flock() as we do elsewhere
to avoid the polling retry behavior of SQLite.

We also need to clear CachedKids before disconnecting to
to avoid warnings like:

  ->disconnect invalidates 1 active statement handle
  (either destroy statement handles or call finish on
  them before disconnecting)
Diffstat (limited to 'lib/PublicInbox/SharedKV.pm')
-rw-r--r--lib/PublicInbox/SharedKV.pm10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/PublicInbox/SharedKV.pm b/lib/PublicInbox/SharedKV.pm
index f5d09cc1..77df0fb4 100644
--- a/lib/PublicInbox/SharedKV.pm
+++ b/lib/PublicInbox/SharedKV.pm
@@ -143,9 +143,17 @@ SELECT COUNT(k) FROM kv
         $sth->fetchrow_array;
 }
 
+sub dbh_release {
+        my ($self, $lock) = @_;
+        my $dbh = delete $self->{dbh} or return;
+        $lock //= $self->lock_for_scope; # may be needed for WAL
+        %{$dbh->{CachedKids}} = (); # cleanup prepare_cached
+        $dbh->disconnect;
+}
+
 sub DESTROY {
         my ($self) = @_;
-        delete $self->{dbh};
+        dbh_release($self);
         my $dir = delete $self->{"tmp$$.$self"} or return;
         my $tries = 0;
         do {