From: Austin Clements Date: Mon, 22 Sep 2014 15:43:35 +0000 (+2000) Subject: [PATCH] lib: Simplify close and codify aborting atomic section X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=9842a2dd70a8d42b6d53fbd5405369deb88313f1;p=notmuch-archives.git [PATCH] lib: Simplify close and codify aborting atomic section --- diff --git a/5d/ec4dd831441f0a909a25d25618b569f345f93e b/5d/ec4dd831441f0a909a25d25618b569f345f93e new file mode 100644 index 000000000..ec3e514b6 --- /dev/null +++ b/5d/ec4dd831441f0a909a25d25618b569f345f93e @@ -0,0 +1,154 @@ +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 333DE431FC0 + for ; Mon, 22 Sep 2014 08:43:57 -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 lvH6LqRsPS2H for ; + Mon, 22 Sep 2014 08:43:51 -0700 (PDT) +Received: from dmz-mailsec-scanner-7.mit.edu (dmz-mailsec-scanner-7.mit.edu + [18.7.68.36]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 92A42431FB6 + for ; Mon, 22 Sep 2014 08:43:51 -0700 (PDT) +X-AuditID: 12074424-f79346d000004923-48-542043b60783 +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-7.mit.edu (Symantec Messaging Gateway) with SMTP + id B8.8B.18723.6B340245; Mon, 22 Sep 2014 11:43:50 -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 s8MFhndg028845; + Mon, 22 Sep 2014 11:43:49 -0400 +Received: from drake.dyndns.org (navigator.sea-net.de [185.31.6.22]) + (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s8MFhhkC032098 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Mon, 22 Sep 2014 11:43:48 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XW5mA-0005SM-3W; Mon, 22 Sep 2014 11:43:42 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH] lib: Simplify close and codify aborting atomic section +Date: Mon, 22 Sep 2014 11:43:35 -0400 +Message-Id: <1411400615-20934-1-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.1.0 +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFlrOIsWRmVeSWpSXmKPExsUixG6norvNWSHE4P43c4vrN2cyOzB6PFt1 + izmAMYrLJiU1J7MstUjfLoEr4+P1RpaCWVIV2+/NY2xgnCzaxcjJISFgIrHgWgcLhC0mceHe + erYuRi4OIYHZTBK3JuxhgXA2Mkp8mdzGCOHsYpLYtqmPGcKZyyixYd1tdpB+NgENid+3FjOB + 2CIC0hI7785m7WLk4GAWUJP406UCEhYWcJdYcngJ2DoWAVWJtYt3grXyCjhIrHjZyQZxhpzE + ht3/GScw8i5gZFjFKJuSW6Wbm5iZU5yarFucnJiXl1qka66Xm1mil5pSuokRHAYuKjsYmw8p + HWIU4GBU4uFd0CQfIsSaWFZcmXuIUZKDSUmU976pQogQX1J+SmVGYnFGfFFpTmrxIUYJDmYl + Ed4gaaAcb0piZVVqUT5MSpqDRUmcd9MPvhAhgfTEktTs1NSC1CKYrAwHh5IE73snoEbBotT0 + 1Iq0zJwShDQTByfIcB6g4YdBaniLCxJzizPTIfKnGHU51nV+62cSYsnLz0uVEuctASkSACnK + KM2DmwOL31eM4kBvCfM+BaniAcY+3KRXQEuYgJbcPy4PsqQkESEl1cB4uOWDV3DY/itROiaK + q9geTXM92BRv07vrrYoNy2tZ7wsRXJUrVonyrp/nurut73v8e29T5a9Pb9/JlAw9YbA0+oxE + a7vd6iXCnzRdJk9Rj5F0c/wxw8Xr5/0Ato2yuRzHGXdk5Pbuk0/hKXx2sXzhi72RlYbvk6fG + leb9rd06tf5sk4e78R8lluKMREMt5qLiRABec9EnugIAAA== +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, 22 Sep 2014 15:43:57 -0000 + +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). +--- + lib/database.cc | 23 +++++++---------------- + lib/notmuch.h | 5 +++++ + 2 files changed, 12 insertions(+), 16 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..5c40c67 100644 +--- a/lib/notmuch.h ++++ b/lib/notmuch.h +@@ -292,6 +292,11 @@ 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. ++ * + * Return value: + * + * NOTMUCH_STATUS_SUCCESS: Successfully closed the database. +-- +2.1.0 +