]> Sergey Matveev's repositories - public-inbox.git/commitdiff
msgmap: fix atfork_* callbacks
authorEric Wong <e@yhbt.net>
Sat, 18 Jul 2020 06:36:32 +0000 (06:36 +0000)
committerEric Wong <e@yhbt.net>
Sat, 18 Jul 2020 23:58:08 +0000 (23:58 +0000)
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
t/msgmap.t

index 38ec785820bc3eadfe457bc803e109f106bd9d90..9d2ef0dc5455f2c239ad54d283fe24a272d23bdc 100644 (file)
@@ -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 {
index f78070cc959d47db729dbd753e6534550db318aa..1d7d1e87adbb7bbe3316c9ad86bcbddc920ec24f 100644 (file)
@@ -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();