user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [PATCH] lei export-kw: do not write directly to mail_sync.sqlite3
@ 2021-06-02 10:03 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2021-06-02 10:03 UTC (permalink / raw)
  To: meta

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-02 10:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-02 10:03 [PATCH] lei export-kw: do not write directly to mail_sync.sqlite3 Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://7fh6tueqddpjyxjmgtdiueylzoqt6pt7hec3pukyptlmohoowvhde4yd.onion/inbox.comp.mail.public-inbox.meta
	nntp://ie5yzdi7fg72h7s4sdcztq5evakq23rdt33mfyfcddc5u3ndnw24ogqd.onion/inbox.comp.mail.public-inbox.meta
	nntp://4uok3hntl7oi7b4uf4rtfwefqeexfzil2w6kgk2jn5z2f764irre7byd.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for project(s) associated with this inbox:

	https://80x24.org/public-inbox.git

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git