- delete($ibx->{$_}) for (qw(mm over search)); # cleanup
- process_queue(\@q, $cb, $max, $opt);
- commit_changes($ibx, $tmp, $opt);
- });
+ # fine-grained locking if we prepare for reindex
+ if (!$opt->{-coarse_lock}) {
+ prepare_reindex($ibx, $im, $opt);
+ $im->lock_release;
+ }
+
+ $ibx->cleanup;
+ process_queue($queue, $cb, $opt);
+ $im->lock_acquire if !$opt->{-coarse_lock};
+ commit_changes($ibx, $im, $tmp, $opt);
+}
+
+sub run {
+ my ($ibx, $task, $opt) = @_; # task = 'cpdb' or 'compact'
+ my $cb = \&$task;
+ 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} && $ibx->search;
+
+ if (!$opt->{-coarse_lock}) {
+ # per-epoch ranges for v2
+ # v1:{ from => $OID }, v2:{ from => [ $OID, $OID, $OID ] } }
+ $opt->{reindex} = { from => $ibx->version == 1 ? '' : [] };
+ PublicInbox::SearchIdx::load_xapian_writable();
+ }
+
+ local %SIG = %SIG;
+ setup_signals();
+ $ibx->umask_prepare;
+ $ibx->with_umask(\&_run, $ibx, $cb, $opt);