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 0B73C429E2F for ; Sat, 11 Jun 2011 13:07:02 -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 fnkPnziW2kGq for ; Sat, 11 Jun 2011 13:07:01 -0700 (PDT) Received: from dmz-mailsec-scanner-8.mit.edu (DMZ-MAILSEC-SCANNER-8.MIT.EDU [18.7.68.37]) by olra.theworths.org (Postfix) with ESMTP id DA566429E2D for ; Sat, 11 Jun 2011 13:07:00 -0700 (PDT) X-AuditID: 12074425-b7b82ae000000a2a-84-4df3cacc1b72 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP id 00.75.02602.CCAC3FD4; Sat, 11 Jun 2011 16:06:36 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id p5BK70Kg015055; Sat, 11 Jun 2011 16:07:00 -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 p5BK6xtl006026 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Sat, 11 Jun 2011 16:07:00 -0400 (EDT) Received: from amthrax by drake.mit.edu with local (Exim 4.76) (envelope-from ) id 1QVUSR-0000II-8J; Sat, 11 Jun 2011 16:06:59 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 10/17] lib: Remove message document directly after removing the last file name. Date: Sat, 11 Jun 2011 16:04:36 -0400 Message-Id: <1307822683-848-11-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+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrHvm1Gdfg2kTtC2u35zJ7MDo8WzV LeYAxigum5TUnMyy1CJ9uwSujNb+1ywFm+UrTp1/z9rAeFKyi5GTQ0LAROJ28z8mCFtM4sK9 9WxdjFwcQgL7GCXmve+DcjYwShyceogZwrnPJHHpYTs7hDOfUeLcwe+MIP1sAhoS2/YvB7NF BKQldt6dzdrFyMHBLKAm8adLBSQsLBAvsW/zDrB1LAKqEn+nXAcr5xWwl9i55D0jxBkKEleu zGMBsTmB4vMOXgWzhQTSJJbc2s0+gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzUIl0LvdzM Er3UlNJNjKCwYXdR3cE44ZDSIUYBDkYlHl7FtZ99hVgTy4orcw8xSnIwKYny6pwACvEl5adU ZiQWZ8QXleakFh9ilOBgVhLhXd/+yVeINyWxsiq1KB8mJc3BoiTOO19S3VdIID2xJDU7NbUg tQgmK8PBoSTBKwmMDyHBotT01Iq0zJwShDQTByfIcB6g4UdPAtXwFhck5hZnpkPkTzEaczze sOkQI0f7ZiApxJKXn5cqJc57H6RUAKQ0ozQPbhos9l8xigM9J8z7A6SKB5g24Oa9AlrFBLRK oBRsVUkiQkqqgZHD9/LM8ruX+KKmfc40iVgdH7LAPIb1+gXRz/KRHOmT/hSyKebcf+sboW0l d3hv19M1EXPt5zfe9hDnrrPff8zZo/tXrLiJ8PLUg+1aR1L3bCnb/2L+QaH1fvrhBlIfvJ1k OL+qbLe43n95Q8PEla2MLtvn/+N+dOx98kxLyZAXIYm3l4Yo+SqxFGckGmoxFxUnAgCCMVy9 2AIAAA== 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:02 -0000 Previously, notmuch_database_remove_message would remove the message file name, sync the change to the message document, re-find the message document, and then delete it if there were no more file names. An interruption after sync'ing would result in a file-name-less, permanently un-removable zombie message that would produce errors and odd results in searches. We could wrap this in an atomic section, but it's much simpler to eliminate the round-about approach and just delete the message document instead of sync'ing it if we removed the last filename. --- lib/database.cc | 25 +++++-------------------- lib/message.cc | 16 ++++++++++++++++ lib/notmuch-private.h | 3 +++ 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index b766e94..9886622 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1747,7 +1747,6 @@ notmuch_status_t notmuch_database_remove_message (notmuch_database_t *notmuch, const char *filename) { - Xapian::WritableDatabase *db; void *local; const char *prefix = _find_prefix ("file-direntry"); char *direntry, *term; @@ -1761,8 +1760,6 @@ notmuch_database_remove_message (notmuch_database_t *notmuch, local = talloc_new (notmuch); - db = static_cast (notmuch->xapian_db); - try { status = _notmuch_database_filename_to_direntry (local, notmuch, @@ -1785,23 +1782,11 @@ notmuch_database_remove_message (notmuch_database_t *notmuch, return COERCE_STATUS (private_status, "Inconsistent document ID in datbase."); - _notmuch_message_remove_filename (message, filename); - _notmuch_message_sync (message); - - /* Take care to find document after sync'ing filename removal. */ - document = find_document_for_doc_id (notmuch, *i); - j = document.termlist_begin (); - j.skip_to (prefix); - - /* Was this the last file-direntry in the message? */ - if (j == document.termlist_end () || - strncmp ((*j).c_str (), prefix, strlen (prefix))) - { - db->delete_document (document.get_docid ()); - status = NOTMUCH_STATUS_SUCCESS; - } else { - status = NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID; - } + status = _notmuch_message_remove_filename (message, filename); + if (status == NOTMUCH_STATUS_SUCCESS) + _notmuch_message_delete (message); + else if (status == NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID) + _notmuch_message_sync (message); } } catch (const Xapian::Error &error) { fprintf (stderr, "Error: A Xapian exception occurred removing message: %s\n", diff --git a/lib/message.cc b/lib/message.cc index 5120b3a..9de60d2 100644 --- a/lib/message.cc +++ b/lib/message.cc @@ -797,6 +797,22 @@ _notmuch_message_sync (notmuch_message_t *message) db->replace_document (message->doc_id, message->doc); } +/* Delete a message document from the database. */ +notmuch_status_t +_notmuch_message_delete (notmuch_message_t *message) +{ + notmuch_status_t status; + Xapian::WritableDatabase *db; + + status = _notmuch_database_ensure_writable (message->notmuch); + if (status) + return status; + + db = static_cast (message->notmuch->xapian_db); + db->delete_document (message->doc_id); + return NOTMUCH_STATUS_SUCCESS; +} + /* Ensure that 'message' is not holding any file object open. Future * calls to various functions will still automatically open the * message file as needed. diff --git a/lib/notmuch-private.h b/lib/notmuch-private.h index 02e24ee..d319530 100644 --- a/lib/notmuch-private.h +++ b/lib/notmuch-private.h @@ -293,6 +293,9 @@ _notmuch_message_set_date (notmuch_message_t *message, void _notmuch_message_sync (notmuch_message_t *message); +notmuch_status_t +_notmuch_message_delete (notmuch_message_t *message); + void _notmuch_message_close (notmuch_message_t *message); -- 1.7.5.1