diff options
author | Robin Houston <robin.houston@gmail.com> | 2012-01-12 16:41:08 +0000 |
---|---|---|
committer | Robin Houston <robin.houston@gmail.com> | 2012-01-12 16:41:08 +0000 |
commit | 0aafbd4a25b5c4c0edbd87c2224dcdd18388ede5 (patch) | |
tree | 65d6cc3949216cd7240b26b3aa2cd956fb6bcd04 | |
parent | 50da9903f9a390fa5c5b32b9af889f13b2954030 (diff) |
Retry if we get a DatabaseModifiedError from Xapian
-rw-r--r-- | vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb index 70605ad04..c086c8125 100644 --- a/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb +++ b/vendor/plugins/acts_as_xapian/lib/acts_as_xapian.rb @@ -248,6 +248,8 @@ module ActsAsXapian end end + MSET_MAX_TRIES = 5 + MSET_MAX_DELAY = 5 # Set self.query before calling this def initialize_query(options) #raise options.to_yaml @@ -278,7 +280,28 @@ module ActsAsXapian ActsAsXapian.enquire.collapse_key = value end - self.matches = ActsAsXapian.enquire.mset(offset, limit, 100) + tries = 0 + delay = 1 + begin + self.matches = ActsAsXapian.enquire.mset(offset, limit, 100) + rescue IOError => e + if e.message =~ /DatabaseModifiedError: / + # This should be a transient error, so back off and try again, up to a point + if tries > MAX_TRIES + raise "Received DatabaseModifiedError from Xapian even after retrying #{MAX_TRIES} times" + else + sleep delay + end + tries += 1 + delay *= 2 + delay = MAX_DELAY if delay > MAX_DELAY + + @@db.reopen() + retry + else + raise + end + end self.cached_results = nil } end |