about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2021-10-16 01:41:34 +0000
committerEric Wong <e@80x24.org>2021-10-16 01:43:08 +0000
commit6af8612cd3ae255da7cba18d24c2b7e8a9af5ff6 (patch)
tree7da50c46011dc3b47cb1348ca6ff03834a9f07a5
parentbb8a6a435a4b7707e9fb0329c49671f495262016 (diff)
downloadpublic-inbox-6af8612cd3ae255da7cba18d24c2b7e8a9af5ff6.tar.gz
We can't attempt to unref messages beyond the highwater mark of
an inbox.  This bugfix was found by commit c485036d0b1ce7ed
(extindex: guard against buggy unrefs, 2021-10-14), which
actually did its intended job and guarded against a buggy unref.
-rw-r--r--lib/PublicInbox/ExtSearchIdx.pm11
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/PublicInbox/ExtSearchIdx.pm b/lib/PublicInbox/ExtSearchIdx.pm
index a08a9451..69d048fb 100644
--- a/lib/PublicInbox/ExtSearchIdx.pm
+++ b/lib/PublicInbox/ExtSearchIdx.pm
@@ -839,7 +839,7 @@ sub _unref_stale_range ($$$) {
                 $r = $sync->{self}->{oidx}->dbh->selectall_arrayref(
                         <<EOS, undef, $ibx->{-ibx_id});
 SELECT docid,xnum,oidbin FROM xref3
-WHERE ibx_id = ? AND xnum $lt_or_gt LIMIT $lim
+WHERE ibx_id = ? AND $lt_or_gt LIMIT $lim
 EOS
                 return if $sync->{quit};
                 for (@$r) { # hopefully rare, not worth optimizing:
@@ -859,7 +859,7 @@ sub _reindex_check_ibx ($$$) {
         my $opt = { limit => $slice };
         my ($beg, $end) = (1, $slice);
         my $err = sync_inbox($self, $sync, $ibx) and return;
-        my $max = $ibx->over->max;
+        my $max = $ibx->mm->num_highwater;
         $end = $max if $end > $max;
 
         # first, check if we missed any messages in target $ibx
@@ -869,7 +869,7 @@ sub _reindex_check_ibx ($$$) {
         local $sync->{-regen_fmt} = "$ekey checking %u/$max\n";
         ${$sync->{nr}} = 0;
         my $fast = $sync->{-opt}->{fast};
-        my $dsu; # _unref_stale_range (< $lo) called
+        my $usr; # _unref_stale_range (< $lo) called
         my ($lo, $hi);
         while (scalar(@{$msgs = $ibx->over->query_xover($beg, $end, $opt)})) {
                 ${$sync->{nr}} = $beg;
@@ -880,7 +880,7 @@ sub _reindex_check_ibx ($$$) {
                         reindex_checkpoint($self, $sync); # release lock
                 }
                 ($lo, $hi) = ($msgs->[0]->{num}, $msgs->[-1]->{num});
-                $dsu //= _unref_stale_range($sync, $ibx, "< $lo");
+                $usr //= _unref_stale_range($sync, $ibx, "xnum < $lo");
                 my $x3a = $self->{oidx}->dbh->selectall_arrayref(
                         <<"", undef, $ibx_id, $lo, $hi);
 SELECT xnum,oidbin,docid FROM xref3 WHERE
@@ -921,7 +921,8 @@ ibx_id = ? AND xnum >= ? AND xnum <= ?
                         }
                 }
         }
-        _unref_stale_range($sync, $ibx, "> $hi") if defined($hi);
+        defined($hi) and ($hi < $max) and
+                _unref_stale_range($sync, $ibx, "xnum > $hi AND xnum <= $max");
 }
 
 sub _reindex_inbox ($$$) {