From: Austin Clements Date: Sun, 27 Jul 2014 03:52:49 +0000 (+2000) Subject: [PATCH 10/14] lib: Reorganize upgrade around document types X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=4b0aec4c82a10c01605b24be0cf9499159fecaba;p=notmuch-archives.git [PATCH 10/14] lib: Reorganize upgrade around document types --- diff --git a/e1/d760a082d2a4c29c4414dfecfd56ea00c47946 b/e1/d760a082d2a4c29c4414dfecfd56ea00c47946 new file mode 100644 index 000000000..271d05280 --- /dev/null +++ b/e1/d760a082d2a4c29c4414dfecfd56ea00c47946 @@ -0,0 +1,193 @@ +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 DECA2431FD6 + for ; Sat, 26 Jul 2014 20:53:46 -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 pkaRQ0FBN+I8 for ; + Sat, 26 Jul 2014 20:53:41 -0700 (PDT) +Received: from dmz-mailsec-scanner-8.mit.edu (dmz-mailsec-scanner-8.mit.edu + [18.7.68.37]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id BC41D431FD5 + for ; Sat, 26 Jul 2014 20:53:13 -0700 (PDT) +X-AuditID: 12074425-f79766d000006da8-d6-53d477a97527 +Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-8.mit.edu (Symantec Messaging Gateway) with SMTP + id B1.5E.28072.9A774D35; Sat, 26 Jul 2014 23:53:13 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id s6R3r2eK004149; + Sat, 26 Jul 2014 23:53:02 -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 s6R3r0fF016406 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Sat, 26 Jul 2014 23:53:01 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XBFW8-00051W-E8; Sat, 26 Jul 2014 23:53:00 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH 10/14] lib: Reorganize upgrade around document types +Date: Sat, 26 Jul 2014 23:52:49 -0400 +Message-Id: <1406433173-19169-11-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406433173-19169-1-git-send-email-amdragon@mit.edu> +References: <1406433173-19169-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrIIsWRmVeSWpSXmKPExsUixCmqrbuy/Eqwwd9pyhbXb85kdmD0eLbq + FnMAYxSXTUpqTmZZapG+XQJXRvOS1ewFaxUrTnXMYW9gXCPVxcjJISFgIrH5ZisjhC0mceHe + erYuRi4OIYHZTBLrfxxnB0kICWxklNh1JhEicYdJYsGpU0wQzlxGiTv/ullAqtgENCS27V8O + NkpEQFpi593ZrF2MHBzMAmoSf7pUQMLCAi4Sh3sfg5WwCKhKnHn5nBXE5hVwlJi9ais7xBVy + Eg03PrGB2JxA8ePPTrCBjBEScJC4dSlxAiP/AkaGVYyyKblVurmJmTnFqcm6xcmJeXmpRboW + ermZJXqpKaWbGEEhw+6iuoNxwiGlQ4wCHIxKPLwCLFeChVgTy4orcw8xSnIwKYny7jcDCvEl + 5adUZiQWZ8QXleakFh9ilOBgVhLhFSoGyvGmJFZWpRblw6SkOViUxHnfWlsFCwmkJ5akZqem + FqQWwWRlODiUJHjDyoAaBYtS01Mr0jJzShDSTBycIMN5gIZvKAUZXlyQmFucmQ6RP8WoKCXO + GwuMSiEBkERGaR5cLyymXzGKA70izMsKsoIHmA7gul8BDWYCGszifxlkcEkiQkqqgTHs052Z + BVw9u59FPvwje/zmwuKI5QGlW1/URS33P/qs+tte//0+tk5H43YdLzy5QXH3M+YnkU0vb6+L + jrjY2zXlxf44mffiPx7EaYUubbnod71i0tuW/zWnnx6f1L7DfAbDj8Ir0VPVJ5/fX573jtM6 + 4r4xp0TqU4md2w/mLdn9pURuqtY5y0kLlViKMxINtZiLihMBz2hOVsQCAAA= +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: Sun, 27 Jul 2014 03:53:47 -0000 + +Rather than potentially making multiple passes over the same type of +data in the database, reorganize upgrade around each type of data that +may be upgraded. This eliminates code duplication, will make +multi-version upgrades faster, and will let us improve progress +reporting. +--- + lib/database.cc | 71 +++++++++++++++++++++------------------------------------ + 1 file changed, 26 insertions(+), 45 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 1dd2cd9..155cbac 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -1243,11 +1243,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + /* Perform the upgrade in a transaction. */ + db->begin_transaction (true); + +- /* Before version 1, each message document had its filename in the +- * data field. Copy that into the new format by calling +- * notmuch_message_add_filename. +- */ +- if (new_features & NOTMUCH_FEATURE_FILE_TERMS) { ++ /* Perform per-message upgrades. */ ++ if (new_features & ++ (NOTMUCH_FEATURE_FILE_TERMS | NOTMUCH_FEATURE_BOOL_FOLDER)) { + notmuch_query_t *query = notmuch_query_create (notmuch, ""); + notmuch_messages_t *messages; + notmuch_message_t *message; +@@ -1266,13 +1264,28 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + + message = notmuch_messages_get (messages); + +- filename = _notmuch_message_talloc_copy_data (message); +- if (filename && *filename != '\0') { +- _notmuch_message_add_filename (message, filename); +- _notmuch_message_clear_data (message); ++ /* Before version 1, each message document had its ++ * filename in the data field. Copy that into the new ++ * format by calling notmuch_message_add_filename. ++ */ ++ if (new_features & NOTMUCH_FEATURE_FILE_TERMS) { ++ filename = _notmuch_message_talloc_copy_data (message); ++ if (filename && *filename != '\0') { ++ _notmuch_message_add_filename (message, filename); ++ _notmuch_message_clear_data (message); ++ _notmuch_message_sync (message); ++ } ++ talloc_free (filename); ++ } ++ ++ /* Prior to version 2, the "folder:" prefix was ++ * probabilistic and stemmed. Change it to the current ++ * boolean prefix. Add "path:" prefixes while at it. ++ */ ++ if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) { ++ _notmuch_message_upgrade_folder (message); + _notmuch_message_sync (message); + } +- talloc_free (filename); + + notmuch_message_destroy (message); + +@@ -1282,7 +1295,9 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + notmuch_query_destroy (query); + } + +- /* Also, before version 1 we stored directory timestamps in ++ /* Perform per-directory upgrades. */ ++ ++ /* Before version 1 we stored directory timestamps in + * XTIMESTAMP documents instead of the current XDIRECTORY + * documents. So copy those as well. */ + if (new_features & NOTMUCH_FEATURE_DIRECTORY_DOCS) { +@@ -1324,40 +1339,6 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + } + } + +- /* +- * Prior to version 2, the "folder:" prefix was probabilistic and +- * stemmed. Change it to the current boolean prefix. Add "path:" +- * prefixes while at it. +- */ +- if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) { +- notmuch_query_t *query = notmuch_query_create (notmuch, ""); +- notmuch_messages_t *messages; +- notmuch_message_t *message; +- +- count = 0; +- total = notmuch_query_count_messages (query); +- +- for (messages = notmuch_query_search_messages (query); +- notmuch_messages_valid (messages); +- notmuch_messages_move_to_next (messages)) { +- if (do_progress_notify) { +- progress_notify (closure, (double) count / total); +- do_progress_notify = 0; +- } +- +- message = notmuch_messages_get (messages); +- +- _notmuch_message_upgrade_folder (message); +- _notmuch_message_sync (message); +- +- notmuch_message_destroy (message); +- +- count++; +- } +- +- notmuch_query_destroy (query); +- } +- + notmuch->features = target_features; + db->set_metadata ("features", _print_features (local, notmuch->features)); + db->set_metadata ("version", STRINGIFY (NOTMUCH_DATABASE_VERSION)); +-- +2.0.0 +