]> Sergey Matveev's repositories - public-inbox.git/commitdiff
v2writable: prepare initialization for external indices
authorEric Wong <e@80x24.org>
Tue, 27 Oct 2020 07:54:10 +0000 (07:54 +0000)
committerEric Wong <e@80x24.org>
Sat, 7 Nov 2020 10:18:37 +0000 (10:18 +0000)
External indices won't have $self->{ibx} since it needs to
deal with multiple inboxes.  We can also hoist out
->parallel_init to make it easier to distinguish the
non-parallel control flow.

lib/PublicInbox/V2Writable.pm

index de89b7292c147625cfe79bb6a5a12d9dd50682da..eecc702b8a62f7148fb1ad42bfb0b261950e4def 100644 (file)
@@ -271,15 +271,30 @@ 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);
+       my $ibx = $self->{ibx} or return; # ExtIdxSearch
 
        # Now that all subprocesses are up, we can open the FDs
        # for SQLite:
        my $mm = $self->{mm} = PublicInbox::Msgmap->new_file(
-                               "$self->{ibx}->{inboxdir}/msgmap.sqlite3",
-                               $self->{ibx}->{-no_fsync} ? 2 : 1);
+                               "$ibx->{inboxdir}/msgmap.sqlite3",
+                               $ibx->{-no_fsync} ? 2 : 1);
        $mm->{dbh}->begin_work;
 }
 
+sub parallel_init ($$) {
+       my ($self, $indexlevel) = @_;
+       if (($indexlevel // 'full') eq 'basic') {
+               $self->{parallel} = 0;
+       } else {
+               pipe(my ($r, $w)) or die "pipe failed: $!";
+               # pipe for barrier notifications doesn't need to be big,
+               # 1031: F_SETPIPE_SZ
+               fcntl($w, 1031, 4096) if $^O eq 'linux';
+               $self->{bnote} = [ $r, $w ];
+               $w->autoflush(1);
+       }
+}
+
 # idempotent
 sub idx_init {
        my ($self, $opt) = @_;
@@ -292,16 +307,7 @@ sub idx_init {
        delete @$ibx{qw(mm search)};
        $ibx->git->cleanup;
 
-       $self->{parallel} = 0 if ($ibx->{indexlevel}//'') eq 'basic';
-       if ($self->{parallel}) {
-               pipe(my ($r, $w)) or die "pipe failed: $!";
-               # pipe for barrier notifications doesn't need to be big,
-               # 1031: F_SETPIPE_SZ
-               fcntl($w, 1031, 4096) if $^O eq 'linux';
-               $self->{bnote} = [ $r, $w ];
-               $w->autoflush(1);
-       }
-
+       parallel_init($self, $ibx->{indexlevel});
        $ibx->umask_prepare;
        $ibx->with_umask(\&_idx_init, $self, $opt);
 }