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 AAE1920097 for ; Tue, 27 Oct 2020 07:54:59 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 37/52] searchidx: reduce inbox-dependency, wrap ->with_umask Date: Tue, 27 Oct 2020 07:54:38 +0000 Message-Id: <20201027075453.19163-38-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: This will let us work consistently with both existing inboxes and external indices. --- lib/PublicInbox/SearchIdx.pm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm index 0c0e844a..ea884434 100644 --- a/lib/PublicInbox/SearchIdx.pm +++ b/lib/PublicInbox/SearchIdx.pm @@ -137,7 +137,7 @@ sub idx_acquire { } } return unless defined $flag; - $flag |= $DB_NO_SYNC if $self->{ibx}->{-no_fsync}; + $flag |= $DB_NO_SYNC if ($self->{ibx} // $self->{eidx})->{-no_fsync}; my $xdb = eval { ($X->{WritableDatabase})->new($dir, $flag) }; croak "Failed opening $dir: $@" if $@; $self->{xdb} = $xdb; @@ -631,11 +631,16 @@ sub unindex_both { # git->cat_async callback unindex_eml($self, $oid, PublicInbox::Eml->new($bref)); } +sub with_umask { + my $self = shift; + ($self->{ibx} // $self->{eidx})->with_umask(@_); +} + # called by public-inbox-index sub index_sync { my ($self, $opt) = @_; delete $self->{lock_path} if $opt->{-skip_lock}; - $self->{ibx}->with_umask(\&_index_sync, $self, $opt); + $self->with_umask(\&_index_sync, $self, $opt); if ($opt->{reindex}) { my %again = %$opt; delete @again{qw(rethread reindex)}; @@ -893,7 +898,7 @@ sub _begin_txn { sub begin_txn_lazy { my ($self) = @_; - $self->{ibx}->with_umask(\&_begin_txn, $self) if !$self->{txn}; + $self->with_umask(\&_begin_txn, $self) if !$self->{txn}; } # store 'indexlevel=medium' in v2 shard=0 and v1 (only one shard) @@ -931,7 +936,7 @@ sub _commit_txn { sub commit_txn_lazy { my ($self) = @_; delete($self->{txn}) and - $self->{ibx}->with_umask(\&_commit_txn, $self); + $self->with_umask(\&_commit_txn, $self); } sub worker_done { @@ -945,6 +950,7 @@ sub worker_done { sub eidx_shard_new { my ($class, $eidx, $shard) = @_; my $self = bless { + eidx => $eidx, xpfx => $eidx->{xpfx}, indexlevel => $eidx->{indexlevel}, -skip_docdata => 1,