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 14B6B431FBF for ; Wed, 24 Sep 2014 14:33:12 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 NDOW85WMgbcU for ; Wed, 24 Sep 2014 14:33:05 -0700 (PDT) Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu [18.9.25.12]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 07A7E431FAF for ; Wed, 24 Sep 2014 14:33:04 -0700 (PDT) X-AuditID: 1209190c-f795e6d000006c66-62-54233890c6ce Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP id 3A.34.27750.09833245; Wed, 24 Sep 2014 17:33:04 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s8OLX2hL023020; Wed, 24 Sep 2014 17:33:02 -0400 Received: from drake.dyndns.org (q-1.n.148.220.37.qore.nl [37.220.148.94] (may be forged)) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s8OLWwjf023605 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Wed, 24 Sep 2014 17:33:01 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.84) (envelope-from ) id 1XWuBA-0002Yq-Lo; Wed, 24 Sep 2014 17:32:52 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH v3] lib: Simplify close and codify aborting atomic section Date: Wed, 24 Sep 2014 17:32:50 -0400 Message-Id: <1411594370-9794-1-git-send-email-aclements@csail.mit.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <20140924212839.GE20130@odin.tremily.us> References: <20140924212839.GE20130@odin.tremily.us> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrIIsWRmVeSWpSXmKPExsUixG6nojvBQjnE4PNaUYsbrd2MFtdvzmS2 uLLmPLsDs8ezVbeYPbYces/ssfv7T5YA5igum5TUnMyy1CJ9uwSujAtTFrAULJCrOLzmNXMD 40qJLkZODgkBE4ntfdfZIWwxiQv31rN1MXJxCAnMZpK4MW8ylLORUeLdqrNMEM4FJokzJxey gbQICSxhlNi4VBjEZhPQl1ixdhIriC0iIC2x8+5sMJtZwFti9tfVYCuEBbwkemftAerl4GAR UJW4PD8OxOQVcJPY9k4G4gg5iQ27/zOC2JwCphKdk18yQ2wykbja94l1AiP/AkaGVYyyKblV urmJmTnFqcm6xcmJeXmpRbqGermZJXqpKaWbGEGhxSnJs4PxzUGlQ4wCHIxKPLwTxJVChFgT y4orcw8xSnIwKYnyrtVXDhHiS8pPqcxILM6ILyrNSS0+xCjBwawkwqvyEaicNyWxsiq1KB8m Jc3BoiTOu+kHX4iQQHpiSWp2ampBahFMVoaDQ0mCV98caKhgUWp6akVaZk4JQpqJgxNkOA/Q 8HkgNbzFBYm5xZnpEPlTjLoc6zq/9TMJseTl56VKifNeNQMqEgApyijNg5sDSwmvGMWB3hLm 5QUZxQNMJ3CTXgEtYQJacv+4PMiSkkSElFQDoxd7zl8mS8E1G7himl7z8NbMPfNf6NMX/e7D 0R4zjH1fXncTq4/buuRi8cutmy3t7363LuuMNjAXf9j65cjc2EQfpWNzbURnfxDx3uog5vDh yYm+ho66//tFLmneLHra8jTwSOollUufry8tluRapOy++NTZ99fFEtiDyz8fexadx/1msyff FyWW4oxEQy3mouJEANER8aDkAgAA 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: Wed, 24 Sep 2014 21:33:12 -0000 From: Austin Clements In Xapian, closing a database implicitly aborts any outstanding transaction and commits changes. For historical reasons, notmuch_database_close had grown to almost, but not quite duplicate this behavior. Before closing the database, it would explicitly (and unnecessarily) commit it. However, if there was an outstanding transaction (ie atomic section), commit would throw a Xapian exception, which notmuch_database_close would unnecessarily print to stderr, even though notmuch_database_close would ultimately abort the transaction anyway when it called close. This patch simplifies notmuch_database_close to just call Database::close. This works for both read-only and read/write databases, takes care of committing changes, unifies the exception handling path, and codifies aborting outstanding transactions. This is currently the only way to abort an atomic section (and may remain so, since it would be difficult to roll back things we may have cached from rolled-back modifications). --- 'Doh. Left out the all-critical "git commit" before sending v2. lib/database.cc | 23 +++++++---------------- lib/notmuch.h | 8 +++++++- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index a3a7cd3..1f7ff2a 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -903,28 +903,19 @@ notmuch_database_close (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 (notmuch->xapian_db))->flush (); - } catch (const Xapian::Error &error) { - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; - if (! notmuch->exception_reported) { - fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n", - error.get_msg().c_str()); - } - } - /* Many Xapian objects (and thus notmuch objects) hold references to * the database, so merely deleting the database may not suffice to - * close it. Thus, we explicitly close it here. */ + * close it. Thus, we explicitly close it here. This will + * implicitly abort any outstanding transaction and commit changes. */ if (notmuch->xapian_db != NULL) { try { notmuch->xapian_db->close(); } catch (const Xapian::Error &error) { - /* don't clobber previous error status */ - if (status == NOTMUCH_STATUS_SUCCESS) - status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; + if (! notmuch->exception_reported) { + fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n", + error.get_msg().c_str()); + } } } diff --git a/lib/notmuch.h b/lib/notmuch.h index fe2340b..49a3c79 100644 --- a/lib/notmuch.h +++ b/lib/notmuch.h @@ -281,7 +281,7 @@ notmuch_database_open (const char *path, notmuch_database_t **database); /** - * Close the given notmuch database. + * Commit changes and close the given notmuch database. * * After notmuch_database_close has been called, calls to other * functions on objects derived from this database may either behave @@ -292,6 +292,12 @@ notmuch_database_open (const char *path, * notmuch_database_close can be called multiple times. Later calls * have no effect. * + * If the caller is currently in an atomic section (there was a + * notmuch_database_begin_atomic without a matching + * notmuch_database_end_atomic), this will abort the atomic section, + * discarding any modifications made in the atomic section. All + * changes up to this will be committed. + * * Return value: * * NOTMUCH_STATUS_SUCCESS: Successfully closed the database. -- 2.1.0