From: Eric Wong <e@80x24.org>
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 [thread overview]
Message-ID: <20210602100325.9231-1-e@80x24.org> (raw)
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
reply other threads:[~2021-06-02 10:03 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20210602100325.9231-1-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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/public-inbox.git
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).