From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,AWL,BAYES_00 shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id 27B7920085 for ; Tue, 27 Oct 2020 07:54:57 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 22/52] searchidxshard: special init for eidx Date: Tue, 27 Oct 2020 07:54:23 +0000 Message-Id: <20201027075453.19163-23-e@80x24.org> In-Reply-To: <20201027075453.19163-1-e@80x24.org> References: <20201027075453.19163-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: Having a special init path for external indices is probably easier than further overloading SearchIdx->new initialization to work without an Inbox object. --- lib/PublicInbox/SearchIdx.pm | 13 +++++++++++++ lib/PublicInbox/SearchIdxShard.pm | 7 ++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 0458d9c3..029b2726 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -942,4 +942,17 @@ sub worker_done { die "$$ $0 still in transaction\n" if $self->{txn}; } +sub eidx_shard_new { + my ($class, $eidx, $shard) = @_; + my $self = bless { + xpfx => $eidx->{xpfx}, + indexlevel => $eidx->{indexlevel}, + -skip_docdata => 1, + shard => $shard, + creat => 1, + }, $class; + $self->{-set_indexlevel_once} = 1 if $self->{indexlevel} eq 'medium'; + $self; +} + 1; diff --git a/lib/PublicInbox/SearchIdxShard.pm b/lib/PublicInbox/SearchIdxShard.pm index fa77a9f9..ac01340c 100644 --- a/lib/PublicInbox/SearchIdxShard.pm +++ b/lib/PublicInbox/SearchIdxShard.pm @@ -12,9 +12,10 @@ use IO::Handle (); # autoflush use PublicInbox::Eml; sub new { - my ($class, $v2w, $shard) = @_; + my ($class, $v2w, $shard) = @_; # v2w may be ExtSearchIdx my $ibx = $v2w->{ibx}; - my $self = $class->SUPER::new($ibx, 1, $shard); + my $self = $ibx ? $class->SUPER::new($ibx, 1, $shard) + : $class->eidx_shard_new($v2w, $shard); # create the DB before forking: $self->idx_acquire; $self->set_metadata_once; @@ -58,7 +59,7 @@ sub eml ($$) { # this reads all the writes to $self->{w} from the parent process sub shard_worker_loop ($$$$$) { my ($self, $v2w, $r, $shard, $bnote) = @_; - $0 = "pi-v2-shard[$shard]"; + $0 = "shard[$shard]"; $self->begin_txn_lazy; while (my $line = readline($r)) { $v2w->{current_info} = "[$shard] $line";