From d88849079cc95f8f1e70a9b8f1fc5f55dfa929b9 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Thu, 25 Sep 2014 17:20:23 +2000 Subject: [PATCH] [PATCH v2] lib: Simplify close and codify aborting atomic section --- c1/0a91964dd6f927d7ac9dedfa7a099b3b9a5eca | 159 ++++++++++++++++++++++ 1 file changed, 159 insertions(+) create mode 100644 c1/0a91964dd6f927d7ac9dedfa7a099b3b9a5eca diff --git a/c1/0a91964dd6f927d7ac9dedfa7a099b3b9a5eca b/c1/0a91964dd6f927d7ac9dedfa7a099b3b9a5eca new file mode 100644 index 000000000..285fced52 --- /dev/null +++ b/c1/0a91964dd6f927d7ac9dedfa7a099b3b9a5eca @@ -0,0 +1,159 @@ +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 41067431FBC + for ; Wed, 24 Sep 2014 14:20:44 -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 WtR9-lQ9g+c8 for ; + Wed, 24 Sep 2014 14:20:38 -0700 (PDT) +Received: from dmz-mailsec-scanner-4.mit.edu (dmz-mailsec-scanner-4.mit.edu + [18.9.25.15]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id B56AB431FAF + for ; Wed, 24 Sep 2014 14:20:38 -0700 (PDT) +X-AuditID: 1209190f-f79aa6d000005b45-a9-542335a538f7 +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-4.mit.edu (Symantec Messaging Gateway) with SMTP + id 63.9B.23365.5A533245; Wed, 24 Sep 2014 17:20:38 -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 s8OLKYuY021561; + Wed, 24 Sep 2014 17:20:34 -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 s8OLKUxX018469 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Wed, 24 Sep 2014 17:20:32 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XWtzB-00029S-TY; Wed, 24 Sep 2014 17:20:29 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2] lib: Simplify close and codify aborting atomic section +Date: Wed, 24 Sep 2014 17:20:23 -0400 +Message-Id: <1411593623-8234-1-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1411400615-20934-1-git-send-email-amdragon@mit.edu> +References: <1411400615-20934-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFrrMIsWRmVeSWpSXmKPExsUixG6norvMVDnEYHI7s8WN1m5Gi+s3ZzJb + XFlznt2B2ePZqlvMHlsOvWf22P39J0sAcxSXTUpqTmZZapG+XQJXxoUb/SwFx6QqDq/5ydzA + uEO0i5GTQ0LARGL7+lWMELaYxIV769m6GLk4hARmM0n8efKIBcLZyCixqnESI4RzgUli1rRv + LCAtQgJLGCX2/rMGsdkE9CVWrJ3ECmKLCEhL7Lw7G8xmFvCWmP11NTuILSzgJXH8zhYmEJtF + QFXiZM8xsBpeATeJK39fQJ0hJ7Fh938wm1PAUeLexJmsELscJH5Pf8k+gZF/ASPDKkbZlNwq + 3dzEzJzi1GTd4uTEvLzUIl0TvdzMEr3UlNJNjKDw4pTk38H47aDSIUYBDkYlHt4J4kohQqyJ + ZcWVuYcYJTmYlER51+orhwjxJeWnVGYkFmfEF5XmpBYfYpTgYFYS4VX5CFTOm5JYWZValA+T + kuZgURLn3fSDL0RIID2xJDU7NbUgtQgmK8PBoSTBe9QEaKhgUWp6akVaZk4JQpqJgxNkOA/Q + 8NMgNbzFBYm5xZnpEPlTjLoc6zq/9TMJseTl56VKifMeBCkSACnKKM2DmwNLC68YxYHeEuat + BKniAaYUuEmvgJYwAS25f1weZElJIkJKqoHRh7tw+vb/4U4BsnMLYuZ+NpTdytJ68Zx2YPpK + vcPX5aSEwq7ECnbvrLHcrr7pV6Vs7cpgObHFQS0/Jh+cViB731Hbj9ltVZyV5KlivjSJJPXX + /MVTd/jIK89tYmba2f7ee7W4VL21FvOvXrd337pnf3vy7rjqoZ/ZU5yOu9nKZyya83/RgV1K + LMUZiYZazEXFiQDvLj9h5gIAAA== +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:20:44 -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). +--- + 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 + -- 2.26.2