about summary refs log tree commit homepage
path: root/lib/PublicInbox/V2Writable.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-10-27 07:54:10 +0000
committerEric Wong <e@80x24.org>2020-11-07 10:18:37 +0000
commit9276207ff8e337f45e4e44260824e8a1f986dee7 (patch)
tree336e112eb1022d8ac400af53cca5a6dc42ef044c /lib/PublicInbox/V2Writable.pm
parentd42bb8077d6fe78a61458c990989667308ff1dd2 (diff)
downloadpublic-inbox-9276207ff8e337f45e4e44260824e8a1f986dee7.tar.gz
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.
Diffstat (limited to 'lib/PublicInbox/V2Writable.pm')
-rw-r--r--lib/PublicInbox/V2Writable.pm30
1 files changed, 18 insertions, 12 deletions
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index de89b729..eecc702b 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -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);
 }