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 1A5FD429E2F for ; Fri, 3 Oct 2014 07:19:45 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -2.3 X-Spam-Level: X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_MED=-2.3] 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 PRYSfKQx5Qfk for ; Fri, 3 Oct 2014 07:19:38 -0700 (PDT) Received: from dmz-mailsec-scanner-6.mit.edu (dmz-mailsec-scanner-6.mit.edu [18.7.68.35]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 3AE2A431FCF for ; Fri, 3 Oct 2014 07:19:26 -0700 (PDT) X-AuditID: 12074423-f799d6d00000337c-eb-542eb06dbcd7 Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) (using TLS with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by dmz-mailsec-scanner-6.mit.edu (Symantec Messaging Gateway) with SMTP id A3.B6.13180.D60BE245; Fri, 3 Oct 2014 10:19:25 -0400 (EDT) Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s93EJO7q018553; Fri, 3 Oct 2014 10:19:25 -0400 Received: from drake.dyndns.org (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com [216.15.114.40]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s93EJLNP023322 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); Fri, 3 Oct 2014 10:19:24 -0400 Received: from amthrax by drake.dyndns.org with local (Exim 4.84) (envelope-from ) id 1Xa3hZ-0002K7-9F; Fri, 03 Oct 2014 10:19:21 -0400 From: Austin Clements To: notmuch@notmuchmail.org Subject: [PATCH 08/11] lib: Implement upgrade to ghost messages feature Date: Fri, 3 Oct 2014 10:19:15 -0400 Message-Id: <1412345958-8278-9-git-send-email-aclements@csail.mit.edu> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu> References: <1412345958-8278-1-git-send-email-aclements@csail.mit.edu> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrZu7QS/E4PBWaYvrN2cyOzB6PFt1 izmAMYrLJiU1J7MstUjfLoErY+HO7YwFB2QqPk2fztTAuEusi5GTQ0LAROLbol5GCFtM4sK9 9WxdjFwcQgKzmST+tm9ignA2MEqc+L4WKnObSWLxzXlgLUICSxglds/yALHZBPQlVqydxApi iwhIS+y8OxvI5uBgFlCT+NOlAhIWFnCXuPTuIgtImEVAVeLvOiuQMK+Am8SDf0eZII6Qk9iw +z/YdE6g8gt3n7JBbHKTWHWsm20CI/8CRoZVjLIpuVW6uYmZOcWpybrFyYl5ealFumZ6uZkl eqkppZsYQSHD7qK8g/HPQaVDjAIcjEo8vB9u6IYIsSaWFVfmHmKU5GBSEuWtXKwXIsSXlJ9S mZFYnBFfVJqTWnyIUYKDWUmEd8FKoBxvSmJlVWpRPkxKmoNFSZx30w++ECGB9MSS1OzU1ILU IpisDAeHkgRv+3qgRsGi1PTUirTMnBKENBMHJ8hwHqDhYDW8xQWJucWZ6RD5U4yKUuK8D9cB JQRAEhmleXC9sJh+xSgO9IowbxdIOw8wHcB1vwIazAQ0+J29LsjgkkSElFQD45XCh7JZ/34X r9KWEC1/WbR0jkz8ybSzxW6fa9Oa1/Axf5x2NHSB97x3wgHbOhnuKZao7DnQfNXmlZhAp9+E greFqYenu02L0cridH20u1bcXnljJp+fdZuuLB+rxES2Z1sCZ53SF114KzP2ikePjvjvKXGt nkHhwdJPtqS7iCUVLE+NCedSYinOSDTUYi4qTgQAP4SZg8QCAAA= 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, 03 Oct 2014 14:19:45 -0000 From: Austin Clements Somehow this is the first upgrade pass that actually does *any* error checking, so this also adds the bit of necessary infrastructure to handle that. --- lib/database.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/lib/database.cc b/lib/database.cc index fdcc526..ff6a7f6 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -1231,6 +1231,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, notmuch_bool_t timer_is_active = FALSE; enum _notmuch_features target_features, new_features; notmuch_status_t status; + notmuch_private_status_t private_status; unsigned int count = 0, total = 0; status = _notmuch_database_ensure_writable (notmuch); @@ -1275,6 +1276,11 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++) ++total; } + if (new_features & NOTMUCH_FEATURE_GHOSTS) { + t_end = db->metadata_keys_end ("thread_id_"); + for (t = db->metadata_keys_begin ("thread_id_"); t != t_end; ++t) + ++total; + } /* Perform the upgrade in a transaction. */ db->begin_transaction (true); @@ -1378,10 +1384,64 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, } } + /* Perform metadata upgrades. */ + + /* Prior to NOTMUCH_FEATURE_GHOSTS, thread IDs for missing + * messages were stored as database metadata. Change these to + * ghost messages. + */ + if (new_features & NOTMUCH_FEATURE_GHOSTS) { + notmuch_message_t *message; + std::string message_id, thread_id; + + t_end = db->metadata_keys_end (NOTMUCH_METADATA_THREAD_ID_PREFIX); + for (t = db->metadata_keys_begin (NOTMUCH_METADATA_THREAD_ID_PREFIX); + t != t_end; ++t) { + if (do_progress_notify) { + progress_notify (closure, (double) count / total); + do_progress_notify = 0; + } + + message_id = (*t).substr ( + strlen (NOTMUCH_METADATA_THREAD_ID_PREFIX)); + thread_id = db->get_metadata (*t); + + /* Create ghost message */ + message = _notmuch_message_create_for_message_id ( + notmuch, message_id.c_str (), &private_status); + if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) { + /* Document already exists; ignore the stored thread ID */ + } else if (private_status == + NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) { + private_status = _notmuch_message_initialize_ghost ( + message, thread_id.c_str ()); + if (! private_status) + _notmuch_message_sync (message); + } + + if (private_status) { + fprintf (stderr, + "Upgrade failed while creating ghost messages.\n"); + status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost"); + goto DONE; + } + + /* Clear saved metadata thread ID */ + db->set_metadata (*t, ""); + + ++count; + } + } + + status = NOTMUCH_STATUS_SUCCESS; db->set_metadata ("features", _print_features (local, notmuch->features)); db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION)); - db->commit_transaction (); + DONE: + if (status == NOTMUCH_STATUS_SUCCESS) + db->commit_transaction (); + else + db->cancel_transaction (); if (timer_is_active) { /* Now stop the timer. */ @@ -1397,7 +1457,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, } talloc_free (local); - return NOTMUCH_STATUS_SUCCESS; + return status; } notmuch_status_t -- 2.1.0