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 BAE8A429E2C
\r
6 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:07:10 -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 FQYUvGa0ay5J for <notmuch@notmuchmail.org>;
\r
16 Sat, 11 Jun 2011 13:07:10 -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 49460429E2B
\r
20 for <notmuch@notmuchmail.org>; Sat, 11 Jun 2011 13:07:10 -0700 (PDT)
\r
21 X-AuditID: 1209190f-b7b0eae000000a42-70-4df3caf26097
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP
\r
24 id 6C.DC.02626.2FAC3FD4; Sat, 11 Jun 2011 16:07:14 -0400 (EDT)
\r
25 Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103])
\r
26 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK79u3030020;
\r
27 Sat, 11 Jun 2011 16:07:09 -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 p5BK78KH006034
\r
33 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
34 Sat, 11 Jun 2011 16:07:09 -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 1QVUSa-0000IV-Lp; Sat, 11 Jun 2011 16:07:08 -0400
\r
38 From: Austin Clements <amdragon@MIT.EDU>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH 12/17] lib: Wrap notmuch_database_add_message in an atomic
\r
42 Date: Sat, 11 Jun 2011 16:04:38 -0400
\r
43 Message-Id: <1307822683-848-13-git-send-email-amdragon@mit.edu>
\r
44 X-Mailer: git-send-email 1.7.5.1
\r
45 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
46 References: <87ei34rnc5.fsf@yoom.home.cworth.org>
\r
47 <1307822683-848-1-git-send-email-amdragon@mit.edu>
\r
48 X-Brightmail-Tracker:
\r
49 H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsUixG6nrvvp1Gdfg6n7zSyu35zJ7MDo8WzV
\r
50 LeYAxigum5TUnMyy1CJ9uwSujM1db5kL1vJWHNz7jaWB8RpXFyMnh4SAicTx/iPMELaYxIV7
\r
51 69m6GLk4hAT2MUoc/z6fFcLZwCixcPU1RgjnPpNE0+GVUJn5jBKXl1xnAelnE9CQ2LZ/OSOI
\r
52 LSIgLbHz7mygIg4OZgE1iT9dKiBhYYFgiT/t/WAlLAKqEjP/rgKzeQXsJSZteMECcYaCxJUr
\r
53 88BsTqD4vINXwWwhgTSJJbd2s09g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI10QvN7NE
\r
54 LzWldBMjKGw4Jfl3MH47qHSIUYCDUYmHV2XtZ18h1sSy4srcQ4ySHExKorw6J4BCfEn5KZUZ
\r
55 icUZ8UWlOanFhxglOJiVRHjXt3/yFeJNSaysSi3Kh0lJc7AoifPOklT3FRJITyxJzU5NLUgt
\r
56 gsnKcHAoSfBKAuNDSLAoNT21Ii0zpwQhzcTBCTKcB2j40ZNANbzFBYm5xZnpEPlTjLocjzds
\r
57 OsQoxJKXn5cqJc57H6RIAKQoozQPbg4s3l8xigO9Jcz7A6SKB5gq4Ca9AlrCBLREoBRsSUki
\r
58 QkqqgXH2IQYFn1tl3czH9q074bxv3rIoXhvrh2HFYvektyyxuLckT9pJdPFV5xopj3b33dd0
\r
59 by4/8eDY7a9BK8TZku6mvuL/cNNxgtZ1J0X2bjc1bZW3fGpuX/X1dtgGPHL5KzG5ovz1o9w0
\r
60 6Vv3Xi8R6zmcY3ky6+4eu8xJiYIJXDPTj5YF3ZgSN0WJpTgj0VCLuag4EQCQ13eU0gIAAA==
\r
61 Cc: Austin Clements <amdragon@mit.edu>
\r
62 X-BeenThere: notmuch@notmuchmail.org
\r
63 X-Mailman-Version: 2.1.13
\r
65 List-Id: "Use and development of the notmuch mail system."
\r
66 <notmuch.notmuchmail.org>
\r
67 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
68 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
69 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
70 List-Post: <mailto:notmuch@notmuchmail.org>
\r
71 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
72 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
73 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
74 X-List-Received-Date: Sat, 11 Jun 2011 20:07:10 -0000
\r
76 Adding a message may involve changes to multiple database documents,
\r
77 and thus needs to be done in a transaction. This makes add_message
\r
78 (and, I think, the whole library) atomicity-safe: library callers only
\r
79 needs to use atomic sections if they needs atomicity across multiple
\r
82 lib/database.cc | 14 +++++++++++++-
\r
83 1 files changed, 13 insertions(+), 1 deletions(-)
\r
85 diff --git a/lib/database.cc b/lib/database.cc
\r
86 index daa619d..f963964 100644
\r
87 --- a/lib/database.cc
\r
88 +++ b/lib/database.cc
\r
89 @@ -1601,7 +1601,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
91 notmuch_message_file_t *message_file;
\r
92 notmuch_message_t *message = NULL;
\r
93 - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS;
\r
94 + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, ret2;
\r
95 notmuch_private_status_t private_status;
\r
97 const char *date, *header;
\r
98 @@ -1619,6 +1619,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
99 if (message_file == NULL)
\r
100 return NOTMUCH_STATUS_FILE_ERROR;
\r
102 + /* Adding a message may change many documents. Do this all
\r
104 + ret = notmuch_database_begin_atomic (notmuch);
\r
108 notmuch_message_file_restrict_headers (message_file,
\r
111 @@ -1740,6 +1746,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
\r
113 notmuch_message_file_close (message_file);
\r
115 + ret2 = notmuch_database_end_atomic (notmuch);
\r
116 + if ((ret == NOTMUCH_STATUS_SUCCESS ||
\r
117 + ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) &&
\r
118 + ret2 != NOTMUCH_STATUS_SUCCESS)
\r