[PATCH v2] Use the Xapian::DB_RETRY_LOCK flag when available

Istvan Marko notmuch at kismala.com
Tue May 3 12:12:57 PDT 2016


Xapian 1.3 has introduced the DB_RETRY_LOCK flag (Xapian bug
275). Detect it in configure and use it if available. With this flag
commands that need the write lock will wait for their turn instead of
aborting when it's not immediately available.
---

Updated based on Jani's feedback.

Regarding tests, I couldn't think of a meaningful test for this. We get
different behaviors depending on the Xapian version and if we try do
some kind of a concurrent locking test we'd really be just testing
Xapian's locking code rather than notmuch.

 configure       | 20 ++++++++++++++++++++
 lib/database.cc |  8 +++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 6231d2b..8ef96b4 100755
--- a/configure
+++ b/configure
@@ -371,6 +371,21 @@ if [ ${have_xapian} = "1" ]; then
     esac
 fi
 
+# DB_RETRY_LOCK is only supported on Xapian > 1.3.2
+have_xapian_db_retry_lock=0
+if [ ${have_xapian} = "1" ]; then
+    printf "Checking for Xapian lock retry support... "
+    case "${xapian_version}" in
+	0.*|1.[012].*|1.3.[0-2])
+	    printf "No (only available with Xapian > 1.3.2).\n" ;;
+	[1-9]*.[0-9]*.[0-9]*)
+	    have_xapian_db_retry_lock=1
+	    printf "Yes.\n" ;;
+	*)
+	    printf "Unknown version.\n" ;;
+    esac
+fi
+
 default_xapian_backend=""
 if [ ${have_xapian} = "1" ]; then
     printf "Testing default Xapian backend... "
@@ -998,6 +1013,9 @@ HAVE_D_TYPE = ${have_d_type}
 # Whether the Xapian version in use supports compaction
 HAVE_XAPIAN_COMPACT = ${have_xapian_compact}
 
+# Whether the Xapian version in use supports DB_RETRY_LOCK
+HAVE_XAPIAN_DB_RETRY_LOCK = ${have_xapian_db_retry_lock}
+
 # Whether the getpwuid_r function is standards-compliant
 # (if not, then notmuch will #define _POSIX_PTHREAD_SEMANTICS
 # to enable the standards-compliant version -- needed for Solaris)
@@ -1072,6 +1090,7 @@ CONFIGURE_CFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)      \\
 		   -DSTD_GETPWUID=\$(STD_GETPWUID)                       \\
 		   -DSTD_ASCTIME=\$(STD_ASCTIME)                         \\
 		   -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)	 \\
+		   -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK) \\
 		   -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
 
 CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
@@ -1086,6 +1105,7 @@ CONFIGURE_CXXFLAGS = -DHAVE_GETLINE=\$(HAVE_GETLINE) \$(GMIME_CFLAGS)    \\
 		     -DSTD_GETPWUID=\$(STD_GETPWUID)                     \\
 		     -DSTD_ASCTIME=\$(STD_ASCTIME)                       \\
 		     -DHAVE_XAPIAN_COMPACT=\$(HAVE_XAPIAN_COMPACT)       \\
+                     -DHAVE_XAPIAN_DB_RETRY_LOCK=\$(HAVE_XAPIAN_DB_RETRY_LOCK) \\
 		     -DUTIL_BYTE_ORDER=\$(UTIL_BYTE_ORDER)
 
 CONFIGURE_LDFLAGS =  \$(GMIME_LDFLAGS) \$(TALLOC_LDFLAGS) \$(ZLIB_LDFLAGS) \$(XAPIAN_LDFLAGS)
diff --git a/lib/database.cc b/lib/database.cc
index c8c5e26..c0fcb29 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -48,6 +48,12 @@ typedef struct {
 #define STRINGIFY(s) _SUB_STRINGIFY(s)
 #define _SUB_STRINGIFY(s) #s
 
+#if HAVE_XAPIAN_DB_RETRY_LOCK
+#define DB_ACTION (Xapian::DB_CREATE_OR_OPEN | Xapian::DB_RETRY_LOCK)
+#else
+#define DB_ACTION Xapian::DB_CREATE_OR_OPEN
+#endif
+
 /* Here's the current schema for our database (for NOTMUCH_DATABASE_VERSION):
  *
  * We currently have three different types of documents (mail, ghost,
@@ -930,7 +936,7 @@ notmuch_database_open_verbose (const char *path,
 
 	if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
 	    notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
-							       Xapian::DB_CREATE_OR_OPEN);
+							       DB_ACTION);
 	} else {
 	    notmuch->xapian_db = new Xapian::Database (xapian_path);
 	}
-- 
2.4.10


-- 
	Istvan


More information about the notmuch mailing list