From: Austin Clements Date: Mon, 25 Aug 2014 17:26:04 +0000 (+2000) Subject: [PATCH v4 06/11] lib: Use database features to drive upgrade X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=38b651980daf35cc32b3ca27bf2fca4c58eb8b47;p=notmuch-archives.git [PATCH v4 06/11] lib: Use database features to drive upgrade --- diff --git a/ad/c9ce0a022cb4a5e260a4eda538380cbfc31e26 b/ad/c9ce0a022cb4a5e260a4eda538380cbfc31e26 new file mode 100644 index 000000000..fcc9a1eb0 --- /dev/null +++ b/ad/c9ce0a022cb4a5e260a4eda538380cbfc31e26 @@ -0,0 +1,164 @@ +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 0EC13431FBC + for ; Mon, 25 Aug 2014 10:26:35 -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 XhRM-ylbaTX7 for ; + Mon, 25 Aug 2014 10:26:29 -0700 (PDT) +Received: from dmz-mailsec-scanner-1.mit.edu (dmz-mailsec-scanner-1.mit.edu + [18.9.25.12]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 84990431FBD + for ; Mon, 25 Aug 2014 10:26:19 -0700 (PDT) +X-AuditID: 1209190c-f795e6d000006c66-af-53fb71b9585b +Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) + (using TLS with cipher AES256-SHA (256/256 bits)) + (Client did not present a certificate) + by dmz-mailsec-scanner-1.mit.edu (Symantec Messaging Gateway) with SMTP + id 8F.F6.27750.9B17BF35; Mon, 25 Aug 2014 13:26:17 -0400 (EDT) +Received: from outgoing.mit.edu (outgoing-auth-1.mit.edu [18.9.28.11]) + by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id s7PHQE4v007793; + Mon, 25 Aug 2014 13:26:14 -0400 +Received: from drake.dyndns.org (31-35-14.wireless.csail.mit.edu + [128.31.35.14]) (authenticated bits=0) + (User authenticated as amdragon@ATHENA.MIT.EDU) + by outgoing.mit.edu (8.13.8/8.12.4) with ESMTP id s7PHQCBA029615 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Mon, 25 Aug 2014 13:26:13 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XLy20-0003jY-0d; Mon, 25 Aug 2014 13:26:12 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v4 06/11] lib: Use database features to drive upgrade +Date: Mon, 25 Aug 2014 13:26:04 -0400 +Message-Id: <1408987569-14146-7-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1408987569-14146-1-git-send-email-amdragon@mit.edu> +References: <1408987569-14146-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFjrKIsWRmVeSWpSXmKPExsUixCmqrLuz8HewwfsnGhY3WrsZLZqmO1tc + vzmT2YHZ49b91+wez1bdYvbYcug9cwBzFJdNSmpOZllqkb5dAlfGmb1bWQoOSFb8uLaPsYFx + lkgXIyeHhICJxMbmhywQtpjEhXvr2boYuTiEBGYzSax5sJcVwtnIKHHnVBszSJWQwDEmiftN + ZhCJuYwSi+49ZAdJsAloSPy+tZgJxBYRkJbYeXc2K4jNLOAlsexCP5gtLOAq8al/O1gNi4Cq + xJULO4F6OTh4BRwkJhwzh7hCTqLhxic2EJtTwFFi+sLZTBB7HSS+Xz7PPIGRfwEjwypG2ZTc + Kt3cxMyc4tRk3eLkxLy81CJdQ73czBK91JTSTYzg0JLk2cH45qDSIUYBDkYlHt4b8b+DhVgT + y4orcw8xSnIwKYnyTssHCvEl5adUZiQWZ8QXleakFh9ilOBgVhLhbQbJ8aYkVlalFuXDpKQ5 + WJTEed9aWwULCaQnlqRmp6YWpBbBZGU4OJQkeHMLgBoFi1LTUyvSMnNKENJMHJwgw3mAhseD + 1PAWFyTmFmemQ+RPMSpKifOuBdkqAJLIKM2D64XF/itGcaBXhHmPgrTzANMGXPcroMFMQINN + e36CDC5JREhJNTCq3Lt3fcXef7f0qy1OhR38+aeM16WQkXuW61TWigUsD+/4X7uvffulkqjD + GtHsolVO3hslZW9ze/ecWdr6pb0nkynyajCf2NW8cvnje9L+Cr4p2GBcvPfQjzMLGLb4nc1T + VZzQeWvjeiXjuXs2yqQ8LHvlduT+rEtHr14ozXfRbvNVF/u9rjxMiaU4I9FQi7moOBEAvrCj + EdgCAAA= +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, 25 Aug 2014 17:26:35 -0000 + +Previously, we had database version information hard-coded in the +upgrade code. Slightly re-organize the upgrade process around the set +of new database features to be enabled by the upgrade. +--- + lib/database.cc | 24 +++++++++++++----------- + 1 file changed, 13 insertions(+), 11 deletions(-) + +diff --git a/lib/database.cc b/lib/database.cc +index 1e46fc8..525c9c3 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -1202,11 +1202,12 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + void *closure) + { + void *local = talloc_new (NULL); ++ Xapian::TermIterator t, t_end; + Xapian::WritableDatabase *db; + struct sigaction action; + struct itimerval timerval; + notmuch_bool_t timer_is_active = FALSE; +- unsigned int version; ++ enum _notmuch_features target_features, new_features; + notmuch_status_t status; + unsigned int count = 0, total = 0; + +@@ -1216,9 +1217,10 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + + db = static_cast (notmuch->xapian_db); + +- version = notmuch_database_get_version (notmuch); ++ target_features = notmuch->features | NOTMUCH_FEATURES_CURRENT; ++ new_features = NOTMUCH_FEATURES_CURRENT & ~notmuch->features; + +- if (version >= NOTMUCH_DATABASE_VERSION) ++ if (! new_features) + return NOTMUCH_STATUS_SUCCESS; + + if (progress_notify) { +@@ -1244,18 +1246,17 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + + /* Set the target features so we write out changes in the desired + * format. */ +- notmuch->features |= NOTMUCH_FEATURES_CURRENT; ++ notmuch->features = target_features; + + /* 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 (version < 1) { ++ if (new_features & NOTMUCH_FEATURE_FILE_TERMS) { + notmuch_query_t *query = notmuch_query_create (notmuch, ""); + notmuch_messages_t *messages; + notmuch_message_t *message; + char *filename; +- Xapian::TermIterator t, t_end; + + total = notmuch_query_count_messages (query); + +@@ -1284,11 +1285,12 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + } + + notmuch_query_destroy (query); ++ } + +- /* Also, before version 1 we stored directory timestamps in +- * XTIMESTAMP documents instead of the current XDIRECTORY +- * documents. So copy those as well. */ +- ++ /* Also, 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) { + t_end = notmuch->xapian_db->allterms_end ("XTIMESTAMP"); + + for (t = notmuch->xapian_db->allterms_begin ("XTIMESTAMP"); +@@ -1332,7 +1334,7 @@ notmuch_database_upgrade (notmuch_database_t *notmuch, + * stemmed. Change it to the current boolean prefix. Add "path:" + * prefixes while at it. + */ +- if (version < 2) { ++ if (new_features & NOTMUCH_FEATURE_BOOL_FOLDER) { + notmuch_query_t *query = notmuch_query_create (notmuch, ""); + notmuch_messages_t *messages; + notmuch_message_t *message; +-- +2.0.0 +