From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20241119214752.1883670-3-e@80x24.org> (raw)
In-Reply-To: <20241119214752.1883670-1-e@80x24.org>
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;
next prev parent reply other threads:[~2024-11-19 21:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-19 21:47 [PATCH 0/3] write-related fixes Eric Wong
2024-11-19 21:47 ` [PATCH 1/3] v2writable: use DS and import now() sub Eric Wong
2024-11-19 21:47 ` Eric Wong [this message]
2024-11-19 21:47 ` [PATCH 3/3] v2writable: done: force synchronous awaitpid Eric Wong
2024-11-20 19:06 ` Eric Wong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241119214752.1883670-3-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).