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 99096429E21 for ; Sun, 11 Sep 2011 18:04:56 -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 jNsAlB10wzY0 for ; Sun, 11 Sep 2011 18:04:56 -0700 (PDT) Received: from mail-yx0-f181.google.com (mail-yx0-f181.google.com [209.85.213.181]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id DAB68431FB6 for ; Sun, 11 Sep 2011 18:04:55 -0700 (PDT) Received: by yxk30 with SMTP id 30so2379293yxk.26 for ; Sun, 11 Sep 2011 18:04:55 -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=h3yP9xLC630aCufaAJ5hLfiTEsBo5HwmgJ0m6iODA0w=; b=VjjqbHuYSAGcaRBpE+HHBd1YwAvP08rcamO8k1zRf6ixPS6uKtIdhIN9f0LMkje6lt N5lo3Jq1ie5SvpkfyY0130gzHdqS+imxD02D65lwN9pDhBakEijESz44x/hqk3BwRcmZ jlBAWjca9ZWeOOSQeoZ0GTIMf9aeQ1b2wTIxw= Received: by 10.150.138.3 with SMTP id l3mr3582924ybd.384.1315789495356; Sun, 11 Sep 2011 18:04:55 -0700 (PDT) Received: from [192.168.5.100] (mcd2436d0.tmodns.net [208.54.36.205]) by mx.google.com with ESMTPS id z6sm5134273anf.22.2011.09.11.18.04.50 (version=SSLv3 cipher=OTHER); Sun, 11 Sep 2011 18:04:54 -0700 (PDT) Subject: Re: Patch: Flush and Reopen From: Martin Owens To: Austin Clements In-Reply-To: <20110912002327.GC23603@mit.edu> References: <1315445674.32058.183.camel@delen> <1315536861.2435.34.camel@delen> <87obyuj7q1.fsf@zancas.localnet> <1315590950.2435.59.camel@delen> <1315615433.2435.62.camel@delen> <20110912002327.GC23603@mit.edu> Content-Type: multipart/mixed; boundary="=-BYbaCrqc5AZGCLvtRXrH" Date: Sun, 11 Sep 2011 21:04:39 -0400 Message-ID: <1315789479.2435.75.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: Mon, 12 Sep 2011 01:04:56 -0000 --=-BYbaCrqc5AZGCLvtRXrH Content-Type: text/plain Content-Transfer-Encoding: 7bit Previous Email was sans-attachment. See below. --=-BYbaCrqc5AZGCLvtRXrH Content-Disposition: attachment; filename*0=0001-Add-flush-and-reopen-to-notmuch-database-python-bind.pat; filename*1=ch Content-Type: text/x-patch; name="0001-Add-flush-and-reopen-to-notmuch-database-python-bind.patch"; charset="UTF-8" Content-Transfer-Encoding: 7bit >From 2d247d56660689dee5ae58c252621f9343044dd8 Mon Sep 17 00:00:00 2001 From: Martin Owens Date: Sun, 11 Sep 2011 20:51:35 -0400 Subject: [PATCH] Add flush and reopen to notmuch database + python bindings. Flush and reopen methods in the libnotmuch and python bindings allows concurent access to the database. Flush allows read_write databases to commit their changes, forcing a flush to disk and reopen allows a database to reread from the disk when changes are detected or known about. --- bindings/python/notmuch/database.py | 10 ++++++++++ lib/database.cc | 28 ++++++++++++++++++++++++---- lib/notmuch.h | 8 ++++++++ 3 files changed, 42 insertions(+), 4 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/lib/database.cc b/lib/database.cc index 9c2f4ec..9258137 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -700,18 +700,38 @@ notmuch_database_open (const char *path, } void -notmuch_database_close (notmuch_database_t *notmuch) +notmuch_database_reopen (notmuch_database_t *notmuch) +{ + try { + notmuch->xapian_db->reopen (); + } catch (const Xapian::Error &error) { + if (! notmuch->exception_reported) { + fprintf (stderr, "Error: A Xapian exception reopening database: %s\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; + } + } +} + +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) { + } 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()); + fprintf (stderr, "Error: A Xapian exception flushing database: %s\n", + error.get_msg().c_str()); + notmuch->exception_reported = TRUE; } } +} +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 --=-BYbaCrqc5AZGCLvtRXrH--