From: David Riebenbauer <davrieb@liegesta.at>
To: Notmuch Mailing List <notmuch@notmuchmail.org>
Subject: [PATCH 1/3] notmuch-deliver: wait for the database to become unlocked
Date: Sun, 6 Nov 2011 12:23:02 +0100 [thread overview]
Message-ID: <1320578584-6642-2-git-send-email-davrieb@liegesta.at> (raw)
In-Reply-To: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>
If notmuch-deliver just gives up on a locked database this can result
in mail bouncing.
This patch makes it wait a given time and then retry to open the
database. The wait time starts at a millisecond, and doubles every
time the database is still locked, until an absolute maximum time of
10 minutes is reached.
---
contrib/notmuch-deliver/src/main.c | 25 ++++++++++++++++++++++---
1 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/contrib/notmuch-deliver/src/main.c b/contrib/notmuch-deliver/src/main.c
index f7a4eaa..e30cbac 100644
--- a/contrib/notmuch-deliver/src/main.c
+++ b/contrib/notmuch-deliver/src/main.c
@@ -71,6 +71,9 @@
#define EX_CONFIG 78
#endif
+#define MIN_UWAIT 1000 // 1 millisecond
+#define MAX_UWAIT 600000000 // 10 minutes
+
static gboolean opt_create, opt_fatal, opt_folder, opt_version;
static gboolean opt_verbose = FALSE;
static gchar **opt_tags = NULL;
@@ -428,10 +431,26 @@ main(int argc, char **argv)
maildir = g_strdup(db_path);
g_debug("Opening notmuch database `%s'", db_path);
- db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE);
+ gint32 wait_time = 0;
+ gint32 next_wait = MIN_UWAIT;
+ while ((db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE)) == NULL) {
+ g_debug("Retrying to open database in %u microseconds", next_wait);
+ usleep(next_wait);
+
+ next_wait *= 2;
+ if (wait_time + next_wait >= MAX_UWAIT) {
+ wait_time = next_wait - MAX_UWAIT;
+ if (wait_time <= 0) {
+ g_free(db_path);
+ if (db == NULL)
+ return EX_SOFTWARE;
+ }
+ }
+
+ wait_time += next_wait;
+ }
g_free(db_path);
- if (db == NULL)
- return EX_SOFTWARE;
+
if (notmuch_database_needs_upgrade(db)) {
g_message("Upgrading database");
notmuch_database_upgrade(db, NULL, NULL);
--
1.7.7.1
next prev parent reply other threads:[~2011-11-06 12:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-06 11:23 [PATCH 0/3] notmuch-deliver: wait for database to become unlocked and test David Riebenbauer
2011-11-06 11:23 ` David Riebenbauer [this message]
2011-11-06 11:23 ` [PATCH 2/3] notmuch-deliver: test wait for database to become available David Riebenbauer
2011-11-06 11:23 ` [PATCH 3/3] notmuch-deliver: Convert test program to glib main loop David Riebenbauer
2011-11-07 1:32 ` [PATCH 0/3] notmuch-deliver: wait for database to become unlocked and test Ali Polatel
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=1320578584-6642-2-git-send-email-davrieb@liegesta.at \
--to=davrieb@liegesta.at \
--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).