From 9276207ff8e337f45e4e44260824e8a1f986dee7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 27 Oct 2020 07:54:10 +0000 Subject: v2writable: prepare initialization for external indices 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 | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) (limited to 'lib/PublicInbox/V2Writable.pm') 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); } -- cgit v1.2.3-24-ge0c7