about summary refs log tree commit homepage
path: root/lib/PublicInbox/SearchView.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-12-10 23:35:43 +0000
committerEric Wong <e@80x24.org>2016-12-10 23:44:10 +0000
commit53e8cfbe4e06e5ae6ad61fb7e9bd45804c253a72 (patch)
treed5f6566a46d847e9f807450fbe10ef1b819bb29e /lib/PublicInbox/SearchView.pm
parent71d0581a309ca83cf3be538141435111db8ed290 (diff)
downloadpublic-inbox-53e8cfbe4e06e5ae6ad61fb7e9bd45804c253a72.tar.gz
In addition to needing to retry enquire queries, we also need
to protect document loading from the Xapian DB and retry on
modification, as it seems to throw the same errors.

Checking the $@ ref for Search::Xapian::DatabaseModifiedError
is actually in the test suite for both the XS and SWIG Xapian
bindings, so we should be good as far as forward/backwards
compatibility.
Diffstat (limited to 'lib/PublicInbox/SearchView.pm')
-rw-r--r--lib/PublicInbox/SearchView.pm39
1 files changed, 29 insertions, 10 deletions
diff --git a/lib/PublicInbox/SearchView.pm b/lib/PublicInbox/SearchView.pm
index 6af151a4..50a2c01c 100644
--- a/lib/PublicInbox/SearchView.pm
+++ b/lib/PublicInbox/SearchView.pm
@@ -59,6 +59,17 @@ sub sres_top_html {
         PublicInbox::WwwStream->response($ctx, $code, $cb);
 }
 
+# allow undef for individual doc loads...
+sub load_doc_retry {
+        my ($srch, $mitem) = @_;
+
+        eval {
+                $srch->retry_reopen(sub {
+                        PublicInbox::SearchMsg->load_doc($mitem->get_document)
+                });
+        }
+}
+
 # display non-threaded search results similar to what users expect from
 # regular WWW search engines:
 sub mset_summary {
@@ -68,10 +79,18 @@ sub mset_summary {
         my $pad = length("$total");
         my $pfx = ' ' x $pad;
         my $res = \($ctx->{-html_tip});
+        my $srch = $ctx->{srch};
         foreach my $m ($mset->items) {
                 my $rank = sprintf("%${pad}d", $m->get_rank + 1);
                 my $pct = $m->get_percent;
-                my $smsg = PublicInbox::SearchMsg->load_doc($m->get_document);
+                my $smsg = load_doc_retry($srch, $m);
+                unless ($smsg) {
+                        eval {
+                                $m = "$m ".$m->get_docid . " expired\n";
+                                $ctx->{env}->{'psgi.errors'}->print($m);
+                        };
+                        next;
+                }
                 my $s = ascii_html($smsg->subject);
                 my $f = ascii_html($smsg->from_name);
                 my $ts = PublicInbox::View::fmt_ts($smsg->ts);
@@ -145,14 +164,14 @@ sub search_nav_bot {
 sub mset_thread {
         my ($ctx, $mset, $q) = @_;
         my %pct;
-        my @m = map {
+        my $msgs = $ctx->{srch}->retry_reopen(sub { [ map {
                 my $i = $_;
-                my $m = PublicInbox::SearchMsg->load_doc($i->get_document);
-                $pct{$m->mid} = $i->get_percent;
-                $m;
-        } ($mset->items);
+                my $smsg = PublicInbox::SearchMsg->load_doc($i->get_document);
+                $pct{$smsg->mid} = $i->get_percent;
+                $smsg;
+        } ($mset->items) ]});
 
-        my $th = PublicInbox::SearchThread->new(\@m);
+        my $th = PublicInbox::SearchThread->new($msgs);
         $th->thread;
         if ($q->{r}) { # order by relevance
                 $th->order(sub {
@@ -175,12 +194,11 @@ sub mset_thread {
         $ctx->{prev_attr} = '';
         $ctx->{prev_level} = 0;
         $ctx->{seen} = {};
-        $ctx->{s_nr} = scalar(@m).'+ results';
+        $ctx->{s_nr} = scalar(@$msgs).'+ results';
 
         PublicInbox::View::walk_thread($th, $ctx,
                 *PublicInbox::View::pre_thread);
 
-        my $msgs = \@m;
         my $mime;
         sub {
                 return unless $msgs;
@@ -217,9 +235,10 @@ sub adump {
         my $ibx = $ctx->{-inbox};
         my @items = $mset->items;
         $ctx->{search_query} = $q;
+        my $srch = $ctx->{srch};
         PublicInbox::WwwAtomStream->response($ctx, 200, sub {
                 while (my $x = shift @items) {
-                        $x = PublicInbox::SearchMsg->load_doc($x->get_document);
+                        $x = load_doc_retry($srch, $x);
                         $x = $ibx->msg_by_smsg($x) and
                                         return Email::MIME->new($x);
                 }