From 53e8cfbe4e06e5ae6ad61fb7e9bd45804c253a72 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 10 Dec 2016 23:35:43 +0000 Subject: search: retry document loading from Xapian 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. --- lib/PublicInbox/Search.pm | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'lib/PublicInbox/Search.pm') diff --git a/lib/PublicInbox/Search.pm b/lib/PublicInbox/Search.pm index 5e6bfc68..24cb2667 100644 --- a/lib/PublicInbox/Search.pm +++ b/lib/PublicInbox/Search.pm @@ -166,22 +166,27 @@ sub get_thread { _do_enquire($self, $qtid, $opts); } -sub _do_enquire { - my ($self, $query, $opts) = @_; +sub retry_reopen { + my ($self, $cb) = @_; my $ret; for (1..10) { - eval { $ret = _enquire_once($self, $query, $opts) }; + eval { $ret = $cb->() }; return $ret unless $@; # Exception: The revision being read has been discarded - # you should call Xapian::Database::reopen() - if (index($@, 'Xapian::Database::reopen') >= 0) { + if (ref($@) eq 'Search::Xapian::DatabaseModifiedError') { reopen($self); } else { - die $@; + die; } } } +sub _do_enquire { + my ($self, $query, $opts) = @_; + retry_reopen($self, sub { _enquire_once($self, $query, $opts) }); +} + sub _enquire_once { my ($self, $query, $opts) = @_; my $enquire = $self->enquire; -- cgit v1.2.3-24-ge0c7