* [PATCH 01/11] lei q: retrieve keywords for local, non-external messages
@ 2021-01-20 4:55 Eric Wong
2021-01-20 4:55 ` [PATCH 02/11] lei_overview: rename {relevance} => {pct} Eric Wong
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
This isn't tested for now, so maybe it works.
---
lib/PublicInbox/LeiOverview.pm | 8 +++-----
lib/PublicInbox/LeiSearch.pm | 16 +++-------------
lib/PublicInbox/LeiXSearch.pm | 14 ++++++++++----
lib/PublicInbox/Search.pm | 20 +++++++++++++++++++-
4 files changed, 35 insertions(+), 23 deletions(-)
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index dcc3088b..02c6ae9c 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -228,9 +228,8 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
my $git_dir = $git->{git_dir};
sub {
my ($smsg, $mitem) = @_;
- my $kw = []; # TODO get from mitem
$l2m->wq_do('write_mail', \@io, $git_dir,
- $smsg->{blob}, $lei_ipc, $kw)
+ $smsg->{blob}, $lei_ipc, $smsg->{kw});
}
} elsif ($l2m) {
my $wcb = $l2m->write_cb($lei);
@@ -239,8 +238,8 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
my $g2m = $l2m->can('git_to_mail');
sub {
my ($smsg, $mitem) = @_;
- my $kw = []; # TODO get from mitem
- $git->cat_async($smsg->{blob}, $g2m, [ $wcb, $kw ]);
+ $git->cat_async($smsg->{blob}, $g2m,
+ [ $wcb, $smsg->{kw} ]);
};
} elsif ($self->{fmt} =~ /\A(concat)?json\z/ && $lei->{opt}->{pretty}) {
my $EOR = ($1//'') eq 'concat' ? "\n}" : "\n},";
@@ -270,7 +269,6 @@ sub ovv_each_smsg_cb { # runs in wq worker usually
$lei->{ovv_buf} = \(my $buf = '');
sub {
my ($smsg, $mitem) = @_;
- delete @$smsg{qw(tid num)};
$buf .= $json->encode(_unbless_smsg(@_)) . $ORS;
if (length($buf) > 65536) {
my $lk = $self->lock_for_scope;
diff --git a/lib/PublicInbox/LeiSearch.pm b/lib/PublicInbox/LeiSearch.pm
index b7e337de..440bacf5 100644
--- a/lib/PublicInbox/LeiSearch.pm
+++ b/lib/PublicInbox/LeiSearch.pm
@@ -5,7 +5,7 @@ package PublicInbox::LeiSearch;
use strict;
use v5.10.1;
use parent qw(PublicInbox::ExtSearch);
-use PublicInbox::Search;
+use PublicInbox::Search qw(xap_terms);
# get combined docid from over.num:
# (not generic Xapian, only works with our sharding scheme)
@@ -19,19 +19,9 @@ sub msg_keywords {
my ($self, $num) = @_; # num_or_mitem
my $xdb = $self->xdb; # set {nshard};
my $docid = ref($num) ? $num->get_docid : num2docid($self, $num);
- my %kw;
- eval {
- my $end = $xdb->termlist_end($docid);
- my $cur = $xdb->termlist_begin($docid);
- for (; $cur != $end; $cur++) {
- $cur->skip_to('K');
- last if $cur == $end;
- my $kw = $cur->get_termname;
- $kw =~ s/\AK//s and $kw{$kw} = undef;
- }
- };
+ my $kw = xap_terms('K', $xdb, $docid);
warn "E: #$docid ($num): $@\n" if $@;
- wantarray ? sort(keys(%kw)) : \%kw;
+ wantarray ? sort(keys(%$kw)) : $kw;
}
1;
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index fa37543f..a6770f55 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -13,6 +13,7 @@ use PublicInbox::OpPipe;
use PublicInbox::Import;
use File::Temp 0.19 (); # 0.19 for ->newdir
use File::Spec ();
+use PublicInbox::Search qw(xap_terms);
sub new {
my ($class) = @_;
@@ -74,7 +75,12 @@ sub smsg_for {
my $docid = $mitem->get_docid;
my $shard = ($docid - 1) % $nshard;
my $num = int(($docid - 1) / $nshard) + 1;
- my $smsg = $self->{shard2ibx}->[$shard]->over->get_art($num);
+ my $ibx = $self->{shard2ibx}->[$shard];
+ my $smsg = $ibx->over->get_art($num);
+ if (ref($ibx->can('msg_keywords'))) {
+ my $kw = xap_terms('K', $mitem->get_document);
+ $smsg->{kw} = [ sort keys %$kw ];
+ }
$smsg->{docid} = $docid;
$smsg;
}
@@ -153,11 +159,11 @@ sub query_mset { # non-parallel for non-"--thread" users
$dedupe->prepare_dedupe;
do {
$mset = $self->mset($mo->{qstr}, $mo);
- for my $it ($mset->items) {
- my $smsg = smsg_for($self, $it) or next;
+ for my $mitem ($mset->items) {
+ my $smsg = smsg_for($self, $mitem) or next;
wait_startq($startq) if $startq;
next if $dedupe->is_smsg_dup($smsg);
- $each_smsg->($smsg, $it);
+ $each_smsg->($smsg, $mitem);
}
} while (_mset_more($mset, $mo));
undef $each_smsg; # drops @io for l2m->{each_smsg_done}
diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index a4b40f94..7c6a16be 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -6,7 +6,7 @@
package PublicInbox::Search;
use strict;
use parent qw(Exporter);
-our @EXPORT_OK = qw(retry_reopen int_val get_pct);
+our @EXPORT_OK = qw(retry_reopen int_val get_pct xap_terms);
use List::Util qw(max);
# values for searching, changing the numeric value breaks
@@ -432,4 +432,22 @@ sub get_pct ($) { # mset item
$n > 99 ? 99 : $n;
}
+sub xap_terms ($$;@) {
+ my ($pfx, $xdb_or_doc, @docid) = @_; # @docid may be empty ()
+ my %ret;
+ eval {
+ my $end = $xdb_or_doc->termlist_end(@docid);
+ my $cur = $xdb_or_doc->termlist_begin(@docid);
+ for (; $cur != $end; $cur++) {
+ $cur->skip_to($pfx);
+ last if $cur == $end;
+ my $tn = $cur->get_termname;
+ if (index($tn, $pfx) == 0) {
+ $ret{substr($tn, length($pfx))} = undef;
+ }
+ }
+ };
+ \%ret;
+}
+
1;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 02/11] lei_overview: rename {relevance} => {pct}
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 03/11] overidx: eidx_prep: fix leftover dbh reference Eric Wong
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
The old name was too long compared to the rest of the field
names. With the Xapian method being named ->get_percent,
"pct" is a well known abbreviation for "percent" and already
used internally by our wrapper.
..And cleanup some excess whitespace while we're in the area.
---
lib/PublicInbox/LeiOverview.pm | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/lib/PublicInbox/LeiOverview.pm b/lib/PublicInbox/LeiOverview.pm
index 02c6ae9c..423013de 100644
--- a/lib/PublicInbox/LeiOverview.pm
+++ b/lib/PublicInbox/LeiOverview.pm
@@ -137,11 +137,9 @@ sub _unbless_smsg {
delete @$smsg{qw(lines bytes num tid)};
$smsg->{rt} = _iso8601(delete $smsg->{ts}); # JMAP receivedAt
$smsg->{dt} = _iso8601(delete $smsg->{ds}); # JMAP UTCDate
- $smsg->{relevance} = get_pct($mitem) if $mitem;
-
+ $smsg->{pct} = get_pct($mitem) if $mitem;
if (my $r = delete $smsg->{references}) {
- $smsg->{refs} = [
- map { "<$_>" } ($r =~ m/$MID_EXTRACT/go) ];
+ $smsg->{refs} = [ map { "<$_>" } ($r =~ m/$MID_EXTRACT/go) ];
}
if (my $m = delete($smsg->{mid})) {
$smsg->{'m'} = "<$m>";
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 03/11] overidx: eidx_prep: fix leftover dbh reference
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
2021-01-20 4:55 ` [PATCH 02/11] lei_overview: rename {relevance} => {pct} Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 04/11] lei q: cleanup store initialization Eric Wong
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
Leaving $dbh in another field was causing over.sqlite3 to
remain open after ->dbh_close. Fix up some minor style
issues while we're at it.
---
lib/PublicInbox/OverIdx.pm | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/lib/PublicInbox/OverIdx.pm b/lib/PublicInbox/OverIdx.pm
index 0a4eb39e..e606dcf5 100644
--- a/lib/PublicInbox/OverIdx.pm
+++ b/lib/PublicInbox/OverIdx.pm
@@ -537,7 +537,7 @@ sub eidx_prep ($) {
my ($self) = @_;
$self->{-eidx_prep} //= do {
my $dbh = $self->dbh;
- $dbh->do(<<"");
+ $dbh->do(<<'');
INSERT OR IGNORE INTO counter (key) VALUES ('eidx_docid')
$dbh->do(<<'');
@@ -574,11 +574,9 @@ CREATE TABLE IF NOT EXISTS eidx_meta (
# Currently used for "-extindex --reindex" for Xapian
# data, but may be used in more places down the line.
$dbh->do(<<'');
-CREATE TABLE IF NOT EXISTS eidxq (
- docid INTEGER PRIMARY KEY NOT NULL
-)
+CREATE TABLE IF NOT EXISTS eidxq (docid INTEGER PRIMARY KEY NOT NULL)
- $dbh;
+ 1;
};
}
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 04/11] lei q: cleanup store initialization
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
2021-01-20 4:55 ` [PATCH 02/11] lei_overview: rename {relevance} => {pct} Eric Wong
2021-01-20 4:55 ` [PATCH 03/11] overidx: eidx_prep: fix leftover dbh reference Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 05/11] lei: dump and clear errors.log in daemon mode Eric Wong
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
Since we no longer leak an FD for over.sqlite3, we can
initialize and actually enable it by default as originally
intended.
---
lib/PublicInbox/LeiQuery.pm | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index d6e801e3..941bc299 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -23,14 +23,15 @@ sub _vivify_external { # _externals_each callback
# the main "lei q SEARCH_TERMS" method
sub lei_q {
my ($self, @argv) = @_;
- my $opt = $self->{opt};
-
- # --local is enabled by default
- # src: LeiXSearch || LeiSearch || Inbox
- my @srcs;
require PublicInbox::LeiXSearch;
require PublicInbox::LeiOverview;
- PublicInbox::Config->json;
+ PublicInbox::Config->json; # preload before forking
+ my $opt = $self->{opt};
+ my @srcs; # any number of LeiXSearch || LeiSearch || Inbox
+ if ($opt->{'local'} //= 1) { # --local is enabled by default
+ my $sto = $self->_lei_store(1);
+ push @srcs, $sto->search;
+ }
my $lxs = PublicInbox::LeiXSearch->new;
# --external is enabled by default, but allow --no-external
@@ -39,7 +40,6 @@ sub lei_q {
}
my $j = $opt->{jobs} // (scalar(@srcs) > 3 ? 3 : scalar(@srcs));
$j = 1 if !$opt->{thread};
- $j++ if $opt->{'local'}; # for sto->search below
$self->atfork_prepare_wq($lxs);
$lxs->wq_workers_start('lei_xsearch', $j, $self->oldset);
$self->{lxs} = $lxs;
@@ -50,10 +50,8 @@ sub lei_q {
$self->atfork_prepare_wq($l2m);
$l2m->wq_workers_start('lei2mail', $j, $self->oldset);
}
-
# no forking workers after this
- my $sto = $self->_lei_store(1);
- unshift(@srcs, $sto->search) if $opt->{'local'};
+
my %mset_opt = map { $_ => $opt->{$_} } qw(thread limit offset);
$mset_opt{asc} = $opt->{'reverse'} ? 1 : 0;
$mset_opt{qstr} = join(' ', map {;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 05/11] lei: dump and clear errors.log in daemon mode
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (2 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 04/11] lei q: cleanup store initialization Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 06/11] lei: keep pgr Eric Wong
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
Inspired by "dmesg -c", this should help users report bugs
and avoids eating up $XDG_RUNTIME_DIR.
Once lei is ready for release, hopefully the need for this
should be few an far between, but shit happens.
---
lib/PublicInbox/LEI.pm | 29 +++++++++++++++++++++++------
t/lei.t | 6 ++++++
2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index f3edfe82..cfb6fdf4 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -15,6 +15,7 @@ use Socket qw(AF_UNIX SOCK_SEQPACKET MSG_EOR pack_sockaddr_un);
use Errno qw(EAGAIN EINTR ECONNREFUSED ENOENT ECONNRESET);
use POSIX ();
use IO::Handle ();
+use Fcntl qw(SEEK_SET);
use Sys::Syslog qw(syslog openlog);
use PublicInbox::Config;
use PublicInbox::Syscall qw(SFD_NONBLOCK EPOLLIN EPOLLET);
@@ -26,7 +27,7 @@ use Text::Wrap qw(wrap);
use File::Path qw(mkpath);
use File::Spec;
our $quit = \&CORE::exit;
-our $current_lei;
+our ($current_lei, $errors_log);
my ($recv_cmd, $send_cmd);
my $GLP = Getopt::Long::Parser->new;
$GLP->configure(qw(gnu_getopt no_ignore_case auto_abbrev));
@@ -246,6 +247,7 @@ sub x_it ($$) {
my ($self, $code) = @_;
# make sure client sees stdout before exit
$self->{1}->autoflush(1) if $self->{1};
+ dump_and_clear_log();
if (my $sock = $self->{sock}) {
send($sock, "x_it $code", MSG_EOR);
} elsif (!($code & 127)) { # oneshot, ignore signals
@@ -259,7 +261,7 @@ sub out ($;@) { print { shift->{1} } @_ }
sub err ($;@) {
my $self = shift;
- my $err = $self->{2} // *STDERR{IO};
+ my $err = $self->{2} // ($self->{pgr} // [])->[2] // *STDERR{IO};
print $err @_, (substr($_[-1], -1, 1) eq "\n" ? () : "\n");
}
@@ -295,6 +297,7 @@ sub atfork_child_wq {
$self->{sock} = $sock if -S $sock;
$self->{l2m}->{-wq_s1} = $l2m_wq_s1 if $l2m_wq_s1 && -S $l2m_wq_s1;
%PATH2CFG = ();
+ undef $errors_log;
$quit = \&CORE::exit;
@TO_CLOSE_ATFORK_CHILD = ();
(__WARN__ => sub { err($self, @_) },
@@ -321,7 +324,7 @@ sub atfork_parent_wq {
$ret->{dedupe} = $wq->deep_clone($dedupe);
}
$self->{env} = $env;
- delete @$ret{qw(-lei_store cfg pgr lxs)}; # keep l2m
+ delete @$ret{qw(-lei_store cfg lxs)}; # keep l2m
my @io = delete @$ret{0..2};
$io[3] = delete($ret->{sock}) // *STDERR{GLOB};
my $l2m = $ret->{l2m};
@@ -478,6 +481,7 @@ sub optparse ($$$) {
sub dispatch {
my ($self, $cmd, @argv) = @_;
local $current_lei = $self; # for __WARN__
+ dump_and_clear_log("from previous run\n");
return _help($self, 'no command given') unless defined($cmd);
my $func = "lei_$cmd";
$func =~ tr/-/_/;
@@ -767,6 +771,7 @@ sub event_step {
my ($self) = @_;
local %ENV = %{$self->{env}};
my $sock = $self->{sock};
+ local $current_lei = $self;
eval {
while (my @fds = $recv_cmd->($sock, my $buf, 4096)) {
if (scalar(@fds) == 1 && !defined($fds[0])) {
@@ -800,6 +805,15 @@ sub noop {}
our $oldset; sub oldset { $oldset }
+sub dump_and_clear_log {
+ if (defined($errors_log) && -s STDIN && seek(STDIN, 0, SEEK_SET)) {
+ my @pfx = @_;
+ unshift(@pfx, "$errors_log ") if @pfx;
+ warn @pfx, do { local $/; <STDIN> };
+ truncate(STDIN, 0) or warn "ftruncate ($errors_log): $!";
+ }
+}
+
# lei(1) calls this when it can't connect
sub lazy_start {
my ($path, $errno, $narg) = @_;
@@ -831,9 +845,12 @@ sub lazy_start {
require PublicInbox::Listener;
require PublicInbox::EOFpipe;
(-p STDOUT) or die "E: stdout must be a pipe\n";
- my ($err) = ($path =~ m!\A(.+?/)[^/]+\z!);
- $err .= 'errors.log';
- open(STDIN, '+>>', $err) or die "open($err): $!";
+ local $errors_log;
+ ($errors_log) = ($path =~ m!\A(.+?/)[^/]+\z!);
+ $errors_log .= 'errors.log';
+ open(STDIN, '+>>', $errors_log) or die "open($errors_log): $!";
+ STDIN->autoflush(1);
+ dump_and_clear_log("from previous daemon process:\n");
POSIX::setsid() > 0 or die "setsid: $!";
my $pid = fork // die "fork: $!";
return if $pid;
diff --git a/t/lei.t b/t/lei.t
index 64cb5f0e..9bf3a8a4 100644
--- a/t/lei.t
+++ b/t/lei.t
@@ -258,6 +258,7 @@ SKIP: { # real socket
} // skip 'Socket::MsgHdr or Inline::C missing or unconfigured', 115;
local $ENV{XDG_RUNTIME_DIR} = "$home/xdg_run";
my $sock = "$ENV{XDG_RUNTIME_DIR}/lei/5.seq.sock";
+ my $err_log = "$ENV{XDG_RUNTIME_DIR}/lei/errors.log";
ok($lei->('daemon-pid'), 'daemon-pid');
is($err, '', 'no error from daemon-pid');
@@ -267,10 +268,15 @@ SKIP: { # real socket
ok(-S $sock, 'sock created');
$test_lei_common->();
+ is(-s $err_log, 0, 'nothing in errors.log');
+ open my $efh, '>>', $err_log or BAIL_OUT $!;
+ print $efh "phail\n" or BAIL_OUT $!;
+ close $efh or BAIL_OUT $!;
ok($lei->('daemon-pid'), 'daemon-pid');
chomp(my $pid_again = $out);
is($pid, $pid_again, 'daemon-pid idempotent');
+ like($err, qr/phail/, 'got mock "phail" error previous run');
ok($lei->(qw(daemon-kill)), 'daemon-kill');
is($out, '', 'no output from daemon-kill');
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 06/11] lei: keep pgr
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (3 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 05/11] lei: dump and clear errors.log in daemon mode Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 07/11] store WIP Eric Wong
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
---
lib/PublicInbox/LEI.pm | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/PublicInbox/LEI.pm b/lib/PublicInbox/LEI.pm
index cfb6fdf4..6b505134 100644
--- a/lib/PublicInbox/LEI.pm
+++ b/lib/PublicInbox/LEI.pm
@@ -324,7 +324,7 @@ sub atfork_parent_wq {
$ret->{dedupe} = $wq->deep_clone($dedupe);
}
$self->{env} = $env;
- delete @$ret{qw(-lei_store cfg lxs)}; # keep l2m
+ delete @$ret{qw(-lei_store cfg pgr lxs)}; # keep l2m
my @io = delete @$ret{0..2};
$io[3] = delete($ret->{sock}) // *STDERR{GLOB};
my $l2m = $ret->{l2m};
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 07/11] store WIP
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (4 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 06/11] lei: keep pgr Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 08/11] lei_xsearch: keep l2m->{-wq_s1} while preparing query Eric Wong
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
---
lib/PublicInbox/LeiQuery.pm | 1 +
lib/PublicInbox/LeiStore.pm | 13 +++++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index 941bc299..63edc5d4 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -30,6 +30,7 @@ sub lei_q {
my @srcs; # any number of LeiXSearch || LeiSearch || Inbox
if ($opt->{'local'} //= 1) { # --local is enabled by default
my $sto = $self->_lei_store(1);
+ $sto->ipc_worker_spawn('lei_store', $self->oldset);
push @srcs, $sto->search;
}
my $lxs = PublicInbox::LeiXSearch->new;
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index a7d7d953..acbe236f 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -22,8 +22,12 @@ use List::Util qw(max);
sub new {
my (undef, $dir, $opt) = @_;
my $eidx = PublicInbox::ExtSearchIdx->new($dir, $opt);
- my $self = bless { priv_eidx => $eidx }, __PACKAGE__;
- eidx_init($self)->done if $opt->{creat};
+ my $self = bless { priv_eidx => $eidx, -owner => $$ }, __PACKAGE__;
+ my $lk = $self->ipc_lock_init("$dir/ipc.lock");
+ if ($opt->{creat}) {
+ eidx_init($self)->done;
+ $lk->lock_for_scope; # just creates the file
+ }
$self;
}
@@ -237,4 +241,9 @@ sub done {
die $err if $err;
}
+sub DESTROY {
+ my ($self) = @_;
+ done($self) if $self->{-owner} == $$;
+}
+
1;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 08/11] lei_xsearch: keep l2m->{-wq_s1} while preparing query
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (5 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 07/11] store WIP Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 09/11] nostore Eric Wong
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
This caused a performance regression which made parallel
lei2mail processes fail prematurely.
---
lib/PublicInbox/LeiXSearch.pm | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index a6770f55..d7688ede 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -279,9 +279,9 @@ sub do_query {
pipe(my ($startq, $au_done)) or die "pipe: $!";
$done_op->{'.'} = [ \&do_post_augment, $lei_orig,
$zpipe, $au_done ];
- $io[4] = *STDERR{GLOB}; # don't send l2m->{-wq_s1}
- $self->wq_do('query_prepare', \@io, $lei);
+ local $io[4] = *STDERR{GLOB}; # don't send l2m->{-wq_s1}
die "BUG: unexpected \$io[5]: $io[5]" if $io[5];
+ $self->wq_do('query_prepare', \@io, $lei);
fcntl($startq, 1031, 4096) if $^O eq 'linux'; # F_SETPIPE_SZ
$io[5] = $startq;
$io[1] = $zpipe->[1] if $zpipe;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 09/11] nostore
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (6 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 08/11] lei_xsearch: keep l2m->{-wq_s1} while preparing query Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 10/11] lei_to_mail: call PublicInbox::IPC::DESTROY Eric Wong
2021-01-20 4:55 ` [PATCH 11/11] lei_xsearch: eliminate some unused, commented-out code Eric Wong
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
---
lib/PublicInbox/LeiQuery.pm | 1 -
lib/PublicInbox/LeiStore.pm | 13 ++-----------
2 files changed, 2 insertions(+), 12 deletions(-)
diff --git a/lib/PublicInbox/LeiQuery.pm b/lib/PublicInbox/LeiQuery.pm
index 63edc5d4..941bc299 100644
--- a/lib/PublicInbox/LeiQuery.pm
+++ b/lib/PublicInbox/LeiQuery.pm
@@ -30,7 +30,6 @@ sub lei_q {
my @srcs; # any number of LeiXSearch || LeiSearch || Inbox
if ($opt->{'local'} //= 1) { # --local is enabled by default
my $sto = $self->_lei_store(1);
- $sto->ipc_worker_spawn('lei_store', $self->oldset);
push @srcs, $sto->search;
}
my $lxs = PublicInbox::LeiXSearch->new;
diff --git a/lib/PublicInbox/LeiStore.pm b/lib/PublicInbox/LeiStore.pm
index acbe236f..a7d7d953 100644
--- a/lib/PublicInbox/LeiStore.pm
+++ b/lib/PublicInbox/LeiStore.pm
@@ -22,12 +22,8 @@ use List::Util qw(max);
sub new {
my (undef, $dir, $opt) = @_;
my $eidx = PublicInbox::ExtSearchIdx->new($dir, $opt);
- my $self = bless { priv_eidx => $eidx, -owner => $$ }, __PACKAGE__;
- my $lk = $self->ipc_lock_init("$dir/ipc.lock");
- if ($opt->{creat}) {
- eidx_init($self)->done;
- $lk->lock_for_scope; # just creates the file
- }
+ my $self = bless { priv_eidx => $eidx }, __PACKAGE__;
+ eidx_init($self)->done if $opt->{creat};
$self;
}
@@ -241,9 +237,4 @@ sub done {
die $err if $err;
}
-sub DESTROY {
- my ($self) = @_;
- done($self) if $self->{-owner} == $$;
-}
-
1;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 10/11] lei_to_mail: call PublicInbox::IPC::DESTROY
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (7 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 09/11] nostore Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
2021-01-20 4:55 ` [PATCH 11/11] lei_xsearch: eliminate some unused, commented-out code Eric Wong
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
It doesn't seem to matter at the moment, but it should
save us some surprises down the line.
---
lib/PublicInbox/LeiToMail.pm | 1 +
1 file changed, 1 insertion(+)
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm
index 49b5c8ab..1b5d14d1 100644
--- a/lib/PublicInbox/LeiToMail.pm
+++ b/lib/PublicInbox/LeiToMail.pm
@@ -471,6 +471,7 @@ sub DESTROY {
for my $pid_git (grep(/\A$$\0/, keys %$self)) {
$self->{$pid_git}->async_wait_all;
}
+ $self->SUPER::DESTROY; # PublicInbox::IPC
}
1;
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 11/11] lei_xsearch: eliminate some unused, commented-out code
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
` (8 preceding siblings ...)
2021-01-20 4:55 ` [PATCH 10/11] lei_to_mail: call PublicInbox::IPC::DESTROY Eric Wong
@ 2021-01-20 4:55 ` Eric Wong
9 siblings, 0 replies; 11+ messages in thread
From: Eric Wong @ 2021-01-20 4:55 UTC (permalink / raw)
To: spew
---
lib/PublicInbox/LeiXSearch.pm | 5 -----
1 file changed, 5 deletions(-)
diff --git a/lib/PublicInbox/LeiXSearch.pm b/lib/PublicInbox/LeiXSearch.pm
index d7688ede..13611882 100644
--- a/lib/PublicInbox/LeiXSearch.pm
+++ b/lib/PublicInbox/LeiXSearch.pm
@@ -291,11 +291,6 @@ sub do_query {
my @pids = $self->wq_close;
# for the $lei->atfork_child_wq PIPE handler:
$done_op->{'!'}->[3] = \@pids;
- # $done->event_step;
- # my $ipc_worker_reap = $self->can('ipc_worker_reap');
- # if (my $l2m_pids = delete $self->{l2m_pids}) {
- # dwaitpid($_, $ipc_worker_reap, $l2m) for @$l2m_pids;
- # }
while ($done->{sock}) { $done->event_step }
my $ipc_worker_reap = $self->can('ipc_worker_reap');
dwaitpid($_, $ipc_worker_reap, $self) for @pids;
^ permalink raw reply related [flat|nested] 11+ messages in thread
end of thread, other threads:[~2021-01-20 4:56 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-01-20 4:55 [PATCH 01/11] lei q: retrieve keywords for local, non-external messages Eric Wong
2021-01-20 4:55 ` [PATCH 02/11] lei_overview: rename {relevance} => {pct} Eric Wong
2021-01-20 4:55 ` [PATCH 03/11] overidx: eidx_prep: fix leftover dbh reference Eric Wong
2021-01-20 4:55 ` [PATCH 04/11] lei q: cleanup store initialization Eric Wong
2021-01-20 4:55 ` [PATCH 05/11] lei: dump and clear errors.log in daemon mode Eric Wong
2021-01-20 4:55 ` [PATCH 06/11] lei: keep pgr Eric Wong
2021-01-20 4:55 ` [PATCH 07/11] store WIP Eric Wong
2021-01-20 4:55 ` [PATCH 08/11] lei_xsearch: keep l2m->{-wq_s1} while preparing query Eric Wong
2021-01-20 4:55 ` [PATCH 09/11] nostore Eric Wong
2021-01-20 4:55 ` [PATCH 10/11] lei_to_mail: call PublicInbox::IPC::DESTROY Eric Wong
2021-01-20 4:55 ` [PATCH 11/11] lei_xsearch: eliminate some unused, commented-out code Eric Wong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).