]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ExtSearchIdx.pm
extsearchidx: favor 20-byte OID comparison
[public-inbox.git] / lib / PublicInbox / ExtSearchIdx.pm
index 6b29789a2ed89d33d12e654d6a95f9bbe65cc8fa..3a1856c847096f71df18ad3d6291a96422185e1a 100644 (file)
@@ -89,6 +89,7 @@ sub attach_config {
                        $self->{ibx_map}->{$ibx->eidx_key} //= do {
                                push @{$self->{ibx_active}}, $ibx;
                                push @{$self->{ibx_known}}, $ibx;
+                               $ibx;
                        }
                }
                # invalidate cache
@@ -119,9 +120,8 @@ sub apply_boost ($$) {
                                ||
                $a->[1] <=> $b->[1] # break ties with {xnum}
        } @$xr3;
-       my $top_blob = unpack('H*', $xr3->[0]->[2]);
        my $new_smsg = $req->{new_smsg};
-       return if $top_blob ne $new_smsg->{blob}; # loser
+       return if $xr3->[0]->[2] ne pack('H*', $new_smsg->{blob}); # loser
 
        # replace the old smsg with the more boosted one
        $new_smsg->{num} = $smsg->{num};
@@ -222,13 +222,16 @@ sub _blob_missing ($$) { # called when $smsg->{blob} is bad
        my $xref3 = $self->{oidx}->get_xref3($smsg->{num});
        my @keep = grep(!/:$smsg->{blob}\z/, @$xref3);
        if (@keep) {
+               warn "E: $smsg->{blob} gone, removing #$smsg->{num}\n";
                $keep[0] =~ /:([a-f0-9]{40,}+)\z/ or
                        die "BUG: xref $keep[0] has no OID";
                my $oidhex = $1;
                $self->{oidx}->remove_xref3($smsg->{num}, $smsg->{blob});
-               my $upd = $self->{oidx}->update_blob($smsg, $oidhex);
-               my $saved = $self->{oidx}->get_art($smsg->{num});
+               $self->{oidx}->update_blob($smsg, $oidhex) or warn <<EOM;
+E: #$smsg->{num} gone ($smsg->{blob} => $oidhex)
+EOM
        } else {
+               warn "E: $smsg->{blob} gone, removing #$smsg->{num}\n";
                $self->{oidx}->delete_by_num($smsg->{num});
        }
 }
@@ -688,6 +691,7 @@ sub prep_id2pos ($) {
 
 sub eidxq_process ($$) { # for reindexing
        my ($self, $sync) = @_;
+       return unless $self->{cfg};
 
        return unless eidxq_lock_acquire($self);
        my $dbh = $self->{oidx}->dbh;
@@ -882,6 +886,7 @@ sub _reindex_inbox ($$$) {
 
 sub eidx_reindex {
        my ($self, $sync) = @_;
+       return unless $self->{cfg};
 
        # acquire eidxq_lock early because full reindex takes forever
        # and incremental -extindex processes can run during our checkpoints
@@ -1305,19 +1310,11 @@ sub eidx_watch { # public-inbox-extindex --watch main loop
        };
        my $quit = PublicInbox::SearchIdx::quit_cb($sync);
        $sig->{QUIT} = $sig->{INT} = $sig->{TERM} = $quit;
-       my $sigfd = PublicInbox::Sigfd->new($sig,
-                                       $PublicInbox::Syscall::SFD_NONBLOCK);
-       @SIG{keys %$sig} = values(%$sig) if !$sigfd;
        local $self->{-watch_sync} = $sync; # for ->on_inbox_unlock
-       if (!$sigfd) {
-               # wake up every second to accept signals if we don't
-               # have signalfd or IO::KQueue:
-               PublicInbox::DS::sig_setmask($oldset);
-               PublicInbox::DS->SetLoopTimeout(1000);
-       }
        PublicInbox::DS->SetPostLoopCallback(sub { !$sync->{quit} });
        $pr->("initial scan complete, entering event loop\n") if $pr;
-       PublicInbox::DS->EventLoop; # calls InboxIdle->event_step
+       # calls InboxIdle->event_step:
+       PublicInbox::DS::event_loop($sig, $oldset);
        done($self);
 }