* [PATCH] HACK: lib: add brute and ignorant handling of database lock errors
@ 2015-01-01 18:22 Jani Nikula
0 siblings, 0 replies; only message in thread
From: Jani Nikula @ 2015-01-01 18:22 UTC (permalink / raw)
To: notmuch
From: Jani Nikula <jani.nikula@intel.com>
Instead of failing at first try, back off for an increasing number of
seconds, and only fail after three attempts.
One of my notmuch installations that gets plenty of mail hits db
locked exceptions quite often, and even more than before since I
switched to using notmuch insert. These are quite annoying in the
Emacs UI as there is virtually no error handling for tagging, and the
tag change highlighting gets confused.
This is a dirty hack, but for me it's much more preferrable to the the
db locked exceptions. With the retries and increasing back-off timeout
I hardly ever see the exceptions now.
Maybe this inspires someone to fix this for real. ;)
---
lib/database.cc | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/lib/database.cc b/lib/database.cc
index 3601f9ded307..50063c55969b 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -819,8 +819,23 @@ notmuch_database_open (const char *path,
string last_thread_id;
if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
- notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
- Xapian::DB_CREATE_OR_OPEN);
+ /*
+ * Brute and ignorant handling of database lock errors.
+ * Instead of failing at first try, back off for an
+ * increasing number of seconds.
+ */
+ for (unsigned int tries = 1; ! notmuch->xapian_db; tries++) {
+ try {
+ notmuch->xapian_db =
+ new Xapian::WritableDatabase (xapian_path,
+ Xapian::DB_CREATE_OR_OPEN);
+ } catch (const Xapian::DatabaseLockError &error) {
+ if (tries > 3)
+ throw;
+
+ sleep(tries);
+ }
+ }
} else {
notmuch->xapian_db = new Xapian::Database (xapian_path);
}
--
2.1.4
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2015-01-01 18:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-01 18:22 [PATCH] HACK: lib: add brute and ignorant handling of database lock errors Jani Nikula
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.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).