From 7659fb47843273e29273c77029d046ebe9043704 Mon Sep 17 00:00:00 2001 From: Austin Clements Date: Fri, 24 Oct 2014 08:30:38 +2000 Subject: [PATCH] [PATCH v3 6/9] lib: Implement upgrade to ghost messages feature --- 1f/48988b722c70d03ac65ad1d5ef740f3d881d29 | 189 ++++++++++++++++++++++ 1 file changed, 189 insertions(+) create mode 100644 1f/48988b722c70d03ac65ad1d5ef740f3d881d29 diff --git a/1f/48988b722c70d03ac65ad1d5ef740f3d881d29 b/1f/48988b722c70d03ac65ad1d5ef740f3d881d29 new file mode 100644 index 000000000..6511579c5 --- /dev/null +++ b/1f/48988b722c70d03ac65ad1d5ef740f3d881d29 @@ -0,0 +1,189 @@ +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 E5D24431FDD + for ; Thu, 23 Oct 2014 05:31:08 -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 nU-Bdx7Rh0a9 for ; + Thu, 23 Oct 2014 05:31:01 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 0088E431FDE + for ; Thu, 23 Oct 2014 05:30:52 -0700 (PDT) +X-AuditID: 1209190e-f79d46d000003643-71-5448f4fc4b93 +Received: from mailhub-auth-2.mit.edu ( [18.7.62.36]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 7A.79.13891.CF4F8445; Thu, 23 Oct 2014 08:30:52 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s9NCUppt027184; + Thu, 23 Oct 2014 08:30:51 -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 s9NCUmDP008963 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Thu, 23 Oct 2014 08:30:51 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XhHXP-0007c0-Co; Thu, 23 Oct 2014 08:30:43 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 6/9] lib: Implement upgrade to ghost messages feature +Date: Thu, 23 Oct 2014 08:30:38 -0400 +Message-Id: <1414067441-29054-7-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu> +References: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixG6novvni0eIwc5HPBar5/JYXL85k9mB + yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyjj44ARzwQbZikV75jE3ME4V72Lk5JAQMJFo + Wb+XBcIWk7hwbz1bFyMXh5DAbCaJrhd3WSCcjYwSe/b3QmXuMEmsa3nFDuEsYZQ4/HwzE0g/ + m4C+xIq1k1hBbBEBaYmdd2eD2cwCjhKf9y9iA7GFBTwktn7bzQ5iswioSkx/+BrM5hVwl5g9 + 8zATxB1yEht2/2cEsTmB6vfsuAPWKwRUs/35QdYJjPwLGBlWMcqm5Fbp5iZm5hSnJusWJyfm + 5aUW6Rrr5WaW6KWmlG5iBIUSpyTfDsavB5UOMQpwMCrx8FYke4QIsSaWFVfmHmKU5GBSEuWN + eQAU4kvKT6nMSCzOiC8qzUktPsQowcGsJMIbfwEox5uSWFmVWpQPk5LmYFES5930gy9ESCA9 + sSQ1OzW1ILUIJivDwaEkwcsIjBkhwaLU9NSKtMycEoQ0EwcnyHAeoOEiIDW8xQWJucWZ6RD5 + U4yKUuK8yZ+BEgIgiYzSPLheWKy/YhQHekWYVw2knQeYJuC6XwENZgK5egPY4JJEhJRUA6OQ + yr2Yihu6K30F3i+zVvjTcdDCKXH5ippb/TrdYrP+ce62+24vcG/RwjUBy/7F5aTrn+oTqXt8 + 58rOqTknLj31mum5bE5IEVvGzR93F35qOL3ioZ+Dq8C2JTe/xi1zdZmarLTrZUHIxlWcO76I + MKw5Hyi3zPNI65Q3KSePa/0q3Hi1fFto3sJyJZbijERDLeai4kQAHmqfVtACAAA= +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: Thu, 23 Oct 2014 12:31:09 -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 | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- + 1 file changed, 64 insertions(+), 2 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 92a92d9..b673718 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,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++) + ++total; + } ++ if (new_features & NOTMUCH_FEATURE_GHOSTS) { ++ /* The ghost message upgrade converts all thread_id_* ++ * metadata values into ghost message documents. */ ++ 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 +1386,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 +1459,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + } + + talloc_free (local); +- return NOTMUCH_STATUS_SUCCESS; ++ return status; + } + + notmuch_status_t +-- +2.1.0 + -- 2.26.2