From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 079FB2007D for ; Mon, 1 Feb 2021 08:28:35 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 12/21] sharedkv: lock and explicitly disconnect {dbh} Date: Sun, 31 Jan 2021 22:28:24 -1000 Message-Id: <20210201082833.3293-13-e@80x24.org> In-Reply-To: <20210201082833.3293-1-e@80x24.org> References: <20210201082833.3293-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 | 1 + lib/PublicInbox/SharedKV.pm | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) 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 {