1 Return-Path: <aclements@csail.mit.edu>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by olra.theworths.org (Postfix) with ESMTP id 1F2F9431FC0
\r
6 for <notmuch@notmuchmail.org>; Mon, 6 Oct 2014 16:17:43 -0700 (PDT)
\r
7 X-Virus-Scanned: Debian amavisd-new at olra.theworths.org
\r
11 X-Spam-Status: No, score=-2.3 tagged_above=-999 required=5
\r
12 tests=[RCVD_IN_DNSWL_MED=-2.3] autolearn=disabled
\r
13 Received: from olra.theworths.org ([127.0.0.1])
\r
14 by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id GLMpMRwGzRw5 for <notmuch@notmuchmail.org>;
\r
16 Mon, 6 Oct 2014 16:17:39 -0700 (PDT)
\r
17 Received: from dmz-mailsec-scanner-5.mit.edu (dmz-mailsec-scanner-5.mit.edu
\r
19 by olra.theworths.org (Postfix) with ESMTP id 902B7431FBF
\r
20 for <notmuch@notmuchmail.org>; Mon, 6 Oct 2014 16:17:30 -0700 (PDT)
\r
21 X-AuditID: 12074422-f79436d000000c21-12-5433230aed96
\r
22 Received: from mailhub-auth-4.mit.edu ( [18.7.62.39])
\r
23 (using TLS with cipher AES256-SHA (256/256 bits))
\r
24 (Client did not present a certificate)
\r
25 by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP
\r
26 id E3.37.03105.A0323345; Mon, 6 Oct 2014 19:17:30 -0400 (EDT)
\r
27 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
28 by mailhub-auth-4.mit.edu (8.13.8/8.9.2) with ESMTP id s96NHPGu032086;
\r
29 Mon, 6 Oct 2014 19:17:25 -0400
\r
30 Received: from drake.dyndns.org ([12.185.136.2]) (authenticated bits=0)
\r
31 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
32 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s96NHMCT014473
\r
33 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=NOT);
\r
34 Mon, 6 Oct 2014 19:17:24 -0400
\r
35 Received: from amthrax by drake.dyndns.org with local (Exim 4.84)
\r
36 (envelope-from <aclements@csail.mit.edu>)
\r
37 id 1XbHWs-0001Jq-71; Mon, 06 Oct 2014 17:17:22 -0600
\r
38 From: Austin Clements <aclements@csail.mit.edu>
\r
39 To: notmuch@notmuchmail.org
\r
40 Subject: [PATCH v2 09/12] lib: Implement upgrade to ghost messages feature
\r
41 Date: Mon, 6 Oct 2014 17:17:15 -0600
\r
42 Message-Id: <1412637438-4821-10-git-send-email-aclements@csail.mit.edu>
\r
43 X-Mailer: git-send-email 2.1.0
\r
44 In-Reply-To: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>
\r
45 References: <1412637438-4821-1-git-send-email-aclements@csail.mit.edu>
\r
46 X-Brightmail-Tracker:
\r
47 H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixG6nrsulbBxi8Oi+mMWN1m5Gi+s3ZzI7
\r
48 MHk8W3WL2WPLoffMAUxRXDYpqTmZZalF+nYJXBmrd+5mKdggW3Fr4nf2Bsap4l2MnBwSAiYS
\r
49 J2/tYISwxSQu3FvP1sXIxSEkMJtJYsnF9ewQzgZGiR9/+1khnKVMEsvunmGEcJYwSmw8fpMZ
\r
50 pJ9NQF9ixdpJrCC2iIC0xM67s8FsZgFLiatf25lAbGEBL4nfV5awdDFycLAIqErcmOcNEuYV
\r
51 cJe4PqeZHeIMOYkNu/+DncQJFF9zZTLYGCEBN4nnP5+yTGDkX8DIsIpRNiW3Sjc3MTOnODVZ
\r
52 tzg5MS8vtUjXVC83s0QvNaV0EyM4lFyUdjD+PKh0iFGAg1GJhzdih2GIEGtiWXFl7iFGSQ4m
\r
53 JVHeOezGIUJ8SfkplRmJxRnxRaU5qcWHGCU4mJVEeLl+G4UI8aYkVlalFuXDpKQ5WJTEeTf9
\r
54 4AsREkhPLEnNTk0tSC2CycpwcChJ8HYoAg0VLEpNT61Iy8wpQUgzcXCCDOcBGn4IpIa3uCAx
\r
55 tzgzHSJ/ilFRSpw3GCQhAJLIKM2D64XF+itGcaBXhHnng1TxANMEXPcroMFMQINN5+iDDC5J
\r
56 REhJNTAy3+mI2M2196EUO5OewVInlrPhFzYKFK59nrRXdLdypswLu0atdZWP5m6zMxJa+b/n
\r
57 5aIZZ85qfF5+tu/ViQt7Jzx3eT09LbRm+X2mmpWef5LD83iuaYte/FW067esTO3tgLj5xern
\r
58 Gk/vdGzO9lSo73fQXOeoNPNhIpfRlStX/x+/7bmCee0+JZbijERDLeai4kQA2ao+X9ACAAA=
\r
59 X-BeenThere: notmuch@notmuchmail.org
\r
60 X-Mailman-Version: 2.1.13
\r
62 List-Id: "Use and development of the notmuch mail system."
\r
63 <notmuch.notmuchmail.org>
\r
64 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
65 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
66 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
67 List-Post: <mailto:notmuch@notmuchmail.org>
\r
68 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
69 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
70 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
71 X-List-Received-Date: Mon, 06 Oct 2014 23:17:43 -0000
\r
73 From: Austin Clements <amdragon@mit.edu>
\r
75 Somehow this is the first upgrade pass that actually does *any* error
\r
76 checking, so this also adds the bit of necessary infrastructure to
\r
79 lib/database.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
\r
80 1 file changed, 64 insertions(+), 2 deletions(-)
\r
82 diff --git a/lib/database.cc b/lib/database.cc
\r
83 index fdcc526..1316529 100644
\r
84 --- a/lib/database.cc
\r
85 +++ b/lib/database.cc
\r
86 @@ -1231,6 +1231,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
87 notmuch_bool_t timer_is_active = FALSE;
\r
88 enum _notmuch_features target_features, new_features;
\r
89 notmuch_status_t status;
\r
90 + notmuch_private_status_t private_status;
\r
91 unsigned int count = 0, total = 0;
\r
93 status = _notmuch_database_ensure_writable (notmuch);
\r
94 @@ -1275,6 +1276,13 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
95 for (t = db->allterms_begin ("XTIMESTAMP"); t != t_end; t++)
\r
98 + if (new_features & NOTMUCH_FEATURE_GHOSTS) {
\r
99 + /* The ghost message upgrade converts all thread_id_*
\r
100 + * metadata values into ghost message documents. */
\r
101 + t_end = db->metadata_keys_end ("thread_id_");
\r
102 + for (t = db->metadata_keys_begin ("thread_id_"); t != t_end; ++t)
\r
106 /* Perform the upgrade in a transaction. */
\r
107 db->begin_transaction (true);
\r
108 @@ -1378,10 +1386,64 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
112 + /* Perform metadata upgrades. */
\r
114 + /* Prior to NOTMUCH_FEATURE_GHOSTS, thread IDs for missing
\r
115 + * messages were stored as database metadata. Change these to
\r
116 + * ghost messages.
\r
118 + if (new_features & NOTMUCH_FEATURE_GHOSTS) {
\r
119 + notmuch_message_t *message;
\r
120 + std::string message_id, thread_id;
\r
122 + t_end = db->metadata_keys_end (NOTMUCH_METADATA_THREAD_ID_PREFIX);
\r
123 + for (t = db->metadata_keys_begin (NOTMUCH_METADATA_THREAD_ID_PREFIX);
\r
124 + t != t_end; ++t) {
\r
125 + if (do_progress_notify) {
\r
126 + progress_notify (closure, (double) count / total);
\r
127 + do_progress_notify = 0;
\r
130 + message_id = (*t).substr (
\r
131 + strlen (NOTMUCH_METADATA_THREAD_ID_PREFIX));
\r
132 + thread_id = db->get_metadata (*t);
\r
134 + /* Create ghost message */
\r
135 + message = _notmuch_message_create_for_message_id (
\r
136 + notmuch, message_id.c_str (), &private_status);
\r
137 + if (private_status == NOTMUCH_PRIVATE_STATUS_SUCCESS) {
\r
138 + /* Document already exists; ignore the stored thread ID */
\r
139 + } else if (private_status ==
\r
140 + NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND) {
\r
141 + private_status = _notmuch_message_initialize_ghost (
\r
142 + message, thread_id.c_str ());
\r
143 + if (! private_status)
\r
144 + _notmuch_message_sync (message);
\r
147 + if (private_status) {
\r
149 + "Upgrade failed while creating ghost messages.\n");
\r
150 + status = COERCE_STATUS (private_status, "Unexpected status from _notmuch_message_initialize_ghost");
\r
154 + /* Clear saved metadata thread ID */
\r
155 + db->set_metadata (*t, "");
\r
161 + status = NOTMUCH_STATUS_SUCCESS;
\r
162 db->set_metadata ("features", _print_features (local, notmuch->features));
\r
163 db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));
\r
165 - db->commit_transaction ();
\r
167 + if (status == NOTMUCH_STATUS_SUCCESS)
\r
168 + db->commit_transaction ();
\r
170 + db->cancel_transaction ();
\r
172 if (timer_is_active) {
\r
173 /* Now stop the timer. */
\r
174 @@ -1397,7 +1459,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
177 talloc_free (local);
\r
178 - return NOTMUCH_STATUS_SUCCESS;
\r