From: Austin Clements Date: Fri, 1 Aug 2014 02:09:58 +0000 (+2000) Subject: [PATCH v3 08/13] lib: Use database features to drive upgrade X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ce5ea02a98fb6f34a4a7ad9f8debcc9998d27c43;p=notmuch-archives.git [PATCH v3 08/13] lib: Use database features to drive upgrade --- diff --git a/68/b61260eb9a45e5af8599ab6dc1e0a5f6e03950 b/68/b61260eb9a45e5af8599ab6dc1e0a5f6e03950 new file mode 100644 index 000000000..69494ca3a --- /dev/null +++ b/68/b61260eb9a45e5af8599ab6dc1e0a5f6e03950 @@ -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 C584C431FD5 + for ; Thu, 31 Jul 2014 19:11:00 -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 YqQCcv8AaLLh for ; + Thu, 31 Jul 2014 19:10:54 -0700 (PDT) +Received: from dmz-mailsec-scanner-3.mit.edu (dmz-mailsec-scanner-3.mit.edu + [18.9.25.14]) + (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) + (No client certificate requested) + by olra.theworths.org (Postfix) with ESMTPS id 3FC61431FD6 + for ; Thu, 31 Jul 2014 19:10:20 -0700 (PDT) +X-AuditID: 1209190e-f79946d000007db1-4d-53daf70b2dd0 +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-3.mit.edu (Symantec Messaging Gateway) with SMTP + id 14.DF.32177.B07FAD35; Thu, 31 Jul 2014 22:10:20 -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 s712A8WO008856; + Thu, 31 Jul 2014 22:10:08 -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 s712A6VS029985 + (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); + Thu, 31 Jul 2014 22:10:08 -0400 +Received: from amthrax by drake.dyndns.org with local (Exim 4.77) + (envelope-from ) + id 1XD2II-00033o-2y; Thu, 31 Jul 2014 22:10:06 -0400 +From: Austin Clements +To: notmuch@notmuchmail.org +Subject: [PATCH v3 08/13] lib: Use database features to drive upgrade +Date: Thu, 31 Jul 2014 22:09:58 -0400 +Message-Id: <1406859003-11561-9-git-send-email-amdragon@mit.edu> +X-Mailer: git-send-email 2.0.0 +In-Reply-To: <1406859003-11561-1-git-send-email-amdragon@mit.edu> +References: <1406859003-11561-1-git-send-email-amdragon@mit.edu> +X-Brightmail-Tracker: + H4sIAAAAAAAAA+NgFtrLIsWRmVeSWpSXmKPExsUixCmqrcvz/Vawwc0PjBar5/JYXL85k9mB + yWPnrLvsHs9W3WIOYIrisklJzcksSy3St0vgyni6ejpzwTbJiqd9L9kbGCeIdDFyckgImEg8 + 27OPHcIWk7hwbz1bFyMXh5DAbCaJKSc3M0E4Gxklvk2YCOXcYZL4+uY0C4Qzl1Hi4bpzjCD9 + bAIaEtv2LwezRQSkJXbenc0KYjMLOEp83r+IDcQWFnCV+NYzCSzOIqAq8eDaBLDdvAIOElNP + zIS6Q06i4cYnsHpOoN7//xaA1QsB1bSe3so8gZF/ASPDKkbZlNwq3dzEzJzi1GTd4uTEvLzU + Il1jvdzMEr3UlNJNjOBQkuTbwfj1oNIhRgEORiUe3hnht4KFWBPLiitzDzFKcjApifLafAQK + 8SXlp1RmJBZnxBeV5qQWH2KU4GBWEuF9+QEox5uSWFmVWpQPk5LmYFES531rbRUsJJCeWJKa + nZpakFoEk5Xh4FCS4D3zFahRsCg1PbUiLTOnBCHNxMEJMpwHaLjQN5DhxQWJucWZ6RD5U4yK + UuK8e0CaBUASGaV5cL2wWH/FKA70ijDvQ5AqHmCagOt+BTSYCWjw81vXQQaXJCKkpBoYA9Pi + Q0949sXP/p2o+u93ReH8fN3WE9m7NrGe14yYtmKr4beMVIV6+wclO//uuDTvw71Ikb6VCWrb + +U4aTwq7xvRQ5/XPGawee6fvY3zpv34/64cbJd88l9kz8jYE1cRfUAi6J6i74cj07nXuyYvn + 7jxmvIJ/9UO2lWdPlx2ysoz6knOYP+K2pRJLcUaioRZzUXEiAJmPyifQAgAA +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: Fri, 01 Aug 2014 02:11:01 -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 faeab51..69d775f 100644 +--- a/lib/database.cc ++++ b/lib/database.cc +@@ -1195,11 +1195,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; ++ unsigned int target_features, new_features; + notmuch_status_t status; + unsigned int count = 0, total = 0; + +@@ -1209,9 +1210,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) { +@@ -1237,18 +1239,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); + +@@ -1277,11 +1278,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"); +@@ -1325,7 +1327,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 +