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/LeiForgetMailSync.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/PublicInbox/LeiForgetMailSync.pm') diff --git a/lib/PublicInbox/LeiForgetMailSync.pm b/lib/PublicInbox/LeiForgetMailSync.pm index 940ca1b6..2b4e58a9 100644 --- a/lib/PublicInbox/LeiForgetMailSync.pm +++ b/lib/PublicInbox/LeiForgetMailSync.pm @@ -16,12 +16,12 @@ sub lei_forget_mail_sync { my ($lei, @folders) = @_; my $lms = $lei->lms or return; my $sto = $lei->_lei_store or return; # may disappear due to race - $sto->write_prepare; + $sto->write_prepare($lei); my $err = $lms->arg2folder($lei, \@folders); $lei->qerr(@{$err->{qerr}}) if $err->{qerr}; return $lei->fail($err->{fail}) if $err->{fail}; $sto->ipc_do('lms_forget_folders', @folders); - my $wait = $sto->ipc_do('done'); + $lei->sto_done_request; } *_complete_forget_mail_sync = \&PublicInbox::LeiExportKw::_complete_export_kw; -- cgit v1.2.3-24-ge0c7