* [PATCH 1/2] Add notmuch_database_flush method
2012-10-17 21:52 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Adrien Bustany
@ 2012-10-17 21:52 ` Adrien Bustany
2012-10-17 21:52 ` [PATCH 2/2] Add notmuch_database_reopen method Adrien Bustany
` (3 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Adrien Bustany @ 2012-10-17 21:52 UTC (permalink / raw)
To: notmuch
This method explicitly flushes the pending modifications to disk. It is
useful if your program has various threads, each with a read only DB and
one writer thread with a read/write DB. In that case, you most likely
want the writer to sync the changes to disk so that the readers can see
them, without having to close and reopen the database completely.
---
lib/database.cc | 18 ++++++++++++++++++
lib/notmuch.h | 4 ++++
2 files changed, 22 insertions(+)
diff --git a/lib/database.cc b/lib/database.cc
index 761dc1a..1b680ab 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -745,6 +745,24 @@ notmuch_database_open (const char *path,
return status;
}
+notmuch_status_t
+notmuch_database_flush(notmuch_database_t *notmuch)
+{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
+
+ try {
+ if (notmuch->xapian_db != NULL &&
+ notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)
+ (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();
+ } catch (const Xapian::Error &error) {
+ fprintf(stderr, "A Xapian exception occured flushing the database: %s\n",
+ error.get_msg().c_str());
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+ }
+
+ return status;
+}
+
void
notmuch_database_close (notmuch_database_t *notmuch)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index 3633bed..aef5c56 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -201,6 +201,10 @@ notmuch_database_open (const char *path,
notmuch_database_mode_t mode,
notmuch_database_t **database);
+/* Flushes all the pending modifications to the database to disk. */
+notmuch_status_t
+notmuch_database_flush (notmuch_database_t *database);
+
/* Close the given notmuch database.
*
* After notmuch_database_close has been called, calls to other
--
1.7.11.7
^ permalink raw reply related [flat|nested] 14+ messages in thread
* [PATCH 2/2] Add notmuch_database_reopen method
2012-10-17 21:52 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Adrien Bustany
2012-10-17 21:52 ` [PATCH 1/2] Add notmuch_database_flush method Adrien Bustany
@ 2012-10-17 21:52 ` Adrien Bustany
2012-10-19 3:19 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Ethan Glasser-Camp
` (2 subsequent siblings)
4 siblings, 0 replies; 14+ messages in thread
From: Adrien Bustany @ 2012-10-17 21:52 UTC (permalink / raw)
To: notmuch
Calling notmuch_database_reopen is needed to refresh the database
contents when the database on disk was modified by another
notmuch_database_t instance, for example in a different thread.
---
lib/database.cc | 17 +++++++++++++++++
lib/notmuch.h | 8 ++++++++
2 files changed, 25 insertions(+)
diff --git a/lib/database.cc b/lib/database.cc
index 1b680ab..f27d57f 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -763,6 +763,23 @@ notmuch_database_flush(notmuch_database_t *notmuch)
return status;
}
+notmuch_status_t
+notmuch_database_reopen(notmuch_database_t *notmuch)
+{
+ notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
+
+ try {
+ if (notmuch->xapian_db != NULL)
+ (notmuch->xapian_db)->reopen ();
+ } catch (const Xapian::Error &error) {
+ fprintf(stderr, "A Xapian exception occured reopening the database: %s\n",
+ error.get_msg().c_str());
+ status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
+ }
+
+ return status;
+}
+
void
notmuch_database_close (notmuch_database_t *notmuch)
{
diff --git a/lib/notmuch.h b/lib/notmuch.h
index aef5c56..51d6a9a 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -205,6 +205,14 @@ notmuch_database_open (const char *path,
notmuch_status_t
notmuch_database_flush (notmuch_database_t *database);
+/* Refresh the database contents to the latest version.
+ *
+ * This is needed only if another instance of notmuch_database_t has
+ * modified the database contents on disk.
+ */
+notmuch_status_t
+notmuch_database_reopen (notmuch_database_t *database);
+
/* Close the given notmuch database.
*
* After notmuch_database_close has been called, calls to other
--
1.7.11.7
^ permalink raw reply related [flat|nested] 14+ messages in thread
* Re: [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t
2012-10-17 21:52 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Adrien Bustany
2012-10-17 21:52 ` [PATCH 1/2] Add notmuch_database_flush method Adrien Bustany
2012-10-17 21:52 ` [PATCH 2/2] Add notmuch_database_reopen method Adrien Bustany
@ 2012-10-19 3:19 ` Ethan Glasser-Camp
2012-10-19 7:19 ` Jani Nikula
2012-12-12 1:40 ` Michael Forney
4 siblings, 0 replies; 14+ messages in thread
From: Ethan Glasser-Camp @ 2012-10-19 3:19 UTC (permalink / raw)
To: Adrien Bustany, notmuch
Adrien Bustany <adrien@bustany.org> writes:
> The code of the patches in unchanged, but the formatting issues are now
> hopefully fixed.
These look fine to me, and they're pretty trivial.
Ethan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t
2012-10-17 21:52 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Adrien Bustany
` (2 preceding siblings ...)
2012-10-19 3:19 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Ethan Glasser-Camp
@ 2012-10-19 7:19 ` Jani Nikula
2012-10-20 15:49 ` Ethan Glasser-Camp
2012-12-12 1:40 ` Michael Forney
4 siblings, 1 reply; 14+ messages in thread
From: Jani Nikula @ 2012-10-19 7:19 UTC (permalink / raw)
To: Adrien Bustany, notmuch
On Wed, 17 Oct 2012, Adrien Bustany <adrien@bustany.org> wrote:
> The code of the patches in unchanged, but the formatting issues are now
> hopefully fixed.
Hi Adrien, please check at what version flush and reopen have been
introduced to xapian. If they are new-ish (I don't know, didn't have the
time to check), please add appropriate #ifdefs. [1] lays the groundwork
for this. We'll also need to decide what is the minimum xapian version
required in general, i.e. features earlier than that don't need
conditional compilation.
BR,
Jani.
[1] id:"1350487737-32058-2-git-send-email-bgamari.foss@gmail.com"
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t
2012-10-19 7:19 ` Jani Nikula
@ 2012-10-20 15:49 ` Ethan Glasser-Camp
2012-10-25 18:39 ` Adrien Bustany
0 siblings, 1 reply; 14+ messages in thread
From: Ethan Glasser-Camp @ 2012-10-20 15:49 UTC (permalink / raw)
To: Jani Nikula, Adrien Bustany, notmuch
Jani Nikula <jani@nikula.org> writes:
> On Wed, 17 Oct 2012, Adrien Bustany <adrien@bustany.org> wrote:
>> The code of the patches in unchanged, but the formatting issues are now
>> hopefully fixed.
>
> Hi Adrien, please check at what version flush and reopen have been
> introduced to xapian. If they are new-ish (I don't know, didn't have the
> time to check), please add appropriate #ifdefs. [1] lays the groundwork
> for this. We'll also need to decide what is the minimum xapian version
> required in general, i.e. features earlier than that don't need
> conditional compilation.
Hi! The new versions of these patches are still pretty trivial and they
still look OK to me, but based on Jani's prompting I decided to look up
the methods. Seems that flush() is a very old (pre-1.1.0, 2009-04) name
for commit(), which is the preferred name these days. You should
probably therefore rename the function notmuch_database_commit, and have
it call the WritableDatabase::commit() method.
reopen() is a very very old method, seems like it has been around since
2004.
So I think Adrien is safe from having to do version checks, but we
should probably use commit() instead of flush().
Ethan
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t
2012-10-20 15:49 ` Ethan Glasser-Camp
@ 2012-10-25 18:39 ` Adrien Bustany
0 siblings, 0 replies; 14+ messages in thread
From: Adrien Bustany @ 2012-10-25 18:39 UTC (permalink / raw)
To: Ethan Glasser-Camp; +Cc: notmuch
Le 20/10/2012 18:49, Ethan Glasser-Camp a écrit :
> Jani Nikula <jani@nikula.org> writes:
>
>> On Wed, 17 Oct 2012, Adrien Bustany <adrien@bustany.org> wrote:
>>> The code of the patches in unchanged, but the formatting issues are now
>>> hopefully fixed.
>>
>> Hi Adrien, please check at what version flush and reopen have been
>> introduced to xapian. If they are new-ish (I don't know, didn't have the
>> time to check), please add appropriate #ifdefs. [1] lays the groundwork
>> for this. We'll also need to decide what is the minimum xapian version
>> required in general, i.e. features earlier than that don't need
>> conditional compilation.
>
> Hi! The new versions of these patches are still pretty trivial and they
> still look OK to me, but based on Jani's prompting I decided to look up
> the methods. Seems that flush() is a very old (pre-1.1.0, 2009-04) name
> for commit(), which is the preferred name these days. You should
> probably therefore rename the function notmuch_database_commit, and have
> it call the WritableDatabase::commit() method.
>
> reopen() is a very very old method, seems like it has been around since
> 2004.
>
> So I think Adrien is safe from having to do version checks, but we
> should probably use commit() instead of flush().
>
> Ethan
>
Thanks for checking that! Sorry for the late answer, I had a hard time
keeping on top of things lately...
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t
2012-10-17 21:52 ` [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t Adrien Bustany
` (3 preceding siblings ...)
2012-10-19 7:19 ` Jani Nikula
@ 2012-12-12 1:40 ` Michael Forney
2012-12-27 3:23 ` David Bremner
4 siblings, 1 reply; 14+ messages in thread
From: Michael Forney @ 2012-12-12 1:40 UTC (permalink / raw)
To: Adrien Bustany, notmuch
On Thu, 18 Oct 2012 00:52:20 +0300, Adrien Bustany <adrien@bustany.org> wrote:
> The code of the patches in unchanged, but the formatting issues are now
> hopefully fixed.
I would like to bump this patch set. I also need these features from
libnotmuch. Currently there is no way to recover from Xapian errors,
which is pretty limiting.
If it is the flush/commit that is the issue, I would be happy to make an
updated patch set.
--
Michael Forney <mforney@mforney.org>
^ permalink raw reply [flat|nested] 14+ messages in thread
* Re: [PATCH v2 0/2] Add flush/reopen methods to notmuch_database_t
2012-12-12 1:40 ` Michael Forney
@ 2012-12-27 3:23 ` David Bremner
0 siblings, 0 replies; 14+ messages in thread
From: David Bremner @ 2012-12-27 3:23 UTC (permalink / raw)
To: Michael Forney, Adrien Bustany, notmuch
Michael Forney <mforney@mforney.org> writes:
> On Thu, 18 Oct 2012 00:52:20 +0300, Adrien Bustany <adrien@bustany.org> wrote:
>> The code of the patches in unchanged, but the formatting issues are now
>> hopefully fixed.
>
> I would like to bump this patch set. I also need these features from
> libnotmuch. Currently there is no way to recover from Xapian errors,
> which is pretty limiting.
>
> If it is the flush/commit that is the issue, I would be happy to make an
> updated patch set.
Hi Michael;
Right, we should use the current name of 'commit'. We also need some way
to check the xapian version in the configure script, and to make sure
the right name is supported.
Jani refers to
id:1350487737-32058-2-git-send-email-bgamari.foss@gmail.com
farther up the thread as having some relevant code/ideas.
I think it's reasonable to require Xapian version at least 1.2.0, so
that might simplify the configuration check.
The other thing I wondered is if the error handling in these routines is
as good as it could be. I guess it isn't worse than what is there, but
especially since you are explicitly wanting to handle error conditions,
it would be good to think if we can do something better than adding yet
another printf to the library.
d
^ permalink raw reply [flat|nested] 14+ messages in thread