about summary refs log tree commit homepage
path: root/lib
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2020-12-15 02:02:21 +0000
committerEric Wong <e@80x24.org>2020-12-17 19:13:12 +0000
commitc014cd93de1f2c73348db0e6531f93cf0f1be60f (patch)
tree96777ae7fa13cb470cb09fe928bafce5a672670f /lib
parent35cca56ecb10649f7935d601ef513162e38cb3b8 (diff)
downloadpublic-inbox-c014cd93de1f2c73348db0e6531f93cf0f1be60f.tar.gz
--reindex can take many hours or days, ensure we release
locks according to --batch-size so automated fetch+index
jobs can write new data to indices while we update old data.
Diffstat (limited to 'lib')
-rw-r--r--lib/PublicInbox/ExtSearchIdx.pm19
-rw-r--r--lib/PublicInbox/V2Writable.pm2
2 files changed, 7 insertions, 14 deletions
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index f29a84e3..3b021a1b 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -404,7 +404,7 @@ sub _reindex_finalize ($$$) {
         my $orig_smsg = $req->{orig_smsg} // die 'BUG: no {orig_smsg}';
         my $docid = $smsg->{num} = $orig_smsg->{num};
         $self->{oidx}->add_overview($eml, $smsg); # may rethread
-        $self->{transact_bytes} += $smsg->{bytes};
+        check_batch_limit({ %$sync, new_smsg => $smsg });
         if ($nr == 1) { # likely, all good
                 $self->idx_shard($docid)->shard_reindex_docid($docid);
                 return;
@@ -537,18 +537,8 @@ sub eidxq_process ($$) { # for reindexing
                         warn "E: #$docid does not exist in over\n";
                 }
                 $del->execute($docid);
+                ++${$sync->{nr}};
 
-                my $cur = ++${$sync->{nr}};
-
-                # shards flush on their own, just don't queue up too many
-                # deletes
-                if ($self->{transact_bytes} >= $self->{batch_bytes}) {
-                        $self->git->async_wait_all;
-                        $self->{oidx}->commit_lazy;
-                        $self->{oidx}->begin_lazy;
-                        $pr->("reindexed $cur/$tot\n") if $pr;
-                        $self->{transact_bytes} = 0;
-                }
                 # this is only for SIGUSR1, shards do their own accounting:
                 reindex_checkpoint($self, $sync) if ${$sync->{need_checkpoint}};
         }
@@ -709,7 +699,10 @@ sub eidx_sync { # main entry point
         for my $ibx (@{$self->{ibx_list}}) {
                 $ibx->{-ibx_id} //= $self->{oidx}->ibx_id($ibx->eidx_key);
         }
-        eidx_reindex($self, $sync) if delete($opt->{reindex});
+        if (delete($opt->{reindex})) {
+                $sync->{checkpoint_unlocks} = 1;
+                eidx_reindex($self, $sync);
+        }
 
         # don't use $_ here, it'll get clobbered by reindex_checkpoint
         for my $ibx (@{$self->{ibx_list}}) {
diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 572eb418..97dbf328 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -884,7 +884,7 @@ sub reindex_checkpoint ($$) {
         my $mm_tmp = $sync->{mm_tmp};
         $mm_tmp->atfork_prepare if $mm_tmp;
         die 'BUG: {im} during reindex' if $self->{im};
-        if ($self->{ibx_map}) {
+        if ($self->{ibx_map} && !$sync->{checkpoint_unlocks}) {
                 checkpoint($self, 1); # no need to release lock on pure index
         } else {
                 $self->done; # release lock