]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
lei: simplify startq/au_done wakeup notifications
authorEric Wong <e@80x24.org>
Thu, 19 Oct 2023 01:14:31 +0000 (01:14 +0000)
committerEric Wong <e@80x24.org>
Thu, 19 Oct 2023 07:33:21 +0000 (07:33 +0000)
We only need to write one byte at MUA start instead of a byte
for every LeiXSearch worker.  Also, make sure it succeeds by
enabling autodie for syswrite.

When reading, we can rely on `:perlio' layer `read' semantics
to retry on EINTR to avoid looping and other error checking.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiXSearch.pm

index 3ccdd4f7468e78e60a4f52bb13fc42eff42eb88b..56e4c001f17c9a2f46429e2e03f1a8b503af1ec8 100644 (file)
@@ -9,7 +9,7 @@ package PublicInbox::LEI;
 use v5.12;
 use parent qw(PublicInbox::DS PublicInbox::LeiExternal
        PublicInbox::LeiQuery);
-use autodie qw(bind chdir fork open socket socketpair unlink);
+use autodie qw(bind chdir fork open socket socketpair syswrite unlink);
 use Getopt::Long ();
 use Socket qw(AF_UNIX SOCK_SEQPACKET pack_sockaddr_un);
 use Errno qw(EPIPE EAGAIN ECONNREFUSED ENOENT ECONNRESET);
@@ -1031,9 +1031,10 @@ sub start_mua {
                $io->[0] = $self->{1} if $self->{opt}->{stdin} && -t $self->{1};
                send_exec_cmd($self, $io, \@cmd, {});
        }
-       if ($self->{lxs} && $self->{au_done}) { # kick wait_startq
-               syswrite($self->{au_done}, 'q' x ($self->{lxs}->{jobs} // 0));
-       }
+
+       # kick wait_startq:
+       syswrite($self->{au_done}, 'q') if $self->{lxs} && $self->{au_done};
+
        return unless -t $self->{2}; # XXX how to determine non-TUI MUAs?
        $self->{opt}->{quiet} = 1;
        delete $self->{-progress};
index 25b66b3b0cc05332b39ae347a8882cc971bf5ee6..241b9dabcd89a83f053bae581cf639d28a2373bc 100644 (file)
@@ -122,26 +122,16 @@ sub _mset_more ($$) {
        $size >= $mo->{limit} && (($mo->{offset} += $size) < $mo->{total});
 }
 
-# $startq will EOF when do_augment is done augmenting and allow
+# $startq will see `q' in do_post_augment -> start_mua if spawning MUA.
+# Otherwise $startq will EOF when do_augment is done augmenting and allow
 # query_combined_mset and query_thread_mset to proceed.
 sub wait_startq ($) {
        my ($lei) = @_;
-       my $startq = delete $lei->{startq} or return;
-       while (1) {
-               my $n = sysread($startq, my $do_augment_done, 1);
-               if (defined $n) {
-                       return if $n == 0; # no MUA
-                       if ($do_augment_done eq 'q') {
-                               $lei->{opt}->{quiet} = 1;
-                               delete $lei->{opt}->{verbose};
-                               delete $lei->{-progress};
-                       } else {
-                               die "BUG: do_augment_done=`$do_augment_done'";
-                       }
-                       return;
-               }
-               die "wait_startq: $!" unless $!{EINTR};
-       }
+       read(delete($lei->{startq}) // return, my $buf, 1) or return; # EOF
+       die "BUG: wrote `$buf' to au_done" if $buf ne 'q';
+       $lei->{opt}->{quiet} = 1;
+       delete $lei->{opt}->{verbose};
+       delete $lei->{-progress};
 }
 
 sub mset_progress {
@@ -451,10 +441,10 @@ sub do_post_augment {
                $lei->fail("$err");
        }
        if (!$err && delete $lei->{early_mua}) { # non-augment case
-               eval { $lei->start_mua };
+               eval { $lei->start_mua }; # may trigger wait_startq
                $lei->fail($@) if $@;
        }
-       close(delete $lei->{au_done}); # triggers wait_startq in lei_xsearch
+       close(delete $lei->{au_done}); # trigger wait_startq if start_mua didn't
 }
 
 sub incr_post_augment { # called whenever an l2m shard finishes augment