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-ASN: 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 17CA81F8C7 for ; Thu, 2 Sep 2021 10:17:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 1/3] lei_mail_sync: do not use transactions Date: Thu, 2 Sep 2021 10:17:56 +0000 Message-Id: <20210902101758.18715-2-e@80x24.org> In-Reply-To: <20210902101758.18715-1-e@80x24.org> References: <20210902101758.18715-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: For lei-index to work in parallel with MUA access and upcoming inotify-based updates, mail_sync.sqlite3 needs to always be up-to-date to read-only worker processes (ahead of everything else). So rely on the default auto-commit behavior and hope SQLite WAL can reduce some of the overheads involved with writes. --- lib/PublicInbox/LeiMailSync.pm | 14 +------------- lib/PublicInbox/LeiStore.pm | 10 +++------- t/lei_mail_sync.t | 18 ++++++------------ 3 files changed, 10 insertions(+), 32 deletions(-) diff --git a/lib/PublicInbox/LeiMailSync.pm b/lib/PublicInbox/LeiMailSync.pm index f8834a27..5a10c127 100644 --- a/lib/PublicInbox/LeiMailSync.pm +++ b/lib/PublicInbox/LeiMailSync.pm @@ -32,9 +32,7 @@ sub new { bless { filename => $f, fmap => {} }, $cls; } -sub lms_commit { delete($_[0]->{dbh})->commit } - -sub lms_begin { ($_[0]->{dbh} //= dbh_new($_[0], 1))->begin_work }; +sub lms_write_prepare { ($_[0]->{dbh} //= dbh_new($_[0], 1)) }; sub create_tables { my ($dbh) = @_; @@ -468,14 +466,4 @@ sub imap_oid { $oidbin ? unpack('H*', $oidbin) : undef; } -# FIXED? something with "lei " is causing uncommitted transaction -# TODO: remove soon -sub DESTROY { - my ($self) = @_; - my $dbh = delete($self->{dbh}) or return; - return if $dbh->{ReadOnly}; - undef $dbh; - warn "BUG $$ $0 $self {dbh} OPEN ppid=".getppid.' '.Carp::longmess(); -} - 1; diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index ab39043e..6c557d99 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -202,7 +202,7 @@ sub _lms_rw ($) { require PublicInbox::LeiMailSync; my $f = "$self->{priv_eidx}->{topdir}/mail_sync.sqlite3"; my $lms = PublicInbox::LeiMailSync->new($f); - $lms->lms_begin; + $lms->lms_write_prepare; $lms; }; } @@ -450,9 +450,7 @@ sub checkpoint { if (my $im = $self->{im}) { $wait ? $im->barrier : $im->checkpoint; } - if (my $lms = delete $self->{lms}) { - $lms->lms_commit; - } + delete $self->{lms}; $self->{priv_eidx}->checkpoint($wait); } @@ -481,9 +479,7 @@ sub done { warn $err; } } - if (my $lms = delete $self->{lms}) { - $lms->lms_commit; - } + delete $self->{lms}; $self->{priv_eidx}->done; # V2Writable::done xchg_stderr($self); die $err if $err; diff --git a/t/lei_mail_sync.t b/t/lei_mail_sync.t index 5daa49cd..4439b818 100644 --- a/t/lei_mail_sync.t +++ b/t/lei_mail_sync.t @@ -9,17 +9,15 @@ require_ok 'PublicInbox::LeiMailSync'; my ($dir, $for_destroy) = tmpdir(); my $lms = PublicInbox::LeiMailSync->new("$dir/t.sqlite3"); -$lms->lms_begin; -$lms->lms_commit; +$lms->lms_write_prepare; my $ro = PublicInbox::LeiMailSync->new("$dir/t.sqlite3"); is_deeply([$ro->folders], [], 'no folders, yet'); my $imap = 'imaps://bob@[::1]/INBOX;UIDVALIDITY=9'; -$lms->lms_begin; +$lms->lms_write_prepare; my $deadbeef = "\xde\xad\xbe\xef"; is($lms->set_src($deadbeef, $imap, 1), 1, 'set IMAP once'); ok($lms->set_src($deadbeef, $imap, 1) == 0, 'set IMAP idempotently'); -$lms->lms_commit; is_deeply([$ro->folders], [$imap], 'IMAP folder added'); is_deeply([$ro->folders($imap)], [$imap], 'IMAP folder with full GLOB'); is_deeply([$ro->folders('imaps://bob@[::1]/INBOX')], [$imap], @@ -30,24 +28,21 @@ is_deeply($ro->locations_for($deadbeef), my $maildir = 'maildir:/home/user/md'; my $fname = 'foo:2,S'; -$lms->lms_begin; +$lms->lms_write_prepare; ok($lms->set_src($deadbeef, $maildir, \$fname), 'set Maildir once'); ok($lms->set_src($deadbeef, $maildir, \$fname) == 0, 'set Maildir again'); -$lms->lms_commit; is_deeply($ro->locations_for($deadbeef), { $imap => [ 1 ], $maildir => [ $fname ] }, 'locations_for w/ maildir + imap'); if ('mess things up pretend old bug') { - $lms->lms_begin; + $lms->lms_write_prepare; $lms->{dbh}->do('UPDATE folders SET loc = ? WHERE loc = ?', undef, "$maildir/", $maildir); ok(delete $lms->{fmap}, 'clear folder map'); - $lms->lms_commit; - $lms->lms_begin; + $lms->lms_write_prepare; ok($lms->set_src($deadbeef, $maildir, \$fname), 'set Maildir once'); - $lms->lms_commit; }; is_deeply([sort($ro->folders)], [$imap, $maildir], 'both folders shown'); @@ -70,12 +65,11 @@ is_deeply($ro->location_stats($maildir), { 'name.count' => 1 }, is_deeply($ro->location_stats($imap), { 'uid.count' => 1, 'uid.max' => 1, 'uid.min' => 1 }, 'IMAP location stats'); -$lms->lms_begin; +$lms->lms_write_prepare; is($lms->clear_src($imap, 1), 1, 'clear_src on IMAP'); is($lms->clear_src($maildir, \$fname), 1, 'clear_src on Maildir'); ok($lms->clear_src($imap, 1) == 0, 'clear_src again on IMAP'); ok($lms->clear_src($maildir, \$fname) == 0, 'clear_src again on Maildir'); -$lms->lms_commit; is_deeply($ro->location_stats($maildir), {}, 'nothing left'); done_testing;