]> Sergey Matveev's repositories - public-inbox.git/commitdiff
searchidxshard: special init for eidx
authorEric Wong <e@80x24.org>
Tue, 27 Oct 2020 07:54:23 +0000 (07:54 +0000)
committerEric Wong <e@80x24.org>
Sat, 7 Nov 2020 10:18:55 +0000 (10:18 +0000)
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
lib/PublicInbox/SearchIdxShard.pm

index 0458d9c3ff18ec1ff24fd2e84735d5ac2d334241..029b2726060a88229be332d51e3c3765b3f502b6 100644 (file)
@@ -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;
index fa77a9f9b96a0780d1484f16a2293df0f4e674b3..ac01340cc658e41f02ede68cd13d838159cc77a3 100644 (file)
@@ -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";