diff options
author | Eric Wong <e@80x24.org> | 2021-01-31 22:28:24 -1000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-02-01 11:38:17 +0000 |
commit | 2e8256ba1ced49a686bf5ff1c97375f8ccb30d4a (patch) | |
tree | 367f885570f711af15b59f324f553f546249ccff /lib/PublicInbox/SharedKV.pm | |
parent | 7d3917a9722e445ecb040c2c01e9665123ad5b6c (diff) | |
download | public-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.pm | 10 |
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 { |