1 Return-Path: <amthrax@drake.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 9CE2F429E29
\r
6 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:06:13 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 0PqqZ0Jj+QTT for <notmuch@notmuchmail.org>;
\r
16 Sat, 11 Jun 2011 13:06:12 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU
\r
19 by olra.theworths.org (Postfix) with ESMTP id CC9D2431FB6
\r
20 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:06:12 -0700 (PDT)
\r
21 X-AuditID: 1209190f-b7b0eae000000a42-e4-4df3cab98d52
\r
22 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35])
\r
23 by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 87.DC.02626.9BAC3FD4; Sat, 11 Jun 2011 16:06:17 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK6CiA015024;
\r
27 Sat, 11 Jun 2011 16:06:12 -0400
\r
28 Received: from drake.mit.edu
\r
29 (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
30 [209.6.116.242]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK6BmA005941
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sat, 11 Jun 2011 16:06:12 -0400 (EDT)
\r
35 Received: from amthrax by drake.mit.edu with local (Exim 4.76)
\r
36 (envelope-from <amthrax@drake.mit.edu>)
\r
37 id 1QVURf-0000I8-56; Sat, 11 Jun 2011 16:06:11 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 07/17] lib: Add notmuch_database_{begin,end}_atomic.
\r
41 Date: Sat, 11 Jun 2011 16:04:33 -0400
\r
42 Message-Id: <1307822683-848-8-git-send-email-amdragon@mit.edu>
\r
43 X-Mailer: git-send-email 1.7.5.1
\r
44 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
45 References: <87ei34rnc5.fsf@yoom.home.cworth.org>
\r
46 <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
47 X-Brightmail-Tracker:
\r
48 H4sIAAAAAAAAA+NgFtrHIsWRmVeSWpSXmKPExsUixCmqrLvz1Gdfg/v/pCyu35zJ7MDo8WzV
\r
49 LeYAxigum5TUnMyy1CJ9uwSujL51ZxkLbshUfD78n7GB8aR4FyMnh4SAicT+TdPYIGwxiQv3
\r
50 1gPZXBxCAvsYJS43TmMGSQgJbGCU+NQpDZG4zyQx6fV/VghnPqPE85V3WEGq2AQ0JLbtX84I
\r
51 YosISEvsvDsbKM7BwSygJvGnSwUkLCzgItFyewNYOYuAqkTr/yawzbwCdhILru1mh7hCQeLK
\r
52 lXksIDangL3EvINXWSCOSJNYcms3+wRG/gWMDKsYZVNyq3RzEzNzilOTdYuTE/PyUot0TfRy
\r
53 M0v0UlNKNzGCg0aSfwfjt4NKhxgFOBiVeHhV1n72FWJNLCuuzD3EKMnBpCTKq3MCKMSXlJ9S
\r
54 mZFYnBFfVJqTWnyIUYKDWUmEd337J18h3pTEyqrUonyYlDQHi5I47yxJdV8hgfTEktTs1NSC
\r
55 1CKYrAwHh5IE7+aTQEMFi1LTUyvSMnNKENJMHJwgw3mAhh8FqeEtLkjMLc5Mh8ifYtTleLxh
\r
56 0yFGIZa8/LxUKXHe+yBFAiBFGaV5cHNg0f6KURzoLWHeXSBVPMBEATfpFdASJqAlAqVgS0oS
\r
57 EVJSDYzz58vJZl699lu6h7tF0cVWNVE85cH7m0uYVY4eTc4NODT/ct28sM0uln+mbN11MmZ3
\r
58 +Optj/7fqjvJkKrUbb4jYs+RBaskHSp3MLrJpyxwjEqy2pfIp9t45Yaqv/LP188WSKpF20fd
\r
59 V/19QWzrf98ZC4JU9FZqTeebc9ekOlPll++ttx98OqcpsRRnJBpqMRcVJwIAffDV+9ECAAA=
\r
60 Cc: Austin Clements <amdragon@mit.edu>
\r
61 X-BeenThere: notmuch@notmuchmail.org
\r
62 X-Mailman-Version: 2.1.13
\r
64 List-Id: "Use and development of the notmuch mail system."
\r
65 <notmuch.notmuchmail.org>
\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
69 List-Post: <mailto:notmuch@notmuchmail.org>
\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
73 X-List-Received-Date: Sat, 11 Jun 2011 20:06:13 -0000
\r
75 These operations translate into non-flushed Xapian transactions,
\r
76 allowing arbitrary groups of database operations to be performed
\r
79 lib/database.cc | 44 ++++++++++++++++++++++++++++++++++++++++++++
\r
80 lib/notmuch.h | 30 ++++++++++++++++++++++++++++++
\r
81 2 files changed, 74 insertions(+), 0 deletions(-)
\r
83 diff --git a/lib/database.cc b/lib/database.cc
\r
84 index 7f79cf4..ddb6167 100644
\r
85 --- a/lib/database.cc
\r
86 +++ b/lib/database.cc
\r
87 @@ -974,6 +974,50 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
88 return NOTMUCH_STATUS_SUCCESS;
\r
92 +notmuch_database_begin_atomic (notmuch_database_t *notmuch)
\r
94 + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
\r
95 + return NOTMUCH_STATUS_SUCCESS;
\r
98 + (static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db))->begin_transaction (false);
\r
99 + } catch (const Xapian::Error &error) {
\r
100 + fprintf (stderr, "A Xapian exception occurred beginning transaction: %s.\n",
\r
101 + error.get_msg().c_str());
\r
102 + notmuch->exception_reported = TRUE;
\r
103 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
105 + return NOTMUCH_STATUS_SUCCESS;
\r
109 +notmuch_database_end_atomic (notmuch_database_t *notmuch)
\r
111 + Xapian::WritableDatabase *db;
\r
113 + if (notmuch->mode == NOTMUCH_DATABASE_MODE_READ_ONLY)
\r
114 + return NOTMUCH_STATUS_SUCCESS;
\r
116 + db = static_cast <Xapian::WritableDatabase *> (notmuch->xapian_db);
\r
118 + db->commit_transaction ();
\r
120 + /* This is a hack for testing. Xapian never flushes on a
\r
121 + * non-flushed commit, even if the flush threshold is 1.
\r
122 + * However, we rely on flushing to test atomicity. */
\r
123 + const char *thresh = getenv ("XAPIAN_FLUSH_THRESHOLD");
\r
124 + if (thresh && atoi (thresh) == 1)
\r
126 + } catch (const Xapian::Error &error) {
\r
127 + fprintf (stderr, "A Xapian exception occurred committing transaction: %s.\n",
\r
128 + error.get_msg().c_str());
\r
129 + notmuch->exception_reported = TRUE;
\r
130 + return NOTMUCH_STATUS_XAPIAN_EXCEPTION;
\r
132 + return NOTMUCH_STATUS_SUCCESS;
\r
135 /* We allow the user to use arbitrarily long paths for directories. But
\r
136 * we have a term-length limit. So if we exceed that, we'll use the
\r
137 * SHA-1 of the path for the database term.
\r
138 diff --git a/lib/notmuch.h b/lib/notmuch.h
\r
139 index e508309..208d22c 100644
\r
140 --- a/lib/notmuch.h
\r
141 +++ b/lib/notmuch.h
\r
142 @@ -214,6 +214,36 @@ notmuch_database_upgrade (notmuch_database_t *database,
\r
146 +/* Begin an atomic database operation.
\r
148 + * Any modifications performed between a successful begin and a
\r
149 + * notmuch_database_end_atomic will be applied to the database
\r
150 + * atomically. Note that, unlike a typical database transaction, this
\r
151 + * only ensures atomicity, not durability; neither begin nor end
\r
152 + * necessarily flush modifications to disk.
\r
156 + * NOTMUCH_STATUS_SUCCESS: Successfully entered atomic section.
\r
158 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
\r
159 + * atomic section not entered.
\r
162 +notmuch_database_begin_atomic (notmuch_database_t *notmuch);
\r
164 +/* Indicate the end of an atomic database operation.
\r
168 + * NOTMUCH_STATUS_SUCCESS: Successfully completed atomic section.
\r
170 + * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred;
\r
171 + * atomic section not ended.
\r
174 +notmuch_database_end_atomic (notmuch_database_t *notmuch);
\r
176 /* Retrieve a directory object from the database for 'path'.
\r
178 * Here, 'path' should be a path relative to the path of 'database'
\r