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 BAE8A429E2C for ; Sat, 11 Jun 2011 13:07:10 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] 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 FQYUvGa0ay5J for ; Sat, 11 Jun 2011 13:07:10 -0700 (PDT) Received: from dmz-mailsec-scanner-4.mit.edu (DMZ-MAILSEC-SCANNER-4.MIT.EDU [18.9.25.15]) by olra.theworths.org (Postfix) with ESMTP id 49460429E2B for ; Sat, 11 Jun 2011 13:07:10 -0700 (PDT) X-AuditID: 1209190f-b7b0eae000000a42-70-4df3caf26097 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) by dmz-mailsec-scanner-4.mit.edu (Symantec Messaging Gateway) with SMTP id 6C.DC.02626.2FAC3FD4; Sat, 11 Jun 2011 16:07:14 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK79u3030020; Sat, 11 Jun 2011 16:07:09 -0400 Received: from drake.mit.edu (209-6-116-242.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [209.6.116.242]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id p5BK78KH006034 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 11 Jun 2011 16:07:09 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1QVUSa-0000IV-Lp; Sat, 11 Jun 2011 16:07:08 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 12/17] lib: Wrap notmuch_database_add_message in an atomic section. Date: Sat, 11 Jun 2011 16:04:38 -0400 Message-Id: <1307822683-848-13-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.5.1 In-Reply-To: <1307822683-848-1-git-send-email-amdragon@mit.edu> References: <87ei34rnc5.fsf@yoom.home.cworth.org> <1307822683-848-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrPIsWRmVeSWpSXmKPExsUixG6nrvvp1Gdfg6n7zSyu35zJ7MDo8WzV LeYAxigum5TUnMyy1CJ9uwSujM1db5kL1vJWHNz7jaWB8RpXFyMnh4SAicTx/iPMELaYxIV7 69m6GLk4hAT2MUoc/z6fFcLZwCixcPU1RgjnPpNE0+GVUJn5jBKXl1xnAelnE9CQ2LZ/OSOI LSIgLbHz7mygIg4OZgE1iT9dKiBhYYFgiT/t/WAlLAKqEjP/rgKzeQXsJSZteMECcYaCxJUr 88BsTqD4vINXwWwhgTSJJbd2s09g5F/AyLCKUTYlt0o3NzEzpzg1Wbc4OTEvL7VI10QvN7NE LzWldBMjKGw4Jfl3MH47qHSIUYCDUYmHV2XtZ18h1sSy4srcQ4ySHExKorw6J4BCfEn5KZUZ icUZ8UWlOanFhxglOJiVRHjXt3/yFeJNSaysSi3Kh0lJc7AoifPOklT3FRJITyxJzU5NLUgt gsnKcHAoSfBKAuNDSLAoNT21Ii0zpwQhzcTBCTKcB2j40ZNANbzFBYm5xZnpEPlTjLocjzds OsQoxJKXn5cqJc57H6RIAKQoozQPbg4s3l8xigO9Jcz7A6SKB5gq4Ca9AlrCBLREoBRsSUki QkqqgXH2IQYFn1tl3czH9q074bxv3rIoXhvrh2HFYvektyyxuLckT9pJdPFV5xopj3b33dd0 by4/8eDY7a9BK8TZku6mvuL/cNNxgtZ1J0X2bjc1bZW3fGpuX/X1dtgGPHL5KzG5ovz1o9w0 6Vv3Xi8R6zmcY3ky6+4eu8xJiYIJXDPTj5YF3ZgSN0WJpTgj0VCLuag4EQCQ13eU0gIAAA== Cc: Austin Clements 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: Sat, 11 Jun 2011 20:07:10 -0000 Adding a message may involve changes to multiple database documents, and thus needs to be done in a transaction. This makes add_message (and, I think, the whole library) atomicity-safe: library callers only needs to use atomic sections if they needs atomicity across multiple library calls. --- lib/database.cc | 14 +++++++++++++- 1 files changed, 13 insertions(+), 1 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index daa619d..f963964 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1601,7 +1601,7 @@ notmuch_database_add_message (notmuch_database_t *notmuch, { notmuch_message_file_t *message_file; notmuch_message_t *message = NULL; - notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; + notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS, ret2; notmuch_private_status_t private_status; const char *date, *header; @@ -1619,6 +1619,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch, if (message_file == NULL) return NOTMUCH_STATUS_FILE_ERROR; + /* Adding a message may change many documents. Do this all + * atomically. */ + ret = notmuch_database_begin_atomic (notmuch); + if (ret) + goto DONE; + notmuch_message_file_restrict_headers (message_file, "date", "from", @@ -1740,6 +1746,12 @@ notmuch_database_add_message (notmuch_database_t *notmuch, if (message_file) notmuch_message_file_close (message_file); + ret2 = notmuch_database_end_atomic (notmuch); + if ((ret == NOTMUCH_STATUS_SUCCESS || + ret == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) && + ret2 != NOTMUCH_STATUS_SUCCESS) + ret = ret2; + return ret; } -- 1.7.5.1