]> Sergey Matveev's repositories - public-inbox.git/commitdiff
sharedkv: lock and explicitly disconnect {dbh}
authorEric Wong <e@80x24.org>
Mon, 1 Feb 2021 08:28:24 +0000 (22:28 -1000)
committerEric Wong <e@80x24.org>
Mon, 1 Feb 2021 11:38:17 +0000 (11:38 +0000)
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)

lib/PublicInbox/LeiDedupe.pm
lib/PublicInbox/SharedKV.pm

index 554883766c02ecf18fa06467380ac49bd7ea8623..5c83fd8007ce55438f989ebd3a2bc835d05b7373 100644 (file)
@@ -126,6 +126,7 @@ sub prepare_dedupe {
 sub pause_dedupe {
        my ($self) = @_;
        my $skv = $self->[0];
+       $skv->dbh_release;
        delete($skv->{dbh}) if $skv;
 }
 
index f5d09cc14dcfe3022539be322b53c77daad93701..77df0fb41bd090601662e18b149702f0f427fafe 100644 (file)
@@ -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 {