From: Austin Clements <aclements@csail.mit.edu>
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 [thread overview]
Message-ID: <1414067441-29054-7-git-send-email-aclements@csail.mit.edu> (raw)
In-Reply-To: <1414067441-29054-1-git-send-email-aclements@csail.mit.edu>
From: Austin Clements <amdragon@mit.edu>
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
next prev parent reply other threads:[~2014-10-23 12:31 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-23 12:30 [PATCH v3 0/9] Add ghost messages and fix thread linking Austin Clements
2014-10-23 12:30 ` [PATCH v3 1/9] lib: Add a ghost messages database feature Austin Clements
2014-10-23 12:30 ` [PATCH v3 2/9] lib: Update database schema doc for ghost messages Austin Clements
2014-10-23 12:30 ` [PATCH v3 3/9] lib: Introduce macros for bit operations Austin Clements
2014-10-24 4:40 ` Jani Nikula
2014-10-24 12:49 ` [PATCH v3.1 " Austin Clements
2014-10-23 12:30 ` [PATCH v3 4/9] lib: Internal support for querying and creating ghost messages Austin Clements
2014-10-23 12:30 ` [PATCH v3 5/9] lib: Implement ghost-based thread linking Austin Clements
2014-10-23 12:30 ` Austin Clements [this message]
2014-10-23 12:30 ` [PATCH v3 7/9] lib: Enable ghost messages feature Austin Clements
2014-10-23 12:30 ` [PATCH v3 8/9] test: Test upgrade to " Austin Clements
2014-10-23 12:30 ` [PATCH v3 9/9] lib: Remove unnecessary thread linking steps when using ghost messages Austin Clements
2014-10-25 18:02 ` [PATCH v3 0/9] Add ghost messages and fix thread linking David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1414067441-29054-7-git-send-email-aclements@csail.mit.edu \
--to=aclements@csail.mit.edu \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).