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 11FD31F5AE for ; Wed, 2 Jun 2021 10:03:26 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH] lei export-kw: do not write directly to mail_sync.sqlite3 Date: Wed, 2 Jun 2021 10:03:25 +0000 Message-Id: <20210602100325.9231-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Only the lei/store process should be writing to files/DBs in lei/store. --- lib/PublicInbox/LeiExportKw.pm | 21 +++++++++++---------- lib/PublicInbox/LeiStore.pm | 23 +++++++++++++++++++---- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/lib/PublicInbox/LeiExportKw.pm b/lib/PublicInbox/LeiExportKw.pm index 92c3aa43..b31b065f 100644 --- a/lib/PublicInbox/LeiExportKw.pm +++ b/lib/PublicInbox/LeiExportKw.pm @@ -28,6 +28,7 @@ sub export_kw_md { # LeiMailSync->each_src callback PublicInbox::LeiToMail::kw2suffix([keys %$sto_kw], @$unknown); my $dst = "$mdir/cur/$bn"; my @fail; + my $lei = $self->{lei}; for my $d (@try) { my $src = "$mdir/$d/$$id"; next if $src eq $dst; @@ -39,15 +40,15 @@ sub export_kw_md { # LeiMailSync->each_src callback # unlink(2) may ENOENT from parallel invocation, # ignore it, but not other serious errors if (!unlink($src) and $! != ENOENT) { - $self->{lei}->child_error(1, - "E: unlink($src): $!"); + $lei->child_error(1, "E: unlink($src): $!"); } - $self->{lms}->mv_src("maildir:$mdir", - $oidbin, $id, $bn) or die; + $lei->{sto}->ipc_do('lms_mv_src', "maildir:$mdir", + $oidbin, $id, $bn); return; # success anyways if link(2) worked } if ($! == ENOENT && !-e $src) { # some other process moved it - $self->{lms}->clear_src("maildir:$mdir", $id); + $lei->{sto}->ipc_do('lms_clear_src', + "maildir:$mdir", $id); next; } push @fail, $src if $! != EEXIST; @@ -56,7 +57,7 @@ sub export_kw_md { # LeiMailSync->each_src callback # both tries failed my $e = $!; my $orig = '['.join('|', @fail).']'; - $self->{lei}->child_error(1, "link($orig, $dst) ($oidhex): $e"); + $lei->child_error(1, "link($orig, $dst) ($oidhex): $e"); } sub export_kw_imap { # LeiMailSync->each_src callback @@ -69,8 +70,7 @@ sub export_kw_imap { # LeiMailSync->each_src callback # overrides PublicInbox::LeiInput::input_path_url sub input_path_url { my ($self, $input, @args) = @_; - my $lms = $self->{lms} //= $self->{lse}->lms; - $lms->lms_begin; + my $lms = $self->{-lms_ro} //= $self->{lse}->lms; if ($input =~ /\Amaildir:(.+)/i) { my $mdir = $1; require PublicInbox::LeiToMail; # kw2suffix @@ -81,7 +81,7 @@ sub input_path_url { $lms->each_src($$uri, \&export_kw_imap, $self, $mic); $mic->expunge; } else { die "BUG: $input not supported" } - $lms->lms_commit; + my $wait = $self->{lei}->{sto}->ipc_do('done'); } sub lei_export_kw { @@ -151,8 +151,9 @@ EOM $self->{imap_mod_kw} = $net->can($self->{-merge_kw} ? 'imap_add_kw' : 'imap_set_kw'); } - undef $lms; + undef $lms; # for fork my $ops = {}; + $sto->write_prepare($lei); $lei->{auth}->op_merge($ops, $self) if $lei->{auth}; $self->{-wq_nr_workers} = $j // 1; # locked (my $op_c, $ops) = $lei->workers_start($self, $j, $ops); diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm index 6888afb4..821782b9 100644 --- a/lib/PublicInbox/LeiStore.pm +++ b/lib/PublicInbox/LeiStore.pm @@ -193,15 +193,30 @@ sub remove_eml_vmd { # remove just the VMD \@docids; } -sub set_sync_info { - my ($self, $oidhex, $folder, $id) = @_; - ($self->{lms} //= do { +sub _lms_rw ($) { + my ($self) = @_; + $self->{lms} //= do { require PublicInbox::LeiMailSync; my $f = "$self->{priv_eidx}->{topdir}/mail_sync.sqlite3"; my $lms = PublicInbox::LeiMailSync->new($f); $lms->lms_begin; $lms; - })->set_src($oidhex, $folder, $id); + }; +} + +sub lms_clear_src { + my ($self, $folder, $id) = @_; + _lms_rw($self)->clear_src($folder, $id); +} + +sub lms_mv_src { + my ($self, $folder, $oidbin, $id, $newbn) = @_; + _lms_rw($self)->mv_src($folder, $oidbin, $id, $newbn); +} + +sub set_sync_info { + my ($self, $oidhex, $folder, $id) = @_; + _lms_rw($self)->set_src($oidhex, $folder, $id); } sub _remove_if_local { # git->cat_async arg