user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
From: Eric Wong <e@80x24.org>
To: meta@public-inbox.org
Subject: [PATCH 1/2] search: reopen and retry on updated databases
Date: Sun, 19 Jun 2016 10:20:51 +0000	[thread overview]
Message-ID: <20160619102052.1324-2-e@80x24.org> (raw)
In-Reply-To: <20160619102052.1324-1-e@80x24.org>

This seems like a nasty thing which breaks downloads of
large mailboxes.
---
 lib/PublicInbox/Search.pm | 35 ++++++++++++++++++++++-------------
 1 file changed, 22 insertions(+), 13 deletions(-)

diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm
index d9fbc36..856c8c1 100644
--- a/lib/PublicInbox/Search.pm
+++ b/lib/PublicInbox/Search.pm
@@ -97,7 +97,7 @@ sub query {
 		$opts->{relevance} = 1 unless exists $opts->{relevance};
 	}
 
-	$self->do_enquire($query, $opts);
+	_do_enquire($self, $query, $opts);
 }
 
 sub get_thread {
@@ -111,10 +111,26 @@ sub get_thread {
 	my $query = Search::Xapian::Query->new(OP_OR, $qtid, $qsub);
 	$opts ||= {};
 	$opts->{limit} ||= 1000;
-	$self->do_enquire($query, $opts);
+	_do_enquire($self, $query, $opts);
 }
 
-sub do_enquire {
+sub _do_enquire {
+	my ($self, $query, $opts) = @_;
+	my $ret;
+	for (1..10) {
+		eval { $ret = _enquire_once($self, $query, $opts) };
+		return $ret unless $@;
+		# Exception: The revision being read has been discarded -
+		# you should call Xapian::Database::reopen()
+		if (index($@, 'Xapian::Database::reopen') >= 0) {
+			reopen($self);
+		} else {
+			die $@;
+		}
+	}
+}
+
+sub _enquire_once {
 	my ($self, $query, $opts) = @_;
 	my $enquire = $self->enquire;
 	if (defined $query) {
@@ -127,6 +143,8 @@ sub do_enquire {
         my $desc = !$opts->{asc};
 	if ($opts->{relevance}) {
 		$enquire->set_sort_by_relevance_then_value(TS, $desc);
+	} elsif ($opts->{num}) {
+		$enquire->set_sort_by_value(NUM, 0);
 	} else {
 		$enquire->set_sort_by_value_then_relevance(TS, $desc);
 	}
@@ -186,21 +204,12 @@ sub num_range_processor {
 # only used for NNTP server
 sub query_xover {
 	my ($self, $beg, $end, $offset) = @_;
-	my $enquire = $self->enquire;
 	my $qp = Search::Xapian::QueryParser->new;
 	$qp->set_database($self->{xdb});
 	$qp->add_valuerangeprocessor($self->num_range_processor);
 	my $query = $qp->parse_query("$beg..$end", QP_FLAGS);
-	$query = Search::Xapian::Query->new(OP_AND, $mail_query, $query);
-	$enquire->set_query($query);
-	$enquire->set_sort_by_value(NUM, 0);
-	my $limit = 200;
-	my $mset = $enquire->get_mset($offset, $limit);
-	my @msgs = map {
-		PublicInbox::SearchMsg->load_doc($_->get_document);
-	} $mset->items;
 
-	{ total => $mset->get_matches_estimated, msgs => \@msgs }
+	_do_enquire($self, $query, {num => 1, limit => 200, offset => $offset});
 }
 
 sub lookup_message {

  reply	other threads:[~2016-06-19 10:20 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-19 10:20 [PATCH 0/2] robustness improvements Eric Wong
2016-06-19 10:20 ` Eric Wong [this message]
2016-06-19 10:20 ` [PATCH 2/2] examples/*@.service: wait one day for graceful shutdown Eric Wong
2016-06-19 11:55 ` [PATCH 0/2] robustness improvements Eric Wong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://public-inbox.org/README

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160619102052.1324-2-e@80x24.org \
    --to=e@80x24.org \
    --cc=meta@public-inbox.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).