]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
treewide: warn on SQLite `PRAGMA optimize' failure
authorEric Wong <e@80x24.org>
Tue, 19 Nov 2024 21:47:51 +0000 (21:47 +0000)
committerEric Wong <e@80x24.org>
Wed, 20 Nov 2024 17:39:47 +0000 (17:39 +0000)
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
lib/PublicInbox/Msgmap.pm
lib/PublicInbox/OverIdx.pm
lib/PublicInbox/SearchIdx.pm
lib/PublicInbox/V2Writable.pm

index c498421c9d34b49240f1c0574d67d2bcbb7c98aa..d0f6d7b4f72b43b602607c5d4c2d07f9aae231dc 100644 (file)
@@ -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 {
index c4bc766d2395387ca49d99844ab53c450849b9f2..3101fd7dc86c75d99a4b080717953ef832eba71f 100644 (file)
@@ -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;
index 4f8533f7284b6284ead1422f100cba61b0329b2c..879ae04537ce2a89b58cb20f692fe10685f3a528 100644 (file)
@@ -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 {
index 7829c7d4721c629499b896ef4b12393c10acafa3..48ba806a68dc1458aff3d2242e5df20e33c18e37 100644 (file)
@@ -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');
index f705735959c0017060b8a043a0501bc6b45e50e8..721fbb4a0aea513d34adac135832b46585052752 100644 (file)
@@ -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;