user/dev discussion of public-inbox itself
 help / color / Atom feed
* [PATCH] msgmap: fix atfork_* callbacks
@ 2020-07-18  6:36 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2020-07-18  6:36 UTC (permalink / raw)
  To: meta

Noticed while reindexing a largish v2 inbox in parallel on an
SSD which required checkpointing and respawning shard workers.

Fixes: f06e84220e5566e7 ("over+msgmap: do not store filename after DBI->connect")
---
 lib/PublicInbox/Msgmap.pm | 17 ++++++++---------
 t/msgmap.t                |  6 ++++++
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/lib/PublicInbox/Msgmap.pm b/lib/PublicInbox/Msgmap.pm
index 38ec7858..9d2ef0dc 100644
--- a/lib/PublicInbox/Msgmap.pm
+++ b/lib/PublicInbox/Msgmap.pm
@@ -238,22 +238,21 @@ sub DESTROY {
 
 sub atfork_parent {
 	my ($self) = @_;
-	$self->{pid} or die "not a temporary clone\n";
-	my $dbh = $self->{dbh} and die "tmp_clone dbh not prepared for parent";
-	$self->{filename} = $dbh->sqlite_db_filename;
-	$dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, 1);
+	$self->{pid} or die 'BUG: not a temporary clone';
+	$self->{dbh} and die 'BUG: tmp_clone dbh not prepared for parent';
+	defined($self->{filename}) or die 'BUG: {filename} not defined';
+	my $dbh = $self->{dbh} = PublicInbox::Over::dbh_new($self, 1);
 	$dbh->do('PRAGMA synchronous = OFF');
 }
 
 sub atfork_prepare {
 	my ($self) = @_;
-	$self->{pid} or die "not a temporary clone\n";
-	$self->{pid} == $$ or
-		die "BUG: atfork_prepare not called from $self->{pid}\n";
-	my $dbh = $self->{dbh} or die "temporary clone not open\n";
+	my $pid = $self->{pid} or die 'BUG: not a temporary clone';
+	$pid == $$ or die "BUG: atfork_prepare not called by $pid";
+	my $dbh = $self->{dbh} or die 'BUG: temporary clone not open';
 
 	# must clobber prepared statements
-	%$self = (filename => $dbh->sqlite_db_filename, pid => $$);
+	%$self = (filename => $dbh->sqlite_db_filename, pid => $pid);
 }
 
 sub skip_artnum {
diff --git a/t/msgmap.t b/t/msgmap.t
index f78070cc..1d7d1e87 100644
--- a/t/msgmap.t
+++ b/t/msgmap.t
@@ -64,4 +64,10 @@ my $tmp = $d->tmp_clone;
 is_deeply([$d->minmax], [$tmp->minmax], 'Cloned temporary DB matches');
 ok($tmp->mid_delete('spam@2'), 'temporary DB is writable');
 
+is(eval {
+	$tmp->atfork_prepare;
+	$tmp->atfork_parent;
+	'ok'
+}, 'ok', 'atfork_* work on tmp_clone');
+
 done_testing();

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

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-18  6:36 [PATCH] msgmap: fix atfork_* callbacks Eric Wong

user/dev discussion of public-inbox itself

Archives are clonable:
	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

Example config snippet for mirrors

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.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/

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