From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 7/7] searchidxshard: use add_xapian directly for v2
Date: Sun, 3 Jan 2021 02:06:17 +0000 [thread overview]
Message-ID: <20210103020617.15719-8-e@80x24.org> (raw)
In-Reply-To: <20210103020617.15719-1-e@80x24.org>
We can more clearly distinguish between v1 and v2-only code
paths this way, and may be able to save a few cycles this way.
---
lib/PublicInbox/SearchIdx.pm | 1 +
lib/PublicInbox/SearchIdxShard.pm | 2 +-
lib/PublicInbox/V2Writable.pm | 8 ++++++--
3 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index a7005051..adced076 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -397,6 +397,7 @@ sub eml2doc ($$$;$) {
sub add_xapian ($$$$) {
my ($self, $eml, $smsg, $mids) = @_;
+ begin_txn_lazy($self);
my $doc = eml2doc($self, $eml, $smsg, $mids);
$self->{xdb}->replace_document($smsg->{num}, $doc);
}
diff --git a/lib/PublicInbox/SearchIdxShard.pm b/lib/PublicInbox/SearchIdxShard.pm
index 0051df93..1598faeb 100644
--- a/lib/PublicInbox/SearchIdxShard.pm
+++ b/lib/PublicInbox/SearchIdxShard.pm
@@ -54,7 +54,7 @@ sub ipc_atfork_child { # called automatically before ipc_worker_loop
sub index_eml {
my ($self, $eml, $smsg, $eidx_key) = @_;
$smsg->{eidx_key} = $eidx_key if defined $eidx_key;
- $self->ipc_do('add_message', $eml, $smsg);
+ $self->ipc_do('add_xapian', $eml, $smsg);
}
# wait for return to determine when ipc_do('commit_txn_lazy') is done
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 6be95979..459c7e86 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -141,8 +141,10 @@ sub idx_shard ($$) {
sub do_idx ($$$) {
my ($self, $eml, $smsg) = @_;
$self->{oidx}->add_overview($eml, $smsg);
- my $idx = idx_shard($self, $smsg->{num});
- $idx->index_eml($eml, $smsg);
+ if ($self->{-need_xapian}) {
+ my $idx = idx_shard($self, $smsg->{num});
+ $idx->index_eml($eml, $smsg);
+ }
my $n = $self->{transact_bytes} += $smsg->{bytes};
$n >= $self->{batch_bytes};
}
@@ -267,6 +269,7 @@ sub _idx_init { # with_umask callback
my $max = $self->{shards} - 1;
my $idx = $self->{idx_shards} = [];
push @$idx, PublicInbox::SearchIdxShard->new($self, $_) for (0..$max);
+ $self->{-need_xapian} = $idx->[0]->need_xapian;
# SearchIdxShard may do their own flushing, so don't scale
# until after forking
@@ -1129,6 +1132,7 @@ sub sync_prepare ($$) {
sub unindex_oid_aux ($$$) {
my ($self, $oid, $mid) = @_;
my @removed = $self->{oidx}->remove_oid($oid, $mid);
+ return unless $self->{-need_xapian};
for my $num (@removed) {
idx_shard($self, $num)->ipc_do('xdb_remove', $num);
}
prev parent reply other threads:[~2021-01-03 2:06 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-03 2:06 [PATCH 0/7] v2: swap in new IPC package Eric Wong
2021-01-03 2:06 ` [PATCH 1/7] ipc: some documentation comments Eric Wong
2021-01-03 2:06 ` [PATCH 2/7] searchidxshard: use PublicInbox::IPC to kill lots of code Eric Wong
2021-01-03 2:06 ` [PATCH 3/7] searchidxshard: IPC conversion, part 2 Eric Wong
2021-01-03 2:06 ` [PATCH 4/7] searchidxshard: replace index_raw with index_eml Eric Wong
2021-01-03 2:06 ` [PATCH 5/7] use Eml (or MIME) objects for all indexing paths Eric Wong
2021-01-03 2:06 ` [PATCH 6/7] ipc: switch to one-way pipes Eric Wong
2021-01-03 2:06 ` Eric Wong [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://public-inbox.org/README
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210103020617.15719-8-e@80x24.org \
--to=e@80x24.org \
--cc=meta@public-inbox.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).