]> Sergey Matveev's repositories - public-inbox.git/blobdiff - script/public-inbox-index
index: v2: --sequential-shard option
[public-inbox.git] / script / public-inbox-index
index 2e1934b0833110d58ca0b2ccaba47cd6249419ff..be518134ceb29d8a2dbad565f1e7f1e983325641 100755 (executable)
@@ -14,9 +14,10 @@ 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 rethread 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, sync => 1 };
+GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i prune sync!
+               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 >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
 
@@ -24,6 +25,9 @@ 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;
@@ -43,6 +47,15 @@ if (my $bs = $opt->{batchsize} // $cfg->{lc('publicInbox.indexBatchSize')}) {
        $PublicInbox::SearchIdx::BATCH_BYTES = $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}
@@ -59,6 +72,15 @@ for my $ibx (@ibxs) {
        if ($opt->{compact} >= 2) {
                PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt);
        }
-       PublicInbox::Admin::index_inbox($ibx, undef, $opt);
+       $ibx->{-no_sync} = 1 if !$opt->{sync};
+
+       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);
        PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt) if $compact_opt;
 }