Return-Path: X-Original-To: notmuch@notmuchmail.org Delivered-To: notmuch@notmuchmail.org Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 66CCA431FD0 for ; Fri, 9 Sep 2011 10:55:55 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.799 X-Spam-Level: X-Spam-Status: No, score=-0.799 tagged_above=-999 required=5 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id LyjXEqodE8wC for ; Fri, 9 Sep 2011 10:55:54 -0700 (PDT) Received: from mail-vx0-f181.google.com (mail-vx0-f181.google.com [209.85.220.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 9B746431FB6 for ; Fri, 9 Sep 2011 10:55:54 -0700 (PDT) Received: by vxl15 with SMTP id 15so784951vxl.26 for ; Fri, 09 Sep 2011 10:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer; bh=LohzRBi4oCA1Uv/AGNGwyvoNqk+88ZyGTjnREnLyvMk=; b=HPCgc3QlZ3J1MnbxSmsub7S7BIQjZqeVQj779CTcNFr7MAEDeLeLgMD1kFHoWIh6sw QQQk9QEC39NPlwDlDYkTv5zHxeMQij+ep8n0UTUyq8LilmhOugzjSPN+aoCKBr3ZKSZN Sp9yo+16lfCmhcY9lDMTq4zbFes17IltQ1q48= Received: by 10.52.22.84 with SMTP id b20mr2328082vdf.413.1315590952959; Fri, 09 Sep 2011 10:55:52 -0700 (PDT) Received: from [192.168.1.190] (pool-68-163-190-45.bos.east.verizon.net [68.163.190.45]) by mx.google.com with ESMTPS id be17sm5173198vdc.15.2011.09.09.10.55.50 (version=SSLv3 cipher=OTHER); Fri, 09 Sep 2011 10:55:51 -0700 (PDT) Subject: Re: Patch: Flush and Reopen From: Martin Owens To: David Bremner In-Reply-To: <87obyuj7q1.fsf@zancas.localnet> References: <1315445674.32058.183.camel@delen> <1315536861.2435.34.camel@delen> <87obyuj7q1.fsf@zancas.localnet> Content-Type: multipart/mixed; boundary="=-if+DZnU/UI8bcf6/7HDh" Date: Fri, 09 Sep 2011 13:55:50 -0400 Message-ID: <1315590950.2435.59.camel@delen> Mime-Version: 1.0 X-Mailer: Evolution 2.30.3 Cc: Notmuch developer list X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 09 Sep 2011 17:55:55 -0000 --=-if+DZnU/UI8bcf6/7HDh Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit 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 --=-if+DZnU/UI8bcf6/7HDh Content-Disposition: attachment; filename*0=0001-Add-flush-and-reopen-methods-to-the-libnotmuch-and-t.pat; filename*1=ch Content-Type: text/x-patch; name="0001-Add-flush-and-reopen-methods-to-the-libnotmuch-and-t.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 981b91e9405de2daf35d30d9bbeab0dd62b15683 Mon Sep 17 00:00:00 2001 From: Martin Owens 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 (notmuch->xapian_db))->flush (); + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY) + (static_cast (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 (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 --=-if+DZnU/UI8bcf6/7HDh--