]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-index
index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size
[public-inbox.git] / script / public-inbox-index
index 0018668e6bd0d95f4d2b4c6a3fa2fdd5b0972d07..e2bca16e92510221a0f95998277be6351dcac6f8 100755 (executable)
@@ -14,16 +14,21 @@ PublicInbox::Admin::require_or_die('-index');
 use PublicInbox::Xapcmd;
 
 my $compact_opt;
-my $opt = { quiet => -1, compact => 0, maxsize => undef };
-GetOptions($opt, qw(verbose|v+ reindex compact|c+ jobs|j=i prune
-               indexlevel|L=s maxsize|max-size=s batchsize|batch-size=s))
+my $opt = { quiet => -1, compact => 0, maxsize => undef, fsync => 1 };
+GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i prune
+               fsync|sync! xapianonly|xapian-only
+               indexlevel|L=s maxsize|max-size=s batchsize|batch-size=s
+               sequentialshard|seq-shard|sequential-shard))
        or die "bad command-line args\n$usage";
-die "--jobs must be positive\n" if defined $opt->{jobs} && $opt->{jobs} <= 0;
+die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
 
 if ($opt->{compact}) {
        require PublicInbox::Xapcmd;
        PublicInbox::Xapcmd::check_compact();
        $compact_opt = { -coarse_lock => 1, compact => 1 };
+       if (defined(my $jobs = $opt->{jobs})) {
+               $compact_opt->{jobs} = $jobs;
+       }
 }
 
 my $cfg = PublicInbox::Config->new;
@@ -37,17 +42,31 @@ if (defined $max_size) {
                die "`publicInbox.indexMaxSize=$max_size' not parsed\n";
 }
 
-if (my $bs = $opt->{batchsize} // $cfg->{lc('publicInbox.indexBatchSize')}) {
+my $bs = $opt->{batchsize} // $cfg->{lc('publicInbox.indexBatchSize')};
+if (defined $bs) {
        PublicInbox::Admin::parse_unsigned(\$bs) or
                die "`publicInbox.indexBatchSize=$bs' not parsed\n";
-       $PublicInbox::SearchIdx::BATCH_BYTES = $bs;
+}
+local $PublicInbox::SearchIdx::BATCH_BYTES = $bs if defined($bs);
+
+# out-of-the-box builds of Xapian 1.4.x are still limited to 32-bit
+# https://getting-started-with-xapian.readthedocs.io/en/latest/concepts/indexing/limitations.html
+local $ENV{XAPIAN_FLUSH_THRESHOLD} ||= '4294967295' if defined($bs);
+
+my $s = $opt->{sequentialshard} //
+                       $cfg->{lc('publicInbox.indexSequentialShard')};
+if (defined $s) {
+       my $v = $cfg->git_bool($s);
+       defined($v) or
+               die "`publicInbox.indexSequentialShard=$s' not boolean\n";
+       $opt->{sequentialshard} = $v;
 }
 
 my $mods = {};
 foreach my $ibx (@ibxs) {
        # XXX: users can shoot themselves in the foot, with opt->{indexlevel}
-       $ibx->{indexlevel} //= $opt->{indexlevel} //
-                       PublicInbox::Admin::detect_indexlevel($ibx);
+       $ibx->{indexlevel} //= $opt->{indexlevel} // ($opt->{xapianonly} ?
+                       'full' : PublicInbox::Admin::detect_indexlevel($ibx));
        $ibx->{index_max_size} = $max_size;
        PublicInbox::Admin::scan_ibx_modules($mods, $ibx);
 }
@@ -59,6 +78,18 @@ for my $ibx (@ibxs) {
        if ($opt->{compact} >= 2) {
                PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt);
        }
-       PublicInbox::Admin::index_inbox($ibx, undef, $opt);
-       PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt) if $compact_opt;
+       $ibx->{-no_fsync} = 1 if !$opt->{fsync};
+
+       my $ibx_opt = $opt;
+       if (defined(my $s = $ibx->{indexsequentialshard})) {
+               defined(my $v = $cfg->git_bool($s)) or die <<EOL;
+publicInbox.$ibx->{name}.indexSequentialShard not boolean
+EOL
+               $ibx_opt = { %$opt, sequentialshard => $v };
+       }
+       PublicInbox::Admin::index_inbox($ibx, undef, $ibx_opt);
+       if ($compact_opt) {
+               local $compact_opt->{jobs} = 0 if $ibx_opt->{sequentialshard};
+               PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt);
+       }
 }