From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 6A90C1F4C8 for ; Tue, 19 Nov 2024 21:47:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1732052873; bh=oqYY36vhchyPhKB28wdZdbjQIFMCuceUcKm5bjOodns=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pRBYFFwUdiR3765zlGX3sSV4DVZZCYgMFDQjKHP+dgz033d4PsbY5wOEyQU+Plhu2 kiuZL7XFTPSM2FfPmH2/FZA16oX2hvxCvSoH6WsrOCoGjI58M/nysQguDNqEwCE6Ec a9K7JPcCm98J7ISkjh/ndop+EXXsnHQbRwJteokY= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 2/3] treewide: warn on SQLite `PRAGMA optimize' failure Date: Tue, 19 Nov 2024 21:47:51 +0000 Message-ID: <20241119214752.1883670-3-e@80x24.org> In-Reply-To: <20241119214752.1883670-1-e@80x24.org> References: <20241119214752.1883670-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: While `PRAGMA optimize' isn't a strict requirement for proper functionality anywhere, displaying the failure can help detect bigger problems in the future in case of failing hardware. --- lib/PublicInbox/LeiMailSync.pm | 5 +++-- lib/PublicInbox/Msgmap.pm | 9 +++++++++ lib/PublicInbox/OverIdx.pm | 1 + lib/PublicInbox/SearchIdx.pm | 4 +--- lib/PublicInbox/V2Writable.pm | 7 ++----- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index c498421c..d0f6d7b4 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -49,8 +49,9 @@ sub lms_write_prepare { ($_[0]->{dbh} //= dbh_new($_[0])); $_[0] } sub lms_pause { my ($self) = @_; $self->{fmap} = {}; - my $dbh = delete $self->{dbh}; - eval { $dbh->do('PRAGMA optimize') } if $dbh; + my $dbh = delete $self->{dbh} // return; + eval { $dbh->do('PRAGMA optimize') }; + warn 'W: optimize ', $dbh->sqlite_db_filename, ': ', $@ if $@; } sub create_tables { diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm index c4bc766d..3101fd7d 100644 --- a/lib/PublicInbox/Msgmap.pm +++ b/lib/PublicInbox/Msgmap.pm @@ -275,4 +275,13 @@ sub check_inodes { $self->{dbh} //= PublicInbox::Over::dbh_new($self, !$rw); } +sub mm_commit { + my ($self) = @_; + my $dbh = $self->{dbh} // return; + $dbh->commit; + eval { $dbh->do('PRAGMA optimize') }; + warn 'W: optimize ', $dbh->sqlite_db_filename, ': ', $@ if $@; + $dbh; +} + 1; diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm index 4f8533f7..879ae045 100644 --- a/lib/PublicInbox/OverIdx.pm +++ b/lib/PublicInbox/OverIdx.pm @@ -439,6 +439,7 @@ sub commit_lazy { delete $self->{txn} or return; $self->{dbh}->commit; eval { $self->{dbh}->do('PRAGMA optimize') }; + warn 'W: optimize ', $self->{dbh}->sqlite_db_filename, ': ', $@ if $@; } sub begin_lazy { diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 7829c7d4..48ba806a 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -860,9 +860,7 @@ sub v1_checkpoint ($$;$) { } } ${$sync->{max}} = $self->{batch_bytes}; - - $self->{mm}->{dbh}->commit; - eval { $self->{mm}->{dbh}->do('PRAGMA optimize') }; + $self->{mm}->mm_commit; my $xdb = $self->{xdb}; if ($newest && $xdb) { my $cur = $xdb->get_metadata('last_commit'); diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm index f7057359..721fbb4a 100644 --- a/lib/PublicInbox/V2Writable.pm +++ b/lib/PublicInbox/V2Writable.pm @@ -522,11 +522,8 @@ sub checkpoint ($;$) { $self->{im}->barrier if $self->{im}; my $shards = $self->{idx_shards}; if ($shards) { - my $dbh = $self->{mm}->{dbh} if $self->{mm}; - - # SQLite msgmap data is second in importance - $dbh->commit if $dbh; - eval { $dbh->do('PRAGMA optimize') }; + # SQLite msgmap is second in importance (not in eidx) + my $dbh = $self->{mm} ? $self->{mm}->mm_commit : undef; # SQLite overview is third $self->{oidx}->commit_lazy;