Re: [PATCH 00/17] nmbug-status: Python-3-compabitility and general refactoring
[notmuch-archives.git] / d2 / b03e95863088d3cc00088dc1fdae84aa3d2e4a
1 Return-Path: <davrieb@liegesta.at>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 85C5B431FB6\r
6         for <notmuch@notmuchmail.org>; Sun,  6 Nov 2011 04:23:10 -0800 (PST)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: 0\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]\r
12         autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id A9sXZ9LNqsDT for <notmuch@notmuchmail.org>;\r
16         Sun,  6 Nov 2011 04:23:09 -0800 (PST)\r
17 Received: from plum.liegesta.at (plum.liegesta.at [83.169.17.237])\r
18         by olra.theworths.org (Postfix) with ESMTP id B0570429E21\r
19         for <notmuch@notmuchmail.org>; Sun,  6 Nov 2011 04:23:09 -0800 (PST)\r
20 Received: from ambiguous-mid.liegesta.at (mk046207255168.a1.net\r
21         [46.207.255.168]) (Authenticated sender: davrieb)\r
22         by plum.liegesta.at (Postfix) with ESMTPA id 7FE1127B8259;\r
23         Sun,  6 Nov 2011 13:23:08 +0100 (CET)\r
24 Received: by ambiguous-mid.liegesta.at (Postfix, from userid 1000)\r
25         id 4E0E91FF1E; Sun,  6 Nov 2011 12:23:06 +0100 (CET)\r
26 From: David Riebenbauer <davrieb@liegesta.at>\r
27 To: Notmuch Mailing List <notmuch@notmuchmail.org>\r
28 Subject: [PATCH 1/3] notmuch-deliver: wait for the database to become unlocked\r
29 Date: Sun,  6 Nov 2011 12:23:02 +0100\r
30 Message-Id: <1320578584-6642-2-git-send-email-davrieb@liegesta.at>\r
31 X-Mailer: git-send-email 1.7.7.1\r
32 In-Reply-To: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>\r
33 References: <1320578584-6642-1-git-send-email-davrieb@liegesta.at>\r
34 X-BeenThere: notmuch@notmuchmail.org\r
35 X-Mailman-Version: 2.1.13\r
36 Precedence: list\r
37 List-Id: "Use and development of the notmuch mail system."\r
38         <notmuch.notmuchmail.org>\r
39 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
40         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
42 List-Post: <mailto:notmuch@notmuchmail.org>\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
44 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
45         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
46 X-List-Received-Date: Sun, 06 Nov 2011 12:23:10 -0000\r
47 \r
48 If notmuch-deliver just gives up on a locked database this can result\r
49 in mail bouncing.\r
50 \r
51 This patch makes it wait a given time and then retry to open the\r
52 database. The wait time starts at a millisecond, and doubles every\r
53 time the database is still locked, until an absolute maximum time of\r
54 10 minutes is reached.\r
55 ---\r
56  contrib/notmuch-deliver/src/main.c |   25 ++++++++++++++++++++++---\r
57  1 files changed, 22 insertions(+), 3 deletions(-)\r
58 \r
59 diff --git a/contrib/notmuch-deliver/src/main.c b/contrib/notmuch-deliver/src/main.c\r
60 index f7a4eaa..e30cbac 100644\r
61 --- a/contrib/notmuch-deliver/src/main.c\r
62 +++ b/contrib/notmuch-deliver/src/main.c\r
63 @@ -71,6 +71,9 @@\r
64  #define EX_CONFIG 78\r
65  #endif\r
66  \r
67 +#define MIN_UWAIT 1000        // 1 millisecond\r
68 +#define MAX_UWAIT 600000000   // 10 minutes\r
69 +\r
70  static gboolean opt_create, opt_fatal, opt_folder, opt_version;\r
71  static gboolean opt_verbose = FALSE;\r
72  static gchar **opt_tags = NULL;\r
73 @@ -428,10 +431,26 @@ main(int argc, char **argv)\r
74                 maildir = g_strdup(db_path);\r
75  \r
76         g_debug("Opening notmuch database `%s'", db_path);\r
77 -       db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE);\r
78 +       gint32 wait_time = 0;\r
79 +       gint32 next_wait = MIN_UWAIT;\r
80 +       while ((db = notmuch_database_open(db_path, NOTMUCH_DATABASE_MODE_READ_WRITE)) == NULL) {\r
81 +               g_debug("Retrying to open database in %u microseconds", next_wait);\r
82 +               usleep(next_wait);\r
83 +\r
84 +               next_wait *= 2;\r
85 +               if (wait_time + next_wait >= MAX_UWAIT) {\r
86 +                       wait_time = next_wait - MAX_UWAIT;\r
87 +                       if (wait_time <= 0) {\r
88 +                               g_free(db_path);\r
89 +                               if (db == NULL)\r
90 +                                       return EX_SOFTWARE;\r
91 +                       }\r
92 +               }\r
93 +\r
94 +               wait_time += next_wait;\r
95 +       }\r
96         g_free(db_path);\r
97 -       if (db == NULL)\r
98 -               return EX_SOFTWARE;\r
99 +\r
100         if (notmuch_database_needs_upgrade(db)) {\r
101                 g_message("Upgrading database");\r
102                 notmuch_database_upgrade(db, NULL, NULL);\r
103 -- \r
104 1.7.7.1\r
105 \r