]> Sergey Matveev's repositories - public-inbox.git/commitdiff
lei: generalize auxiliary WQ handling
authorEric Wong <e@80x24.org>
Tue, 8 Jun 2021 09:50:20 +0000 (09:50 +0000)
committerEric Wong <e@80x24.org>
Tue, 8 Jun 2021 16:50:47 +0000 (16:50 +0000)
op_wait_event is now more lei-specific since we no longer have
to care about oneshot and use a synchronous loop.

{ikw} (import-keywords) started a trend, but LeiPmdir (parallel
Maildir) is an upcoming WQ class that will follow this idea.

Eventually, {l2m} usage may be updated to follow this, too.

13 files changed:
lib/PublicInbox/LEI.pm
lib/PublicInbox/LeiBlob.pm
lib/PublicInbox/LeiConvert.pm
lib/PublicInbox/LeiExportKw.pm
lib/PublicInbox/LeiImport.pm
lib/PublicInbox/LeiLsSearch.pm
lib/PublicInbox/LeiMirror.pm
lib/PublicInbox/LeiP2q.pm
lib/PublicInbox/LeiRediff.pm
lib/PublicInbox/LeiRm.pm
lib/PublicInbox/LeiTag.pm
lib/PublicInbox/LeiXSearch.pm
lib/PublicInbox/PktOp.pm

index 0cf4d10b892b287eabbc6a14a50cb9d400791c00..ed01e8def7bf2754fd5130a04d900e111079a602 100644 (file)
@@ -587,6 +587,15 @@ sub workers_start {
        ($op_c, $ops);
 }
 
+# call this when we're ready to wait on events and yield to other clients
+sub wait_wq_events {
+       my ($lei, $op_c, $ops) = @_;
+       for my $wq (grep(defined, @$lei{qw(ikw)})) { # auxiliary WQs
+               $wq->wq_close(1);
+       }
+       $op_c->{ops} = $ops;
+}
+
 sub _help {
        require PublicInbox::LeiHelp;
        PublicInbox::LeiHelp::call($_[0], $_[1], \%CMD, \%OPTDESC);
index 8de86565ab90ad7fb90c1ff385bb8d1b1364107d..0921796428b4254af4f07ed00a85ecd179a28652 100644 (file)
@@ -169,7 +169,7 @@ sub lei_blob {
        $lei->{wq1} = $self;
        $self->wq_io_do('do_solve_blob', []);
        $self->wq_close(1);
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
index 395a80f8adee44cb1a5d49f776f1573d174d3395..6550c242b1a2514ced857e2d956bfa0a8fdc0ad5 100644 (file)
@@ -59,7 +59,7 @@ sub lei_convert { # the main "lei convert" method
        $lei->{wq1} = $self;
        $self->wq_io_do('process_inputs', []);
        $self->wq_close(1);
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
index b31b065fe4f95fb062650a7218dc048a8f21c122..f8579221015e56d5fec023d8e6a5d5bc14257322 100644 (file)
@@ -160,7 +160,7 @@ EOM
        $lei->{wq1} = $self;
        $lei->{-err_type} = 'non-fatal';
        net_merge_all_done($self) unless $lei->{auth};
-       $op_c->op_wait_event($ops); # calls net_merge_all_done if $lei->{auth}
+       $lei->wait_wq_events($op_c, $ops); # net_merge_all_done if !{auth}
 }
 
 sub _complete_export_kw {
index 2efd4935ab7d3d63d1c36460d054513205fed4c7..222f75c8abe1b0e5c9ebda30e68c9a3ca0f03a5e 100644 (file)
@@ -91,9 +91,8 @@ sub do_import_index ($$@) {
        (my $op_c, $ops) = $lei->workers_start($self, $j, $ops);
        $lei->{wq1} = $self;
        $lei->{-err_type} = 'non-fatal';
-       $ikw->wq_close(1) if $ikw;
        net_merge_all_done($self) unless $lei->{auth};
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub lei_import { # the main "lei import" method
index 6cea6ae88089935d4f31a69bf9845ef8dad39dc4..7013613523e33acfcfcfadc305bf136302756e68 100644 (file)
@@ -76,7 +76,7 @@ sub bg_worker ($$$) {
        $lei->{wq1} = $self;
        $self->wq_io_do('do_ls_search_long', [], $pfx);
        $self->wq_close(1);
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub lei_ls_search {
index a37e1d5c626cdfe35398b354a22a686a48e8e679..39671f902b5514b19657bb7e937a06c935aca76d 100644 (file)
@@ -282,11 +282,11 @@ sub start {
        require PublicInbox::Inbox;
        require PublicInbox::Admin;
        require PublicInbox::InboxWritable;
-       my ($op, $ops) = $lei->workers_start($self, 1);
+       my ($op_c, $ops) = $lei->workers_start($self, 1);
        $lei->{wq1} = $self;
        $self->wq_io_do('do_mirror', []);
        $self->wq_close(1);
-       $op->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
index f381a31c543be181b18f4b595e6a0201758c0aaa..c0c4563d6fbb86a1638bf1917bf83f41d9a5525b 100644 (file)
@@ -188,11 +188,11 @@ sub lei_p2q { # the "lei patch-to-query" entry point
        } else {
                $self->{input} = $input;
        }
-       my ($op, $ops) = $lei->workers_start($self, 1);
+       my ($op_c, $ops) = $lei->workers_start($self, 1);
        $lei->{wq1} = $self;
        $self->wq_io_do('do_p2q', []);
        $self->wq_close(1);
-       $op->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
index c8bd0dfbe19ead99c9673ab91ad154f0a5504590..7607b44f5aece34d5db15989f78904935096b210 100644 (file)
@@ -227,7 +227,7 @@ sub lei_rediff {
        my ($op_c, $ops) = $lei->workers_start($self, 1);
        $lei->{wq1} = $self;
        net_merge_all_done($self) unless $lei->{auth};
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub ipc_atfork_child {
index c6d280452f12c70bed10a3e694bc63fe6f8c16ae..578e9811495080f2d620bcb52e0900db2331152c 100644 (file)
@@ -38,7 +38,7 @@ sub lei_rm {
        $lei->{wq1} = $self;
        $lei->{-err_type} = 'non-fatal';
        net_merge_all_done($self) unless $lei->{auth};
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 no warnings 'once';
index b6abd53367f7cfe5c2c24d96b7f60d487d2399cb..4b3ce7d87061c717c2647e2995debc55f76441ee 100644 (file)
@@ -53,7 +53,7 @@ sub lei_tag { # the "lei tag" method
        $lei->{wq1} = $self;
        $lei->{-err_type} = 'non-fatal';
        net_merge_all_done($self) unless $lei->{auth};
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub note_missing {
index 75e55d476710f2df4c8e933f4445728bda252424..beb955bb6de599a5ce675276888f17f6f0c83495 100644 (file)
@@ -532,7 +532,7 @@ sub do_query {
                start_query($self);
        }
        $lei->event_step_init; # wait for shutdowns
-       $op_c->op_wait_event($ops);
+       $lei->wait_wq_events($op_c, $ops);
 }
 
 sub add_uri {
index ca098d3cb53993734dc7398843022bc032e9a9a1..92e150a46bdf2126ad7bcf13e52de2b1ca4794ae 100644 (file)
@@ -63,10 +63,4 @@ sub event_step {
        }
 }
 
-# call this when we're ready to wait on events
-sub op_wait_event {
-       my ($self, $ops) = @_;
-       $self->{ops} = $ops;
-}
-
 1;