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://git.ipfire.org/?a=commitdiff_plain;h=2e8256ba1ced49a686bf5ff1c97375f8ccb30d4a;p=thirdparty%2Fpublic-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 554883766..5c83fd800 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 f5d09cc14..77df0fb41 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 {