--- /dev/null
+Return-Path: <notmuch@kismala.com>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id A8A206DE01F7\r
+ for <notmuch@notmuchmail.org>; Tue, 3 May 2016 08:34:03 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.927\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.927 tagged_above=-999 required=5 tests=[AWL=0.927]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id OEdat0b8IKPl for <notmuch@notmuchmail.org>;\r
+ Tue, 3 May 2016 08:33:53 -0700 (PDT)\r
+X-Greylist: delayed 1480 seconds by postgrey-1.35 at arlo;\r
+ Tue, 03 May 2016 08:33:53 PDT\r
+Received: from imarko.xen.prgmr.com (imarko.xen.prgmr.com [71.19.158.228])\r
+ by arlo.cworth.org (Postfix) with ESMTP id CB0D76DE00DF\r
+ for <notmuch@notmuchmail.org>; Tue, 3 May 2016 08:33:53 -0700 (PDT)\r
+Received: from localhost ([127.0.0.1] helo=zsu.kismala.com)\r
+ by imarko.xen.prgmr.com with esmtp (Exim 4.85)\r
+ (envelope-from <notmuch@kismala.com>) id 1axbwm-0002Vu-HY\r
+ for notmuch@notmuchmail.org; Tue, 03 May 2016 08:09:12 -0700\r
+From: Istvan Marko <notmuch@kismala.com>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH] Use the Xapian::DB_RETRY_LOCK flag when available\r
+User-Agent: Notmuch/0.21+69~gd27d908 (http://notmuchmail.org) Emacs/25.0.92.2\r
+ (x86_64-unknown-linux-gnu)\r
+Date: Tue, 03 May 2016 08:09:12 -0700\r
+Message-ID: <m38tzr2n6v.fsf@zsu.kismala.com>\r
+MIME-Version: 1.0\r
+Content-Type: text/plain\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.20\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Tue, 03 May 2016 15:34:03 -0000\r
+\r
+Xapian 1.3 has introduced the DB_RETRY_LOCK flag (Xapian bug\r
+275). Detect it in configure and use it if available. With this flag\r
+commands that need the write lock will wait for their turn instead of\r
+aborting when it's not immediately available.\r
+---\r
+ configure | 25 ++++++++++++++++++++++++-\r
+ lib/database.cc | 5 +++++\r
+ 2 files changed, 29 insertions(+), 1 deletion(-)\r
+\r
+diff --git a/configure b/configure\r
+index 6231d2b..0c1d5bc 100755\r
+--- a/configure\r
++++ b/configure\r
+@@ -371,6 +371,21 @@ if [ ${have_xapian} = "1" ]; then\r
+ esac\r
+ fi\r
+ \r
++# DB_RETRY_LOCK is only supported on Xapian > 1.3.2\r
++have_xapian_db_retry_lock=0\r
++if [ ${have_xapian} = "1" ]; then\r
++ printf "Checking for Xapian lock retry support... "\r
++ case "${xapian_version}" in\r
++ 0.*|1.[012].*|1.3.[0-2])\r
++ printf "No (only available with Xapian > 1.3.2).\n" ;;\r
++ [1-9]*.[0-9]*.[0-9]*)\r
++ have_xapian_db_retry_lock=1\r
++ printf "Yes.\n" ;;\r
++ *)\r
++ printf "Unknown version.\n" ;;\r
++ esac\r
++fi\r
++\r
+ default_xapian_backend=""\r
+ if [ ${have_xapian} = "1" ]; then\r
+ printf "Testing default Xapian backend... "\r
+@@ -998,6 +1013,9 @@ HAVE_D_TYPE = ${have_d_type}\r
+ # Whether the Xapian version in use supports compaction\r
+ HAVE_XAPIAN_COMPACT = ${have_xapian_compact}\r
+ \r
++# Whether the Xapian version in use supports DB_RETRY_LOCK\r
++HAVE_XAPIAN_DB_RETRY_LOCK = ${have_xapian_db_retry_lock}\r
++\r
+ # Whether the getpwuid_r function is standards-compliant\r
+ # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS\r
+ # to enable the standards-compliant version -- needed for Solaris)\r
+@@ -1072,6 +1090,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+ -DSTD_GETPWUID=\$(STD_GETPWUID) \\\r
+ -DSTD_ASCTIME=\$(STD_ASCTIME) \\\r
+ -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\\r
++ -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK) \\\r
+ -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
+ \r
+ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+@@ -1086,6 +1105,7 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS) \\\r
+ -DSTD_GETPWUID=\$(STD_GETPWUID) \\\r
+ -DSTD_ASCTIME=\$(STD_ASCTIME) \\\r
+ -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT) \\\r
++ -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK) \\\r
+ -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)\r
+ \r
+ CONFIGURE_LDFLAGS = \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS)\r
+@@ -1097,7 +1117,10 @@ cat > sh.config <<EOF\r
+ # script of notmuch.\r
+ \r
+ # Whether the Xapian version in use supports compaction\r
+-NOTMUCH_HAVE_XAPIAN_COMPACT=${have_xapian_compact}\r
++NOTMUCH_HAVE_XAPIAN_ =${have_xapian_compact}\r
++\r
++# Whether the Xapian version in use supports DB_RETRY_LOCK\r
++NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK=${have_xapian_db_retry_lock}\r
+ \r
+ # Which backend will Xapian use by default?\r
+ NOTMUCH_DEFAULT_XAPIAN_BACKEND=${default_xapian_backend}\r
+diff --git a/lib/database.cc b/lib/database.cc\r
+index c8c5e26..4b503a2 100644\r
+--- a/lib/database.cc\r
++++ b/lib/database.cc\r
+@@ -929,8 +929,13 @@ notmuch_database_open_verbose (const char *path,\r
+ string last_mod;\r
+ \r
+ if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {\r
++ #if HAVE_XAPIAN_DB_RETRY_LOCK\r
++ notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,\r
++ Xapian::DB_CREATE_OR_OPEN|Xapian::DB_RETRY_LOCK);\r
++ #else\r
+ notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,\r
+ Xapian::DB_CREATE_OR_OPEN);\r
++ #endif\r
+ } else {\r
+ notmuch->xapian_db = new Xapian::Database (xapian_path);\r
+ }\r
+-- \r
+2.4.10\r
+\r
+\r
+-- \r
+ Istvan\r