]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ExtSearchIdx.pm
extindex: guard against buggy unrefs
[public-inbox.git] / lib / PublicInbox / ExtSearchIdx.pm
index 40489eab4c6668e8b1ca3fc39e6999d741b292a0..3d7a6e7d76223a47904b62cb7bef1d9b42734d03 100644 (file)
@@ -18,6 +18,7 @@ use strict;
 use v5.10.1;
 use parent qw(PublicInbox::ExtSearch PublicInbox::Lock);
 use Carp qw(croak carp);
+use Scalar::Util qw(blessed);
 use Sys::Hostname qw(hostname);
 use POSIX qw(strftime);
 use File::Glob qw(bsd_glob GLOB_NOSORT);
@@ -143,6 +144,14 @@ sub _unref_doc ($$$$$;$) {
                $smsg = $docid;
                $docid = $smsg->{num};
        }
+       if (defined($oidbin) && defined($xnum) && blessed($ibx) && $ibx->over) {
+               my $smsg = $ibx->over->get_art($xnum);
+               if ($smsg && pack('H*', $smsg->{blob}) eq $oidbin) {
+                       carp("BUG: (non-fatal) ".$ibx->eidx_key.
+                               " #$xnum $smsg->{blob} still valid");
+                       return;
+               }
+       }
        my $s = 'DELETE FROM xref3 WHERE oidbin = ?';
        $s .= ' AND ibx_id = ?' if defined($ibx);
        $s .= ' AND xnum = ?' if defined($xnum);
@@ -595,11 +604,11 @@ sub _reindex_oid { # git->cat_async callback
                my $oidbin = pack('H*', $expect_oid);
                my $remain = _unref_doc($sync, $docid, undef, undef, $oidbin);
                if ($remain == 0) {
-                       warn "W: #$docid gone or corrupted\n";
+                       warn "W: #$docid ($oid) gone or corrupt\n";
                } elsif (my $next_oid = $req->{xr3r}->[++$req->{ix}]->[2]) {
                        $self->git->cat_async($next_oid, \&_reindex_oid, $req);
                } else {
-                       warn "BUG: #$docid gone (UNEXPECTED)\n";
+                       warn "BUG: #$docid ($oid) gone (UNEXPECTED)\n";
                }
                return;
        }
@@ -754,9 +763,8 @@ sub prep_id2pos ($) {
 
 sub eidxq_process ($$) { # for reindexing
        my ($self, $sync) = @_;
-       return unless $self->{cfg};
-
-       return unless eidxq_lock_acquire($self);
+       local $self->{current_info} = 'eidxq process';
+       return unless ($self->{cfg} && eidxq_lock_acquire($self));
        my $dbh = $self->{oidx}->dbh;
        my $tot = $dbh->selectrow_array('SELECT COUNT(*) FROM eidxq') or return;
        ${$sync->{nr}} = 0;