From: Eric Wong Date: Mon, 1 Feb 2021 08:28:24 +0000 (-1000) Subject: sharedkv: lock and explicitly disconnect {dbh} X-Git-Tag: v1.7.0~1257 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=2e8256ba1ced49a686bf5ff1c97375f8ccb30d4a;p=public-inbox.git sharedkv: lock and explicitly disconnect {dbh} 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) --- diff --git a/lib/PublicInbox/LeiDedupe.pm b/lib/PublicInbox/LeiDedupe.pm index 55488376..5c83fd80 100644 --- a/lib/PublicInbox/LeiDedupe.pm +++ b/lib/PublicInbox/LeiDedupe.pm @@ -126,6 +126,7 @@ sub prepare_dedupe { sub pause_dedupe { my ($self) = @_; my $skv = $self->[0]; + $skv->dbh_release; delete($skv->{dbh}) if $skv; } 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 {