1 Return-Path: <amdragon@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 11196431FCB
\r
6 for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:38 -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 unXTh991hghl for <notmuch@notmuchmail.org>;
\r
16 Sat, 26 Jul 2014 20:53:32 -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 344CD431FD2
\r
20 for <notmuch@notmuchmail.org>; Sat, 26 Jul 2014 20:53:09 -0700 (PDT)
\r
21 X-AuditID: 12074422-f79be6d000007518-4f-53d477a2a55b
\r
22 Received: from mailhub-auth-2.mit.edu ( [18.7.62.36])
\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 DD.39.29976.2A774D35; Sat, 26 Jul 2014 23:53:07 -0400 (EDT)
\r
27 Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11])
\r
28 by mailhub-auth-2.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r4xh014368;
\r
29 Sat, 26 Jul 2014 23:53:05 -0400
\r
30 Received: from drake.dyndns.org
\r
31 (216-15-114-40.c3-0.arl-ubr1.sbo-arl.ma.cable.rcn.com
\r
32 [216.15.114.40]) (authenticated bits=0)
\r
33 (User authenticated as amdragon@ATHENA.MIT.EDU)
\r
34 by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s6R3r0xt016402
\r
35 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT);
\r
36 Sat, 26 Jul 2014 23:53:04 -0400
\r
37 Received: from amthrax by drake.dyndns.org with local (Exim 4.77)
\r
38 (envelope-from <amdragon@mit.edu>)
\r
39 id 1XBFW8-00051R-CS; Sat, 26 Jul 2014 23:53:00 -0400
\r
40 From: Austin Clements <amdragon@MIT.EDU>
\r
41 To: notmuch@notmuchmail.org
\r
42 Subject: [PATCH 08/14] lib: Simplify upgrade code using a transaction
\r
43 Date: Sat, 26 Jul 2014 23:52:47 -0400
\r
44 Message-Id: <1406433173-19169-9-git-send-email-amdragon@mit.edu>
\r
45 X-Mailer: git-send-email 2.0.0
\r
46 In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu>
\r
47 References: <1406433173-19169-1-git-send-email-amdragon@mit.edu>
\r
48 X-Brightmail-Tracker:
\r
49 H4sIAAAAAAAAA+NgFlrHIsWRmVeSWpSXmKPExsUixG6noru4/EqwwbFJjBbXb85kdmD0eLbq
\r
50 FnMAYxSXTUpqTmZZapG+XQJXxovn0QVr5Sr6unrYGhhfincxcnBICJhIbJ3t1MXICWSKSVy4
\r
51 t54NxBYSmM0kcfxkRBcjF5C9kVHi8/FbTBDOHSaJbasesUI4cxkljm/+yQTSwiagIbFt/3JG
\r
52 EFtEQFpi593ZrCAbmAXUJP50qYCEhQVcJSbefw+2gUVAVWLml72MICW8Ag4SV45XQxwhJ9Fw
\r
53 4xNYCaeAo8TxZyfYQEqEgEpuXUqcwMi/gJFhFaNsSm6Vbm5iZk5xarJucXJiXl5qka6pXm5m
\r
54 iV5qSukmRnCwuCjtYPx5UOkQowAHoxIPbwbblWAh1sSy4srcQ4ySHExKorz7zYBCfEn5KZUZ
\r
55 icUZ8UWlOanFhxglOJiVRHiFioFyvCmJlVWpRfkwKWkOFiVx3rfWVsFCAumJJanZqakFqUUw
\r
56 WRkODiUJXilgVAgJFqWmp1akZeaUIKSZODhBhvMADd9QCjK8uCAxtzgzHSJ/ilFRSpz3F0hC
\r
57 ACSRUZoH1wuL5leM4kCvCPOylgFV8QATAVz3K6DBTECDWfwvgwwuSURISTUwxvznOXvj9+yW
\r
58 mOyZWR/3/61+PWu+U5zVv+M/Zhtbt7rw1UjMe+OtKhU6LWnPYYdVaaEvXz7qsPi86NJXM8sN
\r
59 TSaV5ytUFY7K996Rnn/3xGYzdgMLaeUDtxhnn4lPl3n1zs3bdlfElKKTE0WvLH5z8BBX/N8N
\r
60 r8qaLG7xX13j1npKk+lx39JVbEosxRmJhlrMRcWJAHRQWqLBAgAA
\r
61 X-BeenThere: notmuch@notmuchmail.org
\r
62 X-Mailman-Version: 2.1.13
\r
64 List-Id: "Use and development of the notmuch mail system."
\r
65 <notmuch.notmuchmail.org>
\r
66 List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,
\r
67 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
68 List-Archive: <http://notmuchmail.org/pipermail/notmuch>
\r
69 List-Post: <mailto:notmuch@notmuchmail.org>
\r
70 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
71 List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,
\r
72 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
73 X-List-Received-Date: Sun, 27 Jul 2014 03:53:38 -0000
\r
75 Previously, the upgrade was organized as two passes -- an upgrade
\r
76 pass, and a separate cleanup pass -- so the database was always in a
\r
77 valid state. This change substantially simplifies this code by
\r
78 performing the upgrade in a transaction and combining both passes in
\r
79 to one. This 1) eliminates a lot of duplicate code between the
\r
80 passes, 2) speeds up the upgrade process, 3) makes progress reporting
\r
81 more accurate, 4) eliminates the potential for stale data if the
\r
82 upgrade is interrupted during the cleanup pass, and 5) makes it easier
\r
83 to reason about the safety of the upgrade code.
\r
85 lib/database.cc | 67 ++++++---------------------------------------------------
\r
86 1 file changed, 7 insertions(+), 60 deletions(-)
\r
88 diff --git a/lib/database.cc b/lib/database.cc
\r
89 index 03eef3e..0be7180 100644
\r
90 --- a/lib/database.cc
\r
91 +++ b/lib/database.cc
\r
92 @@ -1238,6 +1238,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
93 timer_is_active = TRUE;
\r
96 + /* Perform the upgrade in a transaction. */
\r
97 + db->begin_transaction (true);
\r
99 /* Before version 1, each message document had its filename in the
\r
100 * data field. Copy that into the new format by calling
\r
101 * notmuch_message_add_filename.
\r
102 @@ -1265,6 +1268,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
103 filename = _notmuch_message_talloc_copy_data (message);
\r
104 if (filename && *filename != '\0') {
\r
105 _notmuch_message_add_filename (message, filename);
\r
106 + _notmuch_message_clear_data (message);
\r
107 _notmuch_message_sync (message);
\r
109 talloc_free (filename);
\r
110 @@ -1312,6 +1316,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
111 NOTMUCH_FIND_CREATE, &status);
\r
112 notmuch_directory_set_mtime (directory, mtime);
\r
113 notmuch_directory_destroy (directory);
\r
115 + db->delete_document (*p);
\r
119 @@ -1353,67 +1359,8 @@ notmuch_database_upgrade (notmuch_database_t *notmuch,
\r
120 notmuch->features |= NOTMUCH_FEATURES_CURRENT;
\r
121 db->set_metadata ("features", _print_features (local, notmuch->features));
\r
122 db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION));
\r
125 - /* Now that the upgrade is complete we can remove the old data
\r
126 - * and documents that are no longer needed. */
\r
127 - if (version < 1) {
\r
128 - notmuch_query_t *query = notmuch_query_create (notmuch, "");
\r
129 - notmuch_messages_t *messages;
\r
130 - notmuch_message_t *message;
\r
133 - for (messages = notmuch_query_search_messages (query);
\r
134 - notmuch_messages_valid (messages);
\r
135 - notmuch_messages_move_to_next (messages))
\r
137 - if (do_progress_notify) {
\r
138 - progress_notify (closure, (double) count / total);
\r
139 - do_progress_notify = 0;
\r
142 - message = notmuch_messages_get (messages);
\r
144 - filename = _notmuch_message_talloc_copy_data (message);
\r
145 - if (filename && *filename != '\0') {
\r
146 - _notmuch_message_clear_data (message);
\r
147 - _notmuch_message_sync (message);
\r
149 - talloc_free (filename);
\r
151 - notmuch_message_destroy (message);
\r
154 - notmuch_query_destroy (query);
\r
157 - if (version < 1) {
\r
158 - Xapian::TermIterator t, t_end;
\r
160 - t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP");
\r
162 - for (t = notmuch->xapian_db->allterms_begin ("XTIMESTAMP");
\r
166 - Xapian::PostingIterator p, p_end;
\r
167 - std::string term = *t;
\r
169 - p_end = notmuch->xapian_db->postlist_end (term);
\r
171 - for (p = notmuch->xapian_db->postlist_begin (term);
\r
175 - if (do_progress_notify) {
\r
176 - progress_notify (closure, (double) count / total);
\r
177 - do_progress_notify = 0;
\r
180 - db->delete_document (*p);
\r
184 + db->commit_transaction ();
\r
186 if (timer_is_active) {
\r
187 /* Now stop the timer. */
\r