From 5a27f82749d723625848c8d1cf216a0f4de73597 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 24 Aug 2021 13:06:39 +0000 Subject: lei: non-blocking lei/store->done in lei-daemon This allows client sockets to wait for "done" commits to lei/store while the daemon reacts asynchronously. The goal of this change is to keep the script/lei client alive until lei/store commits changes to the filesystem, but without blocking the lei-daemon event loop. It depends on Perl refcounting to close the socket. This change also highlighted our over-use of "done" requests to lei/store processes, which is now corrected so we only issue it on collective socket EOF rather than upon reaping every single worker. This also fixes "lei forget-mail-sync" when it is the initial command. This took several iterations and much debugging to arrive at the current implementation: 1. The initial iteration of this change utilized socket passing from lei-daemon to lei/store, which necessitated switching from faster pipes to slower Unix sockets. 2. The second iteration switched to registering notification sockets independently of "done" requests, but that could lead to early wakeups when "done" was requested by other workers. This appeared to work most of the time, but suffered races under high load which were difficult to track down. Finally, this iteration passes the stringified socket GLOB ref to lei/store which is echoed back to lei-daemon upon completion of that particular "done" request. --- lib/PublicInbox/LeiNoteEvent.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/LeiNoteEvent.pm') diff --git a/lib/PublicInbox/LeiNoteEvent.pm b/lib/PublicInbox/LeiNoteEvent.pm index 1cd15296..6a40ba39 100644 --- a/lib/PublicInbox/LeiNoteEvent.pm +++ b/lib/PublicInbox/LeiNoteEvent.pm @@ -15,7 +15,7 @@ sub flush_lei ($) { if (my $lne = delete $lei->{cfg}->{-lei_note_event}) { $lne->wq_close(1, undef, $lei); # runs _lei_wq_eof; } elsif ($lei->{sto}) { # lms_clear_src calls only: - my $wait = $lei->{sto}->ipc_do('done'); + $lei->sto_done_request; } } @@ -117,7 +117,7 @@ sub lne_done_wait { sub _lei_wq_eof { # EOF callback for main lei daemon my ($lei) = @_; my $lne = delete $lei->{lne} or return $lei->fail; - my $wait = $lei->{sto}->ipc_do('done'); + $lei->sto_done_request; $lne->wq_wait_old(\&lne_done_wait, $lei); } -- cgit v1.2.3-24-ge0c7