From: Jani Nikula <jani@nikula.org>
To: notmuch@notmuchmail.org
Subject: [PATCH] HACK: lib: add brute and ignorant handling of database lock errors
Date: Thu, 1 Jan 2015 20:22:03 +0200 [thread overview]
Message-ID: <1420136523-27100-1-git-send-email-jani@nikula.org> (raw)
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
reply other threads:[~2015-01-01 18:22 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1420136523-27100-1-git-send-email-jani@nikula.org \
--to=jani@nikula.org \
--cc=notmuch@notmuchmail.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://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).