Re: [PATCH] emacs: wash: make word-wrap bound message width
[notmuch-archives.git] / 46 / 8cb4578c6fb730bbf9595abfaa51aa87e0dd4b
1 Return-Path: <aclements@csail.mit.edu>\r
2 X-Original-To: notmuch@notmuchmail.org\r
3 Delivered-To: notmuch@notmuchmail.org\r
4 Received: from localhost (localhost [127.0.0.1])\r
5         by olra.theworths.org (Postfix) with ESMTP id 1B31A431FC0\r
6         for <notmuch@notmuchmail.org>; Thu,  2 Oct 2014 12:19:21 -0700 (PDT)\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org\r
8 X-Spam-Flag: NO\r
9 X-Spam-Score: -2.3\r
10 X-Spam-Level: \r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5\r
12         tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled\r
13 Received: from olra.theworths.org ([127.0.0.1])\r
14         by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)\r
15         with ESMTP id h5OeBDRD08fY for <notmuch@notmuchmail.org>;\r
16         Thu,  2 Oct 2014 12:19:17 -0700 (PDT)\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu\r
18         [18.7.68.34])\r
19         by olra.theworths.org (Postfix) with ESMTP id 1D9B1431FB6\r
20         for <notmuch@notmuchmail.org>; Thu,  2 Oct 2014 12:19:17 -0700 (PDT)\r
21 X-AuditID: 12074422-f79436d000000c21-28-542da534ddd0\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])\r
23         (using TLS with cipher AES256-SHA (256/256 bits))\r
24         (Client did not present a certificate)\r
25         by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP\r
26         id AF.23.03105.435AD245; Thu,  2 Oct 2014 15:19:16 -0400 (EDT)\r
27 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])\r
28         by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s92JJEoM022339; \r
29         Thu, 2 Oct 2014 15:19:14 -0400\r
30 Received: from drake.dyndns.org (26-4-182.dynamic.csail.mit.edu [18.26.4.182])\r
31         (authenticated bits=0)\r
32         (User authenticated as amdragon@ATHENA.MIT.EDU)\r
33         by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s92JJBXw006342\r
34         (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);\r
35         Thu, 2 Oct 2014 15:19:13 -0400\r
36 Received: from amthrax by drake.dyndns.org with local (Exim 4.84)\r
37         (envelope-from <aclements@csail.mit.edu>)\r
38         id 1XZluB-0000uZ-Kh; Thu, 02 Oct 2014 15:19:11 -0400\r
39 From: Austin Clements <aclements@csail.mit.edu>\r
40 To: notmuch@notmuchmail.org\r
41 Subject: [PATCH v4] lib: Simplify close and codify aborting atomic section\r
42 Date: Thu,  2 Oct 2014 15:19:08 -0400\r
43 Message-Id: <1412277548-3445-1-git-send-email-aclements@csail.mit.edu>\r
44 X-Mailer: git-send-email 2.1.0\r
45 In-Reply-To: <87mw9ee0vf.fsf@csail.mit.edu>\r
46 References: <87mw9ee0vf.fsf@csail.mit.edu>\r
47 X-Brightmail-Tracker:\r
48  H4sIAAAAAAAAA+NgFjrGIsWRmVeSWpSXmKPExsUixG6nrmuyVDfEYHO/msWN1m5Gi+s3ZzJb\r
49         XFlznt2B2ePZqlvMHlsOvWf22P39J0sAcxSXTUpqTmZZapG+XQJXxuXWXywFR5QqHtxex9jA\r
50         +Fi6i5GTQ0LARKJh2WpWCFtM4sK99WwgtpDAbCaJ5b8ruxi5gOwNjBKvJ61ihUgcZpKYuIYT\r
51         IrGEUWLBz+csIAk2AX2JFWsngRWJCEhL7Lw7G8xmFvCWmP11NTuILSzgJbGt7QIziM0ioCpx\r
52         bcsLMJtXwE1i644j7BBXyEls2P2fEcTmFNCWWPN1FjPEYi2J1s4+9gmM/AsYGVYxyqbkVunm\r
53         JmbmFKcm6xYnJ+blpRbpmurlZpbopaaUbmIEB5eL0g7GnweVDjEKcDAq8fBmNOiECLEmlhVX\r
54         5h5ilORgUhLl/bFQN0SILyk/pTIjsTgjvqg0J7X4EKMEB7OSCK9wN1CONyWxsiq1KB8mJc3B\r
55         oiTOu+kHX4iQQHpiSWp2ampBahFMVoaDQ0mCd/d8oEbBotT01Iq0zJwShDQTByfIcB6g4THT\r
56         QYYXFyTmFmemQ+RPMSpKifNyzgNKCIAkMkrz4Hph0f+KURzoFWHeaJB2HmDigOt+BTSYCWjw\r
57         O3uwwSWJCCmpBkbJ4sTEXucTLmc7J+k+Kyn0r//oucd6Unvrli0am3//X/F4tvhpyZiTcXKZ\r
58         bpHrSq6rrYgW/JuiwuKh0+q2233ZTGvvd7/+/r/xX6wpILom3TL7vsn0cDfvC3Xnvk/MVeQw\r
59         u9oc1N/UdVXhy6qXszccOVijoJjvI2Xmtl59zaJOu84AbcYLE5RYijMSDbWYi4oTAUuMhoPZ        AgAA\r
60 X-BeenThere: notmuch@notmuchmail.org\r
61 X-Mailman-Version: 2.1.13\r
62 Precedence: list\r
63 List-Id: "Use and development of the notmuch mail system."\r
64         <notmuch.notmuchmail.org>\r
65 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
66         <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
67 List-Archive: <http://notmuchmail.org/pipermail/notmuch>\r
68 List-Post: <mailto:notmuch@notmuchmail.org>\r
69 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
70 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
71         <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
72 X-List-Received-Date: Thu, 02 Oct 2014 19:19:21 -0000\r
73 \r
74 From: Austin Clements <amdragon@mit.edu>\r
75 \r
76 In Xapian, closing a database implicitly aborts any outstanding\r
77 transaction and commits changes.  For historical reasons,\r
78 notmuch_database_close had grown to almost, but not quite duplicate\r
79 this behavior.  Before closing the database, it would explicitly (and\r
80 unnecessarily) commit it.  However, if there was an outstanding\r
81 transaction (ie atomic section), commit would throw a Xapian\r
82 exception, which notmuch_database_close would unnecessarily print to\r
83 stderr, even though notmuch_database_close would ultimately abort the\r
84 transaction anyway when it called close.\r
85 \r
86 This patch simplifies notmuch_database_close to explicitly abort any\r
87 outstanding transaction and then just call Database::close.  This\r
88 works for both read-only and read/write databases, takes care of\r
89 committing changes, unifies the exception handling path, and codifies\r
90 aborting outstanding transactions.  This is currently the only way to\r
91 abort an atomic section (and may remain so, since it would be\r
92 difficult to roll back things we may have cached from rolled-back\r
93 modifications).\r
94 ---\r
95  lib/database.cc | 32 +++++++++++++++++---------------\r
96  lib/notmuch.h   |  9 ++++++++-\r
97  2 files changed, 25 insertions(+), 16 deletions(-)\r
98 \r
99 diff --git a/lib/database.cc b/lib/database.cc\r
100 index a3a7cd3..a47a71d 100644\r
101 --- a/lib/database.cc\r
102 +++ b/lib/database.cc\r
103 @@ -903,28 +903,30 @@ notmuch_database_close (notmuch_database_t *notmuch)\r
104  {\r
105      notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;\r
106  \r
107 -    try {\r
108 -       if (notmuch->xapian_db != NULL &&\r
109 -           notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE)\r
110 -           (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->flush ();\r
111 -    } catch (const Xapian::Error &error) {\r
112 -       status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
113 -       if (! notmuch->exception_reported) {\r
114 -           fprintf (stderr, "Error: A Xapian exception occurred flushing database: %s\n",\r
115 -                    error.get_msg().c_str());\r
116 -       }\r
117 -    }\r
118 -\r
119      /* Many Xapian objects (and thus notmuch objects) hold references to\r
120       * the database, so merely deleting the database may not suffice to\r
121       * close it.  Thus, we explicitly close it here. */\r
122      if (notmuch->xapian_db != NULL) {\r
123         try {\r
124 +           /* If there's an outstanding transaction, it's unclear if\r
125 +            * closing the Xapian database commits everything up to\r
126 +            * that transaction, or may discard committed (but\r
127 +            * unflushed) transactions.  To be certain, explicitly\r
128 +            * cancel any outstanding transaction before closing. */\r
129 +           if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_WRITE &&\r
130 +               notmuch->atomic_nesting)\r
131 +               (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))\r
132 +                   ->cancel_transaction ();\r
133 +\r
134 +           /* Close the database.  This implicitly flushes\r
135 +            * outstanding changes. */\r
136             notmuch->xapian_db->close();\r
137         } catch (const Xapian::Error &error) {\r
138 -           /* don't clobber previous error status */\r
139 -           if (status == NOTMUCH_STATUS_SUCCESS)\r
140 -               status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
141 +           status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;\r
142 +           if (! notmuch->exception_reported) {\r
143 +               fprintf (stderr, "Error: A Xapian exception occurred closing database: %s\n",\r
144 +                        error.get_msg().c_str());\r
145 +           }\r
146         }\r
147      }\r
148  \r
149 diff --git a/lib/notmuch.h b/lib/notmuch.h\r
150 index fe2340b..dae0416 100644\r
151 --- a/lib/notmuch.h\r
152 +++ b/lib/notmuch.h\r
153 @@ -281,7 +281,7 @@ notmuch_database_open (const char *path,\r
154                        notmuch_database_t **database);\r
155  \r
156  /**\r
157 - * Close the given notmuch database.\r
158 + * Commit changes and close the given notmuch database.\r
159   *\r
160   * After notmuch_database_close has been called, calls to other\r
161   * functions on objects derived from this database may either behave\r
162 @@ -292,6 +292,13 @@ notmuch_database_open (const char *path,\r
163   * notmuch_database_close can be called multiple times.  Later calls\r
164   * have no effect.\r
165   *\r
166 + * For writable databases, notmuch_database_close commits all changes\r
167 + * to disk before closing the database.  If the caller is currently in\r
168 + * an atomic section (there was a notmuch_database_begin_atomic\r
169 + * without a matching notmuch_database_end_atomic), this will discard\r
170 + * changes made in that atomic section (but still commit changes made\r
171 + * prior to entering the atomic section).\r
172 + *\r
173   * Return value:\r
174   *\r
175   * NOTMUCH_STATUS_SUCCESS: Successfully closed the database.\r
176 -- \r
177 2.1.0\r
178 \r