unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Istvan Marko <notmuch@kismala.com>
To: notmuch@notmuchmail.org
Subject: [PATCH] Use the Xapian::DB_RETRY_LOCK flag when available
Date: Tue, 03 May 2016 08:09:12 -0700	[thread overview]
Message-ID: <m38tzr2n6v.fsf@zsu.kismala.com> (raw)

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.
---
 configure       | 25 ++++++++++++++++++++++++-
 lib/database.cc |  5 +++++
 2 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 6231d2b..0c1d5bc 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)
@@ -1097,7 +1117,10 @@ cat > sh.config <<EOF
 # script of notmuch.
 
 # Whether the Xapian version in use supports compaction
-NOTMUCH_HAVE_XAPIAN_COMPACT=${have_xapian_compact}
+NOTMUCH_HAVE_XAPIAN_  =${have_xapian_compact}
+
+# Whether the Xapian version in use supports DB_RETRY_LOCK
+NOTMUCH_HAVE_XAPIAN_DB_RETRY_LOCK=${have_xapian_db_retry_lock}
 
 # Which backend will Xapian use by default?
 NOTMUCH_DEFAULT_XAPIAN_BACKEND=${default_xapian_backend}
diff --git a/lib/database.cc b/lib/database.cc
index c8c5e26..4b503a2 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -929,8 +929,13 @@ notmuch_database_open_verbose (const char *path,
 	string last_mod;
 
 	if (mode == NOTMUCH_DATABASE_MODE_READ_WRITE) {
+	    #if HAVE_XAPIAN_DB_RETRY_LOCK
+	    notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
+							       Xapian::DB_CREATE_OR_OPEN|Xapian::DB_RETRY_LOCK);
+	    #else
 	    notmuch->xapian_db = new Xapian::WritableDatabase (xapian_path,
 							       Xapian::DB_CREATE_OR_OPEN);
+	    #endif
 	} else {
 	    notmuch->xapian_db = new Xapian::Database (xapian_path);
 	}
-- 
2.4.10


-- 
	Istvan

             reply	other threads:[~2016-05-03 15:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-03 15:09 Istvan Marko [this message]
2016-05-03 16:31 ` [PATCH] Use the Xapian::DB_RETRY_LOCK flag when available Jani Nikula
2016-05-03 19:12   ` [PATCH v2] " Istvan Marko
2016-05-05 10:33     ` David Bremner
2016-06-04 12:29     ` v3 of DB_RETRY_LOCK David Bremner
2016-06-04 12:29       ` [PATCH 1/4] Use the Xapian::DB_RETRY_LOCK flag when available David Bremner
2016-06-04 12:29       ` [PATCH 2/4] test: factor out some boilerplate from C tests David Bremner
2016-06-04 12:37         ` [PATCH] fixup! " David Bremner
2016-06-14  0:57         ` [PATCH 2/4] " David Bremner
2016-06-04 12:29       ` [PATCH 3/4] test: initial tests for locking retry David Bremner
2016-06-04 12:29       ` [PATCH 4/4] lib: add built_with handling for XAPIAN_DB_RETRY_LOCK David Bremner
2016-06-04 12:38         ` [PATCH] fixup! " David Bremner
2016-05-03 19:01 ` [PATCH] Use the Xapian::DB_RETRY_LOCK flag when available David Bremner

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=m38tzr2n6v.fsf@zsu.kismala.com \
    --to=notmuch@kismala.com \
    --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).