[PATCH 1/4] Use the Xapian::DB_RETRY_LOCK flag when available
[notmuch-archives.git] / f4 / eb6819fa325cc87f8cc6c479c6222c8862e508
1 Return-Path: <bremner@tethera.net>\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 arlo.cworth.org (Postfix) with ESMTP id B2A8D6DE02B5\r
6  for <notmuch@notmuchmail.org>; Sat,  4 Jun 2016 05:29:42 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -0.012\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-0.012 tagged_above=-999 required=5\r
12  tests=[AWL=-0.001, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01]\r
13  autolearn=disabled\r
14 Received: from arlo.cworth.org ([127.0.0.1])\r
15  by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
16  with ESMTP id zZofv5GO9FlM for <notmuch@notmuchmail.org>;\r
17  Sat,  4 Jun 2016 05:29:34 -0700 (PDT)\r
18 Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197])\r
19  by arlo.cworth.org (Postfix) with ESMTPS id 8CE396DE02A9\r
20  for <notmuch@notmuchmail.org>; Sat,  4 Jun 2016 05:29:34 -0700 (PDT)\r
21 Received: from remotemail by fethera.tethera.net with local (Exim 4.84)\r
22  (envelope-from <bremner@tethera.net>)\r
23  id 1b9Ahd-0004zM-T5; Sat, 04 Jun 2016 08:29:21 -0400\r
24 Received: (nullmailer pid 23491 invoked by uid 1000);\r
25  Sat, 04 Jun 2016 12:29:27 -0000\r
26 From: David Bremner <david@tethera.net>\r
27 To: Istvan Marko <notmuch@kismala.com>, Jani Nikula <jani@nikula.org>,\r
28  notmuch@notmuchmail.org\r
29 Subject: [PATCH 1/4] Use the Xapian::DB_RETRY_LOCK flag when available\r
30 Date: Sat,  4 Jun 2016 09:29:13 -0300\r
31 Message-Id: <1465043356-23420-2-git-send-email-david@tethera.net>\r
32 X-Mailer: git-send-email 2.8.1\r
33 In-Reply-To: <1465043356-23420-1-git-send-email-david@tethera.net>\r
34 References: <m3wpnb0xc6.fsf@zsu.kismala.com>\r
35  <1465043356-23420-1-git-send-email-david@tethera.net>\r
36 X-BeenThere: notmuch@notmuchmail.org\r
37 X-Mailman-Version: 2.1.20\r
38 Precedence: list\r
39 List-Id: "Use and development of the notmuch mail system."\r
40  <notmuch.notmuchmail.org>\r
41 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
42  <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
43 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
44 List-Post: <mailto:notmuch@notmuchmail.org>\r
45 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
46 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
47  <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
48 X-List-Received-Date: Sat, 04 Jun 2016 12:29:42 -0000\r
49 \r
50 From: Istvan Marko <notmuch@kismala.com>\r
51 \r
52 Xapian 1.3 has introduced the DB_RETRY_LOCK flag (Xapian bug\r
53 275). Detect it in configure and use it if available. With this flag\r
54 commands that need the write lock will wait for their turn instead of\r
55 aborting when it's not immediately available.\r
56 ---\r
57  configure       | 20 ++++++++++++++++++++\r
58  lib/database.cc |  8 +++++++-\r
59  2 files changed, 27 insertions(+), 1 deletion(-)\r
60 \r
61 diff --git a/configure b/configure\r
62 index ce1d698..e9de9c6 100755\r
63 --- a/configure\r
64 +++ b/configure\r
65 @@ -392,6 +392,22 @@ EOF\r
66      rm -f _field_processor.o _field_processor.cc\r
67  \r
68      default_xapian_backend=""\r
69 +    # DB_RETRY_LOCK is only supported on Xapian > 1.3.2\r
70 +    have_xapian_db_retry_lock=0\r
71 +    printf "Checking for Xapian lock retry support... "\r
72 +    cat>_retry.cc<<EOF\r
73 +#include <xapian.h>\r
74 +int flag = Xapian::DB_RETRY_LOCK;\r
75 +EOF\r
76 +    if ${CXX} ${CXXFLAGS_for_sh} ${xapian_cxxflags} -c _retry.cc -o _retry.o > /dev/null 2>&1\r
77 +    then\r
78 +       have_xapian_db_retry_lock=1\r
79 +       printf "Yes.\n"\r
80 +    else\r
81 +       printf "No. (optional)\n"\r
82 +    fi\r
83 +    rm -f _retry.o _retry.cc\r
84 +\r
85      printf "Testing default Xapian backend... "\r
86      cat >_default_backend.cc <<EOF\r
87  #include <xapian.h>\r
88 @@ -1022,6 +1038,9 @@ HAVE_XAPIAN_COMPACT = ${have_xapian_compact}\r
89  # Whether the Xapian version in use supports field processors\r
90  HAVE_XAPIAN_FIELD_PROCESSOR = ${have_xapian_field_processor}\r
91  \r
92 +# Whether the Xapian version in use supports DB_RETRY_LOCK\r
93 +HAVE_XAPIAN_DB_RETRY_LOCK = ${have_xapian_db_retry_lock}\r
94 +\r
95  # Whether the getpwuid_r function is standards-compliant\r
96  # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS\r
97  # to enable the standards-compliant version -- needed for Solaris)\r
98 @@ -1097,6 +1116,7 @@ COMMON_CONFIGURE_CFLAGS = \\\r
99         -DSTD_ASCTIME=\$(STD_ASCTIME)                           \\\r
100         -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)           \\\r
101         -DHAVE_XAPIAN_FIELD_PROCESSOR=\$(HAVE_XAPIAN_FIELD_PROCESSOR) \\\r
102 +       -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK) \\\r
103         -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
104  \r
105  CONFIGURE_CFLAGS = \$(COMMON_CONFIGURE_CFLAGS)\r
106 diff --git a/lib/database.cc b/lib/database.cc\r
107 index 9630000..e4f3ab5 100644\r
108 --- a/lib/database.cc\r
109 +++ b/lib/database.cc\r
110 @@ -49,6 +49,12 @@ typedef struct {\r
111  #define STRINGIFY(s) _SUB_STRINGIFY(s)\r
112  #define _SUB_STRINGIFY(s) #s\r
113  \r
114 +#if HAVE_XAPIAN_DB_RETRY_LOCK\r
115 +#define DB_ACTION (Xapian::DB_CREATE_OR_OPEN | Xapian::DB_RETRY_LOCK)\r
116 +#else\r
117 +#define DB_ACTION Xapian::DB_CREATE_OR_OPEN\r
118 +#endif\r
119 +\r
120  /* Here's the current schema for our database (for NOTMUCH_DATABASE_VERSION):\r
121   *\r
122   * We currently have three different types of documents (mail, ghost,\r
123 @@ -931,7 +937,7 @@ notmuch_database_open_verbose (const char *path,\r
124  \r
125         if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {\r
126             notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,\r
127 -                                                              Xapian::DB_CREATE_OR_OPEN);\r
128 +                                                              DB_ACTION);\r
129         } else {\r
130             notmuch->xapian_db = new Xapian::Database (xapian_path);\r
131         }\r
132 -- \r
133 2.8.1\r
134 \r