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 D81531FFAB for ; Tue, 27 Oct 2020 07:54:54 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/52] v2writable: prepare initialization for external indices Date: Tue, 27 Oct 2020 07:54:10 +0000 Message-Id: <20201027075453.19163-10-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: 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(-) 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); }