my ($ibx, $opt) = @_;
my $tmp = {}; # old shard dir => File::Temp->newdir object or undef
my @queue; # ([old//src,newdir]) - list of args for cpdb() or compact()
-
- my $old = $ibx->search->xdir(1);
- -d $old or die "$old does not exist\n";
+ my $old;
+ if (my $srch = $ibx->search) {
+ $old = $srch->xdir(1);
+ -d $old or die "$old does not exist\n";
+ }
my $reshard = $opt->{reshard};
if (defined $reshard && $reshard <= 0) {
die "--reshard must be a positive number\n";
# we want temporary directories to be as deep as possible,
# so v2 shards can keep "xap$SCHEMA_VERSION" on a separate FS.
- if ($ibx->version == 1) {
+ if ($old && $ibx->version == 1) {
if (defined $reshard) {
warn
"--reshard=$reshard ignored for v1 $ibx->{inboxdir}\n";
$tmp->{$old} = $wip;
nodatacow_dir($wip->dirname);
push @queue, [ $old, $wip ];
- } else {
+ } elsif ($old) {
opendir my $dh, $old or die "Failed to opendir $old: $!\n";
my @old_shards;
while (defined(my $dn = readdir($dh))) {
PublicInbox::Admin::progress_prepare($opt ||= {});
defined(my $dir = $ibx->{inboxdir}) or die "no inboxdir defined\n";
-d $dir or die "inboxdir=$dir does not exist\n";
- check_compact() if $opt->{compact};
+ check_compact() if $opt->{compact} && $ibx->search;
my $reindex; # v1:{ from => $x40 }, v2:{ from => [ $x40, $x40, .. ] } }
if (!$opt->{-coarse_lock}) {
use PublicInbox::Eml;
use PublicInbox::Inbox;
use PublicInbox::InboxWritable;
+use PublicInbox::Spawn qw(which);
require PublicInbox::Admin;
use PublicInbox::TestCommon;
my $PI_TEST_VERSION = $ENV{PI_TEST_VERSION} || 2;
require_git('2.6') if $PI_TEST_VERSION == 2;
require_mods(qw(DBD::SQLite));
+my $have_xapian_compact = which($ENV{XAPIAN_COMPACT} || 'xapian-compact');
my $mime = PublicInbox::Eml->new(<<'EOF');
From: a@example.com
hello world
EOF
-sub import_index_incremental {
+my $import_index_incremental = sub {
my ($v, $level, $mime) = @_;
+ my $err = '';
my $this = "pi-$v-$level-indexlevels";
my ($tmpdir, $for_destroy) = tmpdir();
local $ENV{PI_CONFIG} = "$tmpdir/config";
$im->done;
# index master (required for v1)
- ok(run_script([qw(-index -j0), $ibx->{inboxdir}, "-L$level"]),
- 'index master OK');
+ my @cmd = (qw(-index -j0), $ibx->{inboxdir}, "-L$level");
+ push @cmd, '-c' if $have_xapian_compact;
+ ok(run_script(\@cmd, undef, { 2 => \$err }), 'index master');
my $ro_master = PublicInbox::Inbox->new({
inboxdir => $ibx->{inboxdir},
indexlevel => $level
is($msgs->[0]->{mid}, 'm@1', 'first message in master indexed');
# clone
- my @cmd = (qw(git clone --mirror -q));
+ @cmd = (qw(git clone --mirror -q));
my $mirror = "$tmpdir/mirror-$v";
if ($v == 1) {
push @cmd, $ibx->{inboxdir}, $mirror;
is(PublicInbox::Admin::detect_indexlevel($ro_mirror), $level,
'indexlevel detectable by Admin '.$v.$level);
-}
+
+ SKIP: {
+ skip 'xapian-compact missing', 1 if !$have_xapian_compact;
+ my $cmd = [ qw(-compact), $mirror ];
+ ok(run_script($cmd, undef, { 2 => \$err}), "compact $level");
+ }
+};
# we can probably cull some other tests
-import_index_incremental($PI_TEST_VERSION, 'basic', $mime);
+$import_index_incremental->($PI_TEST_VERSION, 'basic', $mime);
SKIP: {
require PublicInbox::Search;
PublicInbox::Search::load_xapian() or
skip('Xapian perl binding missing', 2);
foreach my $l (qw(medium full)) {
- import_index_incremental($PI_TEST_VERSION, $l, $mime);
+ $import_index_incremental->($PI_TEST_VERSION, $l, $mime);
}
}