From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by arlo.cworth.org (Postfix) with ESMTP id 139506DE1915 for ; Sat, 25 Feb 2017 17:35:22 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at cworth.org X-Spam-Flag: NO X-Spam-Score: -0.005 X-Spam-Level: X-Spam-Status: No, score=-0.005 tagged_above=-999 required=5 tests=[AWL=0.006, SPF_PASS=-0.001, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from arlo.cworth.org ([127.0.0.1]) by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vhdV3cDy1g5U for ; Sat, 25 Feb 2017 17:35:20 -0800 (PST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by arlo.cworth.org (Postfix) with ESMTPS id ABB536DE1917 for ; Sat, 25 Feb 2017 17:35:20 -0800 (PST) Received: from remotemail by fethera.tethera.net with local (Exim 4.84_2) (envelope-from ) id 1chnjU-0006rp-FB for notmuch@notmuchmail.org; Sat, 25 Feb 2017 20:34:40 -0500 Received: (nullmailer pid 16030 invoked by uid 1000); Sun, 26 Feb 2017 01:35:17 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: v2 _notmuch_message_ensure_metadata exception handling Date: Sat, 25 Feb 2017 21:35:08 -0400 Message-Id: <20170226013512.15868-1-david@tethera.net> X-Mailer: git-send-email 2.11.0 X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.22 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: Sun, 26 Feb 2017 01:35:22 -0000 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} < #include #include #include +#include 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, "");