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 51A91429E2F for ; Thu, 17 Feb 2011 23:59:40 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] 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 ZDUCmm2eniJZ for ; Thu, 17 Feb 2011 23:59:39 -0800 (PST) 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 E3C45429E3C for ; Thu, 17 Feb 2011 23:59:31 -0800 (PST) X-AuditID: 1209190f-b7c1dae000000a2b-71-4d5e26e3da3e Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-4.mit.edu (Symantec Brightmail Gateway) with SMTP id 8C.42.02603.3E62E5D4; Fri, 18 Feb 2011 02:59:31 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id p1I7xVsd029794; Fri, 18 Feb 2011 02:59:31 -0500 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 p1I7xUSa001556 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Fri, 18 Feb 2011 02:59:31 -0500 (EST) Received: from amthrax by drake.mit.edu with local (Exim 4.72) (envelope-from ) id 1PqLFS-0008LW-Hs; Fri, 18 Feb 2011 02:59:30 -0500 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 10/10] new: Wrap adding a message in an atomic section. Date: Fri, 18 Feb 2011 02:59:00 -0500 Message-Id: <1298015940-31986-11-git-send-email-amdragon@mit.edu> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <1298015940-31986-1-git-send-email-amdragon@mit.edu> References: <1298015940-31986-1-git-send-email-amdragon@mit.edu> X-Brightmail-Tracker: AAAAAA== Cc: amdragon@mit.edu 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: Fri, 18 Feb 2011 07:59:40 -0000 This prevents atomicity violations when adding new messages. Each message add is wrapped in its own atomic section, so interrupting notmuch new doesn't loose progress. Unlike in the remove case, adding a message can modify more than one database document, necessitating full transactions. --- notmuch-new.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/notmuch-new.c b/notmuch-new.c index 767722a..880f31a 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -424,6 +424,12 @@ add_files_recursive (notmuch_database_t *notmuch, fflush (stdout); } + status = notmuch_database_begin_atomic (notmuch); + if (status) { + ret = status; + goto DONE; + } + status = notmuch_database_add_message (notmuch, next, &message); switch (status) { /* success */ @@ -463,6 +469,12 @@ add_files_recursive (notmuch_database_t *notmuch, goto DONE; } + status = notmuch_database_end_atomic (notmuch); + if (status) { + ret = status; + goto DONE; + } + if (message) { notmuch_message_destroy (message); message = NULL; -- 1.7.2.3