From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: v2 _notmuch_message_ensure_metadata exception handling
Date: Sat, 25 Feb 2017 21:35:08 -0400 [thread overview]
Message-ID: <20170226013512.15868-1-david@tethera.net> (raw)
I tried to address most of Jani's comments on v1 [1]. The bad news is
that the test is a bit delicate, it really does need the whole corpus.
I did decide to follow the suggestion to make the _reopen function
private for now. It would be nice if we could hide that complexity
from library users, I guess we'll have to see.
[1]: id:20170225034513.19427-1-david@tethera.net
Interdiff follows.
diff --git a/lib/database.cc b/lib/database.cc
index 1e958b65..ba440d4d 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -1135,7 +1135,7 @@ notmuch_database_close (notmuch_database_t *notmuch)
}
notmuch_status_t
-notmuch_database_reopen (notmuch_database_t *notmuch)
+_notmuch_database_reopen (notmuch_database_t *notmuch)
{
if (notmuch->mode != NOTMUCH_DATABASE_MODE_READ_ONLY)
return NOTMUCH_STATUS_UNSUPPORTED_OPERATION;
@@ -1147,8 +1147,8 @@ notmuch_database_reopen (notmuch_database_t *notmuch)
_notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n",
error.get_msg ().c_str ());
notmuch->exception_reported = TRUE;
- return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
+ return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
notmuch->view++;
diff --git a/lib/message.cc b/lib/message.cc
index bfb95917..007f1171 100644
--- a/lib/message.cc
+++ b/lib/message.cc
@@ -320,9 +320,8 @@ static void
_notmuch_message_ensure_metadata (notmuch_message_t *message, void *field)
{
Xapian::TermIterator i, end;
- notmuch_bool_t success = FALSE;
- if ((field != NULL) && (message->last_view >= message->notmuch->view))
+ if (field && (message->last_view >= message->notmuch->view))
return;
const char *thread_prefix = _find_prefix ("thread"),
@@ -338,7 +337,7 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message, void *field)
* slightly more costly than looking up individual fields if only
* one field of the message object is actually used, it's a huge
* win as more fields are used. */
- for (int count=0; count < 3 && !success; count++) {
+ for (int count=0; count < 3; count++) {
try {
i = message->doc.termlist_begin ();
end = message->doc.termlist_end ();
@@ -408,13 +407,12 @@ _notmuch_message_ensure_metadata (notmuch_message_t *message, void *field)
message->in_reply_to = talloc_strdup (message, "");
/* all the way without an exception */
- success = TRUE;
+ break;
} catch (const Xapian::DatabaseModifiedError &error) {
- notmuch_status_t status = notmuch_database_reopen (message->notmuch);
+ notmuch_status_t status = _notmuch_database_reopen (message->notmuch);
if (status != NOTMUCH_STATUS_SUCCESS)
INTERNAL_ERROR ("unhandled error from notmuch_database_reopen: %s\n",
notmuch_status_to_string (status));
- success = FALSE;
} catch (const Xapian::Error &error) {
INTERNAL_ERROR ("A Xapian exception occurred fetching message metadata: %s\n",
error.get_msg().c_str());
diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h
index 7b35fc5b..8587e86c 100644
--- a/lib/notmuch-private.h
+++ b/lib/notmuch-private.h
@@ -192,6 +192,9 @@ _notmuch_message_id_compressed (void *ctx, const char *message_id);
notmuch_status_t
_notmuch_database_ensure_writable (notmuch_database_t *notmuch);
+notmuch_status_t
+_notmuch_database_reopen (notmuch_database_t *notmuch);
+
void
_notmuch_database_log (notmuch_database_t *notmuch,
const char *format, ...);
diff --git a/lib/notmuch.h b/lib/notmuch.h
index e9ed01dd..16da8be9 100644
--- a/lib/notmuch.h
+++ b/lib/notmuch.h
@@ -363,18 +363,6 @@ notmuch_status_t
notmuch_database_close (notmuch_database_t *database);
/**
- * Reopen a (read-only) database, synching the database view with that
- * on disk.
- *
- * @returns
- * - NOTMUCH_STATUS_UNSUPPORTED_OPERATION: database is not read only
- * - NOTMUCH_STATUS_XAPIAN_EXCEPTION: a Xapian exception occured trying to
- * re-open the database.
- */
-notmuch_status_t
-notmuch_database_reopen (notmuch_database_t *database);
-
-/**
* A callback invoked by notmuch_database_compact to notify the user
* of the progress of the compaction process.
*/
diff --git a/test/T640-database-modified.sh b/test/T640-database-modified.sh
index 9599417c..516836b0 100755
--- a/test/T640-database-modified.sh
+++ b/test/T640-database-modified.sh
@@ -2,18 +2,22 @@
test_description="DatabaseModifiedError handling"
. ./test-lib.sh || exit 1
+# add enough messages to trigger the exception
add_email_corpus
test_begin_subtest "catching DatabaseModifiedError in _notmuch_message_ensure_metadata"
-test_C ${MAIL_DIR} <<'EOF'
+# it seems to need to be an early document to trigger the exception
+first_id=$(notmuch search --output=messages '*'| head -1 | sed s/^id://)
+
+test_C ${MAIL_DIR} <<EOF
#include <unistd.h>
#include <stdlib.h>
#include <notmuch-test.h>
#include <talloc.h>
+#include <assert.h>
int
main (int argc, char **argv)
{
- pid_t child;
const char *path = argv[1];
notmuch_database_t *rw_db, *ro_db;
@@ -23,7 +27,10 @@ main (int argc, char **argv)
notmuch_tags_t *tags;
EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_ONLY, &ro_db));
- EXPECT0 (notmuch_database_find_message (ro_db, "4EFC743A.3060609@april.org", &ro_message));
+ assert(ro_db);
+
+ EXPECT0 (notmuch_database_find_message (ro_db, "${first_id}", &ro_message));
+ assert(ro_message);
EXPECT0 (notmuch_database_open (path, NOTMUCH_DATABASE_MODE_READ_WRITE, &rw_db));
query = notmuch_query_create(rw_db, "");
next reply other threads:[~2017-02-26 1:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-26 1:35 David Bremner [this message]
2017-02-26 1:35 ` [patch v2 1/4] test: add known broken test for uncaught DatabaseModifiedError David Bremner
2017-02-26 1:35 ` [patch v2 2/4] lib: add _notmuch_database_reopen David Bremner
2017-02-26 1:35 ` [patch v2 3/4] lib: handle DatabaseModifiedError in _n_message_ensure_metadata David Bremner
2017-02-26 1:35 ` [patch v2 4/4] lib/message.cc: use view number to invalidate cached metadata David Bremner
2017-02-26 9:16 ` v2 _notmuch_message_ensure_metadata exception handling Jani Nikula
2017-02-26 11:47 ` 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=20170226013512.15868-1-david@tethera.net \
--to=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).