about summary refs log tree commit homepage
path: root/lib/PublicInbox/LeiXSearch.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-13 07:00:35 +0000
committerEric Wong <e@80x24.org>2021-10-13 19:51:18 +0000
commit6bb8478c8dacf83492de3afe15a615d646f0904f (patch)
tree0e1aaf64816b118f4890509b86caf043e4c7fa7c /lib/PublicInbox/LeiXSearch.pm
parent759493eb1eb737e9dedd30b8280bc4067077c615 (diff)
downloadpublic-inbox-6bb8478c8dacf83492de3afe15a615d646f0904f.tar.gz
warn() is easier to augment with context information, and
frankly unavoidable in the presence of 3rd-party libraries
we don't control.
Diffstat (limited to 'lib/PublicInbox/LeiXSearch.pm')
-rw-r--r--lib/PublicInbox/LeiXSearch.pm25
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index ae9f5881..fee1b859 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -16,6 +16,7 @@ use PublicInbox::Spawn qw(popen_rd spawn which);
 use PublicInbox::MID qw(mids);
 use PublicInbox::Smsg;
 use PublicInbox::Eml;
+use PublicInbox::LEI;
 use Fcntl qw(SEEK_SET F_SETFL O_APPEND O_RDWR);
 use PublicInbox::ContentHash qw(git_sha);
 use POSIX qw(strftime);
@@ -392,11 +393,11 @@ sub query_remote_mboxrd {
                 $err = '';
                 if (-s $cerr) {
                         seek($cerr, 0, SEEK_SET) or
-                                        $lei->err("seek($cmd stderr): $!");
+                                        warn "seek($cmd stderr): $!";
                         $err = do { local $/; <$cerr> } //
-                                        "read($cmd stderr): $!";
+                                        warn "read($cmd stderr): $!";
                         truncate($cerr, 0) or
-                                        $lei->err("truncate($cmd stderr): $!");
+                                        warn "truncate($cmd stderr): $!";
                 }
                 next if (($? >> 8) == 22 && $err =~ /\b404\b/);
                 $uri->query_form(q => $qstr);
@@ -416,6 +417,7 @@ sub xsearch_done_wait { # dwaitpid callback
 
 sub query_done { # EOF callback for main daemon
         my ($lei) = @_;
+        local $PublicInbox::LEI::current_lei = $lei;
         my $l2m = delete $lei->{l2m};
         $l2m->wq_wait_old(\&xsearch_done_wait, $lei) if $l2m;
         if (my $lxs = delete $lei->{lxs}) {
@@ -462,6 +464,7 @@ Error closing $lei->{ovv}->{dst}: $!
 
 sub do_post_augment {
         my ($lei) = @_;
+        local $PublicInbox::LEI::current_lei = $lei;
         my $l2m = $lei->{l2m} or return; # client disconnected
         $lei->fchdir or return;
         my $err;
@@ -497,9 +500,10 @@ sub concurrency {
         $nl + $nr;
 }
 
-sub start_query ($;$) { # always runs in main (lei-daemon) process
-        my ($self, $l2m) = @_;
-        if ($self->{opt_threads} || ($l2m && !$self->{opt_sort})) {
+sub start_query ($$) { # always runs in main (lei-daemon) process
+        my ($self, $lei) = @_;
+        local $PublicInbox::LEI::current_lei = $lei;
+        if ($self->{opt_threads} || ($lei->{l2m} && !$self->{opt_sort})) {
                 for my $ibxish (locals($self)) {
                         $self->wq_io_do('query_one_mset', [], $ibxish);
                 }
@@ -521,9 +525,10 @@ sub start_query ($;$) { # always runs in main (lei-daemon) process
 }
 
 sub incr_start_query { # called whenever an l2m shard starts do_post_auth
-        my ($self, $l2m) = @_;
+        my ($self, $lei) = @_;
+        my $l2m = $lei->{l2m};
         return if ++$self->{nr_start_query} != $l2m->{-wq_nr_workers};
-        start_query($self, $l2m);
+        start_query($self, $lei);
 }
 
 sub ipc_atfork_child {
@@ -545,7 +550,7 @@ sub do_query {
                 'l2m_progress' => [ \&l2m_progress, $lei ],
                 'x_it' => [ $lei ],
                 'child_error' => [ $lei ],
-                'incr_start_query' => [ $self, $l2m ],
+                'incr_start_query' => [ $self, $lei ],
         };
         $lei->{auth}->op_merge($ops, $l2m) if $l2m && $lei->{auth};
         my $end = $lei->pkt_op_pair;
@@ -586,7 +591,7 @@ sub do_query {
         if ($l2m) {
                 $l2m->net_merge_all_done($lei) unless $lei->{auth};
         } else {
-                start_query($self);
+                start_query($self, $lei);
         }
         $lei->event_step_init; # wait for shutdowns
         $lei->wait_wq_events($op_c, $ops);