]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: simplify sto_done_request
authorEric Wong <e@80x24.org>
Sun, 19 Sep 2021 12:50:23 +0000 (12:50 +0000)
committerEric Wong <e@80x24.org>
Sun, 19 Sep 2021 19:52:46 +0000 (19:52 +0000)
With the switch from pipes to sockets for lei-daemon =>
lei/store IPC, we can send the script/lei client socket to the
lei/store process and rely on reference counting in both Perl
and the kernel to persist the script/lei.

lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiRefreshMailSync.pm
lib/PublicInbox/LeiStore.pm

index 549b855b79abc838d29a39474f56c8c7dbd82283..f62e82dc234e364d37df5642b48bb8a74d619139 100644 (file)
@@ -40,7 +40,6 @@ $GLP_PASS->configure(qw(gnu_getopt no_ignore_case auto_abbrev pass_through));
 
 our %PATH2CFG; # persistent for socket daemon
 our $MDIR2CFGPATH; # /path/to/maildir => { /path/to/config => [ ino watches ] }
-our %LIVE_SOCK; # "GLOB(0x....)" => $lei->{sock}
 
 # TBD: this is a documentation mechanism to show a subcommand
 # (may) pass options through to another command:
@@ -580,7 +579,6 @@ sub _lei_atfork_child {
        $dir_idle->force_close if $dir_idle;
        %PATH2CFG = ();
        $MDIR2CFGPATH = {};
-       %LIVE_SOCK = ();
        eval 'no warnings; undef $PublicInbox::LeiNoteEvent::to_flush';
        undef $errors_log;
        $quit = \&CORE::exit;
@@ -619,7 +617,6 @@ sub pkt_ops {
        $ops->{x_it} = [ \&x_it, $lei ];
        $ops->{child_error} = [ \&child_error, $lei ];
        $ops->{incr} = [ \&incr, $lei ];
-       $ops->{sto_done_request} = [ \&sto_done_request, $lei, $lei->{sock} ];
        $ops;
 }
 
@@ -1496,12 +1493,11 @@ sub lms {
        (-f $f || $rw) ? PublicInbox::LeiMailSync->new($f) : undef;
 }
 
-sub sto_done_request { # only call this from lei-daemon process (not workers)
+sub sto_done_request {
        my ($lei, $sock) = @_;
        eval {
                if ($sock //= $lei->{sock}) { # issue, async wait
-                       $LIVE_SOCK{"$sock"} = $sock;
-                       $lei->{sto}->wq_do('done', "$sock");
+                       $lei->{sto}->wq_io_do('done', [ $sock ]);
                } else { # forcibly wait
                        my $wait = $lei->{sto}->wq_do('done');
                }
@@ -1509,9 +1505,4 @@ sub sto_done_request { # only call this from lei-daemon process (not workers)
        $lei->err($@) if $@;
 }
 
-sub sto_done_complete { # called in lei-daemon when LeiStore->done is complete
-       my ($sock_str) = @_;
-       delete $LIVE_SOCK{$sock_str}; # frees {sock} for waiting lei clients
-}
-
 1;
index 72b8fe6367e9b6f479140472095cb52ac46d5247..2f1050059976cb15bcd5ff2e7cedba4e5c996411 100644 (file)
@@ -60,7 +60,7 @@ sub input_path_url { # overrides PublicInbox::LeiInput::input_path_url
                        $self->folder_missing($$uri);
                }
        } else { die "BUG: $input not supported" }
-       $self->{lei}->{pkt_op_p}->pkt_do('sto_done_request');
+       $self->{lei}->sto_done_request;
 }
 
 sub lei_refresh_mail_sync {
index 4ec6369974d53724dad337c428730543740dd999..164a9f2df18dd79472b523ab1c5fb6baa84a1827 100644 (file)
@@ -534,10 +534,6 @@ sub done {
        $self->{priv_eidx}->done; # V2Writable::done
        xchg_stderr($self);
        die $err if $err;
-
-       # notify clients ->done has been issued
-       defined($sock_ref) and
-               $self->{s2d_op_p}->pkt_do('sto_done_complete', $sock_ref);
 }
 
 sub ipc_atfork_child {
@@ -562,9 +558,6 @@ sub write_prepare {
        my ($self, $lei) = @_;
        $lei // die 'BUG: $lei not passed';
        unless ($self->{-ipc_req}) {
-               # s2d => store-to-daemon messages
-               require PublicInbox::PktOp;
-               my ($s2d_op_c, $s2d_op_p) = PublicInbox::PktOp->pair;
                my $dir = $lei->store_path;
                substr($dir, -length('/lei/store'), 10, '');
                pipe(my ($r, $w)) or die "pipe: $!";
@@ -576,14 +569,10 @@ sub write_prepare {
                $self->wq_workers_start("lei/store $dir", 1, $lei->oldset, {
                                        lei => $lei,
                                        -err_wr => $w,
-                                       to_close => [ $r, $s2d_op_c->{sock} ],
-                                       s2d_op_p => $s2d_op_p,
+                                       to_close => [ $r ],
                                });
                require PublicInbox::LeiStoreErr;
                PublicInbox::LeiStoreErr->new($r, $lei);
-               $s2d_op_c->{ops} = {
-                       sto_done_complete => [ $lei->can('sto_done_complete') ]
-               };
        }
        $lei->{sto} = $self;
 }