From: Austin Clements Date: Mon, 6 Oct 2014 23:17:15 +0000 (+1800) Subject: [PATCH v2 09/12] lib: Implement upgrade to ghost messages feature X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=1cc045057114db72cc0c04fe3e8bd0f511778bb3;p=notmuch-archives.git [PATCH v2 09/12] lib: Implement upgrade to ghost messages feature --- diff --git a/cb/1044cd242cd271a0950f5b88b36f5145825f81 b/cb/1044cd242cd271a0950f5b88b36f5145825f81 new file mode 100644 index 000000000..b716ef9a7 --- /dev/null +++ b/cb/1044cd242cd271a0950f5b88b36f5145825f81 @@ -0,0 +1,185 @@ +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 1F2F9431FC0 + for ; Mon, 6 Oct 2014 16:17:43 -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 GLMpMRwGzRw5 for ; + Mon, 6 Oct 2014 16:17:39 -0700 (PDT) +Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu + [18.7.68.34]) + by olra.theworths.org (Postfix) with ESMTP id 902B7431FBF + for ; Mon, 6 Oct 2014 16:17:30 -0700 (PDT) +X-AuditID: 12074422-f79436d000000c21-12-5433230aed96 +Received: from mailhub-auth-4.mit.edu ( [18.7.62.39]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP + id E3.37.03105.A0323345; Mon, 6 Oct 2014 19:17:30 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s96NHPGu032086; + Mon, 6 Oct 2014 19:17:25 -0400 +Received: from drake.dyndns.org ([12.185.136.2]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s96NHMCT014473 + (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT); + Mon, 6 Oct 2014 19:17:24 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.84) + (envelope-from ) + id 1XbHWs-0001Jq-71; Mon, 06 Oct 2014 17:17:22 -0600 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v2 09/12] lib: Implement upgrade to ghost messages feature +Date: Mon, 6 Oct 2014 17:17:15 -0600 +Message-Id: <1412637438-4821-10-git-send-email-aclements@csail.mit.edu> +X-Mailer: git-send-email 2.1.0 +In-Reply-To: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu> +References: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixG6nrsulbBxi8Oi+mMWN1m5Gi+s3ZzI7 + MHk8W3WL2WPLoffMAUxRXDYpqTmZZalF+nYJXBmrd+5mKdggW3Fr4nf2Bsap4l2MnBwSAiYS + J2/tYISwxSQu3FvP1sXIxSEkMJtJYsnF9ewQzgZGiR9/+1khnKVMEsvunmGEcJYwSmw8fpMZ + pJ9NQF9ixdpJrCC2iIC0xM67s8FsZgFLiatf25lAbGEBL4nfV5awdDFycLAIqErcmOcNEuYV + cJe4PqeZHeIMOYkNu/+DncQJFF9zZTLYGCEBN4nnP5+yTGDkX8DIsIpRNiW3Sjc3MTOnODVZ + tzg5MS8vtUjXVC83s0QvNaV0EyM4lFyUdjD+PKh0iFGAg1GJhzdih2GIEGtiWXFl7iFGSQ4m + JVHeOezGIUJ8SfkplRmJxRnxRaU5qcWHGCU4mJVEeLl+G4UI8aYkVlalFuXDpKQ5WJTEeTf9 + 4AsREkhPLEnNTk0tSC2CycpwcChJ8HYoAg0VLEpNT61Iy8wpQUgzcXCCDOcBGn4IpIa3uCAx + tzgzHSJ/ilFRSpw3GCQhAJLIKM2D64XF+itGcaBXhHnng1TxANMEXPcroMFMQINN5+iDDC5J + REhJNTAy3+mI2M2196EUO5OewVInlrPhFzYKFK59nrRXdLdypswLu0atdZWP5m6zMxJa+b/n + 5aIZZ85qfF5+tu/ViQt7Jzx3eT09LbRm+X2mmpWef5LD83iuaYte/FW067esTO3tgLj5xern + Gk/vdGzO9lSo73fQXOeoNPNhIpfRlStX/x+/7bmCee0+JZbijERDLeai4kQA2ao+X9ACAAA= +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: Mon, 06 Oct 2014 23:17:43 -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 fdcc526..1316529 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 +