unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
From: Martin Owens <doctormo@gmail.com>
To: David Bremner <david@tethera.net>
Cc: Notmuch developer list <notmuch@notmuchmail.org>
Subject: Re: Patch: Flush and Reopen
Date: Fri, 09 Sep 2011 13:55:50 -0400	[thread overview]
Message-ID: <1315590950.2435.59.camel@delen> (raw)
In-Reply-To: <87obyuj7q1.fsf@zancas.localnet>

[-- Attachment #1: Type: text/plain, Size: 541 bytes --]

On Fri, 2011-09-09 at 08:06 -0300, David Bremner wrote:
> I was also puzzled by your changes to debian/changelog. We really need
> justification for every little change introduced by the patch; this is
> another reason it helps to split things up a bit. 

That probably was unintended. See attached for the all new slimmed down
patch.

I've removed the debian control change, the changelog change, the extra
error catch in query.cc and put that cast right.

I'll leave the version of python-all for someone else.

Best Regards, Martin Owens

[-- Attachment #2: 0001-Add-flush-and-reopen-methods-to-the-libnotmuch-and-t.patch --]
[-- Type: text/x-patch, Size: 4675 bytes --]

From 981b91e9405de2daf35d30d9bbeab0dd62b15683 Mon Sep 17 00:00:00 2001
From: Martin Owens <doctormo@gmail.com>
Date: Fri, 9 Sep 2011 13:51:59 -0400
Subject: [PATCH] Add flush and reopen methods to the libnotmuch and to the python bindings. Flush allows read_write databases to commit their changes, forcing a flush to disk and reopen allows a read_only database to reread from the disk.

Also added a handler for Xapian DatabaseChangedError which occurs when the flush happens to read only databases.
---
 bindings/python/notmuch/database.py |   10 ++++++++++
 debian/libnotmuch1.symbols          |    2 ++
 lib/database.cc                     |   33 ++++++++++++++++++++++++++-------
 lib/notmuch.h                       |    8 ++++++++
 4 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/bindings/python/notmuch/database.py b/bindings/python/notmuch/database.py
index f18ca14..b6c1c31 100644
--- a/bindings/python/notmuch/database.py
+++ b/bindings/python/notmuch/database.py
@@ -432,6 +432,16 @@ class Database(object):
 
         return Query(self, querystring)
 
+    def reopen(self):
+        """Reopens a read only database, when the data has changed, this is required."""
+        if self._db is not None:
+            nmlib.notmuch_database_reopen(self._db)
+
+    def flush(self):
+        """Flushes the search database, only available when in read-write."""
+        if self._db is not None:
+            nmlib.notmuch_database_flush(self._db)
+
     def __repr__(self):
         return "'Notmuch DB " + self.get_path() + "'"
 
diff --git a/debian/libnotmuch1.symbols b/debian/libnotmuch1.symbols
index 05d86e6..7e42b0e 100644
--- a/debian/libnotmuch1.symbols
+++ b/debian/libnotmuch1.symbols
@@ -3,6 +3,7 @@ libnotmuch.so.1 libnotmuch1 #MINVER#
  notmuch_database_close@Base 0.3
  notmuch_database_create@Base 0.3
  notmuch_database_find_message@Base 0.3
+ notmuch_database_flush@Base 0.3
  notmuch_database_get_all_tags@Base 0.3
  notmuch_database_get_directory@Base 0.3
  notmuch_database_get_path@Base 0.3
@@ -10,6 +11,7 @@ libnotmuch.so.1 libnotmuch1 #MINVER#
  notmuch_database_needs_upgrade@Base 0.3
  notmuch_database_open@Base 0.3
  notmuch_database_remove_message@Base 0.3
+ notmuch_database_reopen@Base 0.3
  notmuch_database_upgrade@Base 0.3
  notmuch_directory_destroy@Base 0.3
  notmuch_directory_get_child_directories@Base 0.3
diff --git a/lib/database.cc b/lib/database.cc
index 9c2f4ec..b86bf1a 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -700,18 +700,37 @@ notmuch_database_open (const char *path,
 }
 
 void
-notmuch_database_close (notmuch_database_t *notmuch)
+notmuch_database_reopen (notmuch_database_t *notmuch)
 {
     try {
-	if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
-	    (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
+        if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
+            (static_cast <Xapian::Database *> (notmuch->xapian_db))->reopen();
     } catch (const Xapian::Error &error) {
-	if (! notmuch->exception_reported) {
-	    fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
-		     error.get_msg().c_str());
-	}
+        if (! notmuch->exception_reported) {
+            fprintf (stderr, "Error: A Xapian exception occurred reopening database: %s\n",
+                error.get_msg().c_str());
+        }
     }
+}
 
+void
+notmuch_database_flush (notmuch_database_t *notmuch)
+{
+    try {
+        if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
+            (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush();
+    } catch (const Xapian::Error &error) {
+        if (! notmuch->exception_reported) {
+            fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",
+                error.get_msg().c_str());
+        }
+    }
+}
+
+void
+notmuch_database_close (notmuch_database_t *notmuch)
+{
+    notmuch_database_flush (notmuch);
     delete notmuch->term_gen;
     delete notmuch->query_parser;
     delete notmuch->xapian_db;
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 974be8d..ca87b89 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -171,6 +171,14 @@ notmuch_database_t *
 notmuch_database_open (const char *path,
 		       notmuch_database_mode_t mode);
 
+/* Reopen a read_only database when the data source has changed */
+void
+notmuch_database_reopen (notmuch_database_t *database);
+
+/* Force a flush of the xapian database, also done on close */
+void
+notmuch_database_flush (notmuch_database_t *database);
+
 /* Close the given notmuch database, freeing all associated
  * resources. See notmuch_database_open. */
 void
-- 
1.7.1


  reply	other threads:[~2011-09-09 17:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-09-08  1:34 Patch: Flush and Reopen Martin Owens
2011-09-09  2:42 ` Austin Clements
2011-09-09  2:54   ` Martin Owens
2011-09-09 11:06     ` David Bremner
2011-09-09 17:55       ` Martin Owens [this message]
2011-09-09 23:40         ` Austin Clements
2011-09-10  0:43           ` Martin Owens
2011-09-12  0:23             ` Austin Clements
2011-09-12  1:03               ` Martin Owens
2011-09-12  1:04               ` Martin Owens
2011-09-12 12:23                 ` Sebastian Spaeth

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=1315590950.2435.59.camel@delen \
    --to=doctormo@gmail.com \
    --cc=david@tethera.net \
    --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).