}
sub index_inbox {
- my ($ibx, $opt) = @_;
+ my ($ibx, $im, $opt) = @_;
my $jobs = delete $opt->{jobs} if $opt;
if (ref($ibx) && ($ibx->{version} || 1) == 2) {
eval { require PublicInbox::V2Writable };
die "v2 requirements not met: $@\n" if $@;
- my $v2w = eval { $ibx->importer(0) } || eval {
+ my $v2w = $im // eval { $ibx->importer(0) } || eval {
PublicInbox::V2Writable->new($ibx, {nproc=>$jobs});
};
if (defined $jobs) {
sub importer {
my ($self, $parallel) = @_;
- $self->{-importer} ||= do {
- my $v = $self->{version} || 1;
- if ($v == 2) {
- eval { require PublicInbox::V2Writable };
- die "v2 not supported: $@\n" if $@;
- my $opt = $self->{-creat_opt};
- my $v2w = PublicInbox::V2Writable->new($self, $opt);
- $v2w->{parallel} = $parallel;
- $v2w;
- } elsif ($v == 1) {
- my @arg = (undef, undef, undef, $self);
- PublicInbox::Import->new(@arg);
- } else {
- $! = 78; # EX_CONFIG 5.3.5 local configuration error
- die "unsupported inbox version: $v\n";
- }
+ my $v = $self->{version} || 1;
+ if ($v == 2) {
+ eval { require PublicInbox::V2Writable };
+ die "v2 not supported: $@\n" if $@;
+ my $opt = $self->{-creat_opt};
+ my $v2w = PublicInbox::V2Writable->new($self, $opt);
+ $v2w->{parallel} = $parallel;
+ $v2w;
+ } elsif ($v == 1) {
+ my @arg = (undef, undef, undef, $self);
+ PublicInbox::Import->new(@arg);
+ } else {
+ $! = 78; # EX_CONFIG 5.3.5 local configuration error
+ die "unsupported inbox version: $v\n";
}
}
our $XAPIAN_COMPACT = $ENV{XAPIAN_COMPACT} || 'xapian-compact';
our @COMPACT_OPT = qw(jobs|j=i quiet|q blocksize|b=s no-full|n fuller|F);
-sub commit_changes ($$$) {
- my ($ibx, $tmp, $opt) = @_;
+sub commit_changes ($$$$) {
+ my ($ibx, $im, $tmp, $opt) = @_;
my $reshard = $opt->{reshard};
my $reindex = $opt->{reindex};
- my $im = $ibx->importer(0);
- $im->lock_acquire if !$opt->{-coarse_lock};
$SIG{INT} or die 'BUG: $SIG{INT} not handled';
my @old_shard;
}
}
- PublicInbox::Admin::index_inbox($ibx, $opt);
- # implicit lock_release
- } else {
- $im->lock_release;
+ PublicInbox::Admin::index_inbox($ibx, $im, $opt);
}
}
which($exe) or die "$exe not found in PATH\n";
}
-sub prepare_reindex ($$) {
- my ($ibx, $reindex) = @_;
+sub prepare_reindex ($$$) {
+ my ($ibx, $im, $reindex) = @_;
if ($ibx->{version} == 1) {
my $dir = $ibx->search->xdir(1);
my $xdb = Search::Xapian::Database->new($dir);
$reindex->{from} = $lc;
}
} else { # v2
- my $v2w = $ibx->importer(0);
my $max;
- $v2w->git_dir_latest(\$max) or return;
+ $im->git_dir_latest(\$max) or return;
my $from = $reindex->{from};
my $mm = $ibx->mm;
my $v = PublicInbox::Search::SCHEMA_VERSION();
$tmp->{$_} ||= undef for @$src;
}
}
- my $im = $ibx->importer(0);
my $max = $opt->{jobs} || scalar(@q);
$ibx->with_umask(sub {
+ my $im = $ibx->importer(0);
$im->lock_acquire;
# fine-grained locking if we prepare for reindex
if (!$opt->{-coarse_lock}) {
- prepare_reindex($ibx, $reindex);
+ prepare_reindex($ibx, $im, $reindex);
$im->lock_release;
}
delete($ibx->{$_}) for (qw(mm over search)); # cleanup
process_queue(\@q, $cb, $max, $opt);
- commit_changes($ibx, $tmp, $opt);
+ $im->lock_acquire if !$opt->{-coarse_lock};
+ commit_changes($ibx, $im, $tmp, $opt);
});
}