Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 2/2] box: fix Tarantool upgrade from 2.1.0 to 2.1.1
Date: Fri, 25 Jan 2019 14:12:25 +0300	[thread overview]
Message-ID: <791d55891bd2534a5d4570ab2e71888efc189f3b.1548414536.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1548414536.git.kshcherbatov@tarantool.org>

Tarantool could not start from the snapshot created by version
2.1.0 because the new version 2.1.1 does not support the
index.opts.sql index opt and stops the execution.
Introduced a special state OPT_DEF_LEGACY macro to ignore legacy
options and introduced migration code in upgrade.lua.
---
 src/box/index_def.c                           |   1 +
 src/box/lua/upgrade.lua                       |  26 +++++++++++++++++-
 src/box/opt_def.c                             |   3 ++
 src/box/opt_def.h                             |  12 +++++---
 test/sql/upgrade.test.lua                     |  17 ++++++++++++
 .../upgrade/2.1.0/00000000000000000003.snap   | Bin 0 -> 2124 bytes
 6 files changed, 54 insertions(+), 5 deletions(-)
 create mode 100644 test/sql/upgrade/2.1.0/00000000000000000003.snap

diff --git a/src/box/index_def.c b/src/box/index_def.c
index 2ba57ee9d..7d2c11729 100644
--- a/src/box/index_def.c
+++ b/src/box/index_def.c
@@ -60,6 +60,7 @@ const struct opt_def index_opts_reg[] = {
 	OPT_DEF("run_size_ratio", OPT_FLOAT, struct index_opts, run_size_ratio),
 	OPT_DEF("bloom_fpr", OPT_FLOAT, struct index_opts, bloom_fpr),
 	OPT_DEF("lsn", OPT_INT64, struct index_opts, lsn),
+	OPT_DEF_LEGACY("sql"),
 	OPT_END,
 };
 
diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
index 81f578e58..b5ef043eb 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -615,6 +615,29 @@ local function upgrade_to_2_1_0()
     upgrade_priv_to_2_1_0()
 end
 
+--------------------------------------------------------------------------------
+-- Tarantool 2.1.1
+--------------------------------------------------------------------------------
+
+local function upgrade_priv_to_2_1_1()
+    local _index = box.space[box.schema.INDEX_ID]
+    for _, index in _index:pairs() do
+        local opts = index.opts
+        for field, _ in pairs(opts) do
+            if field == 'sql' then
+                opts[field] = nil
+            end
+        end
+        _index:replace(box.tuple.new({index.id, index.iid, index.name,
+                                      index.type, opts, index.parts}))
+    end
+end
+
+local function upgrade_to_2_1_1()
+    log.info("started upgrade_to_2_1_1")
+    upgrade_priv_to_2_1_1()
+end
+
 local function get_version()
     local version = box.space._schema:get{'version'}
     if version == nil then
@@ -642,7 +665,8 @@ local function upgrade(options)
         {version = mkversion(1, 7, 7), func = upgrade_to_1_7_7, auto = true},
         {version = mkversion(1, 10, 0), func = upgrade_to_1_10_0, auto = true},
         {version = mkversion(1, 10, 2), func = upgrade_to_1_10_2, auto = true},
-        {version = mkversion(2, 1, 0), func = upgrade_to_2_1_0, auto = true}
+        {version = mkversion(2, 1, 0), func = upgrade_to_2_1_0, auto = true},
+        {version = mkversion(2, 1, 1), func = upgrade_to_2_1_1, auto = true}
     }
 
     for _, handler in ipairs(handlers) do
diff --git a/src/box/opt_def.c b/src/box/opt_def.c
index 1d1f09ed5..17c555a0e 100644
--- a/src/box/opt_def.c
+++ b/src/box/opt_def.c
@@ -167,6 +167,8 @@ opts_parse_key(void *opts, const struct opt_def *reg, const char *key,
 		if (key_len != strlen(def->name) ||
 		    memcmp(key, def->name, key_len) != 0)
 			continue;
+		if (def->is_legacy)
+			goto skip;
 
 		return opt_set(opts, def, data, region, errcode, field_no);
 	}
@@ -177,6 +179,7 @@ opts_parse_key(void *opts, const struct opt_def *reg, const char *key,
 		diag_set(ClientError, errcode, field_no, errmsg);
 		return -1;
 	}
+skip:
 	mp_next(data);
 	return 0;
 }
diff --git a/src/box/opt_def.h b/src/box/opt_def.h
index 318204e91..27d088e74 100644
--- a/src/box/opt_def.h
+++ b/src/box/opt_def.h
@@ -86,6 +86,7 @@ struct opt_def {
 	int enum_size;
 	const char **enum_strs;
 	uint32_t enum_max;
+	bool is_legacy;
 	/** MsgPack data decode callbacks. */
 	union {
 		opt_def_to_enum_cb to_enum;
@@ -95,18 +96,21 @@ struct opt_def {
 
 #define OPT_DEF(key, type, opts, field) \
 	{ key, type, offsetof(opts, field), sizeof(((opts *)0)->field), \
-	  NULL, 0, NULL, 0, {NULL} }
+	  NULL, 0, NULL, 0, false, {NULL} }
 
 #define OPT_DEF_ENUM(key, enum_name, opts, field, to_enum) \
 	{ key, OPT_ENUM, offsetof(opts, field), sizeof(int), #enum_name, \
 	  sizeof(enum enum_name), enum_name##_strs, enum_name##_MAX, \
-	  {(void *)to_enum} }
+	  false, {(void *)to_enum} }
 
 #define OPT_DEF_ARRAY(key, opts, field, to_array) \
 	 { key, OPT_ARRAY, offsetof(opts, field), sizeof(((opts *)0)->field), \
-	   NULL, 0, NULL, 0, {(void *)to_array} }
+	   NULL, 0, NULL, 0, false, {(void *)to_array} }
 
-#define OPT_END {NULL, opt_type_MAX, 0, 0, NULL, 0, NULL, 0, {NULL}}
+#define OPT_DEF_LEGACY(key) \
+	{ key, opt_type_MAX, 0, 0, NULL, 0, NULL, 0, true, {NULL} }
+
+#define OPT_END {NULL, opt_type_MAX, 0, 0, NULL, 0, NULL, 0, false, {NULL}}
 
 struct region;
 
diff --git a/test/sql/upgrade.test.lua b/test/sql/upgrade.test.lua
index cd4dd3cca..4a4cd63a9 100644
--- a/test/sql/upgrade.test.lua
+++ b/test/sql/upgrade.test.lua
@@ -53,3 +53,20 @@ box.sql.execute("DROP TABLE T_OUT;")
 test_run:switch('default')
 test_run:cmd('stop server upgrade')
 test_run:cmd('cleanup server upgrade')
+
+-- Test Tarantool 2.1.0 to 2.1.1 migration.
+work_dir = 'sql/upgrade/2.1.0/'
+test_run:cmd('create server upgrade210 with script="sql/upgrade/upgrade.lua", workdir="' .. work_dir .. '"')
+test_run:cmd('start server upgrade210')
+
+test_run:switch('upgrade210')
+
+s = box.space._space.index['name']:get('T2')
+s
+i = box.space._index:select(s.id)
+i
+i[1].opts.sql == nil
+
+test_run:switch('default')
+test_run:cmd('stop server upgrade210')
+test_run:cmd('cleanup server upgrade210')
diff --git a/test/sql/upgrade/2.1.0/00000000000000000003.snap b/test/sql/upgrade/2.1.0/00000000000000000003.snap
new file mode 100644
index 0000000000000000000000000000000000000000..25bb78734dd5680c510bdb36cf94776f19c4b0c2
GIT binary patch
literal 2124
zcmV-S2($N7PC-x#FfK7O3RY!ub7^mGIv_GGF)lDIFfC^?V>UT5IWjOb3Q2BrbYX5|
zWjY`-G%{soV>o6lHZnM4Ei^D=IW0J5G%zhOGcsm4GG=BqIAUW8RzqxWV{1Afdoem7
zGkppQ)w&D1%?Ho`&Jved>ZJex0000ewJ-euP(3~X%2)IfO5j%20Wi!kLk=ShfrBMO
zsK5y#f}}DW*5UdOMsFeTy^P3|6s07Jp0;HYDH#@Ar4LN3dp;J<%fJ{fJAIfOq;Vq;
zlu$~8$&^wO0Sy5v0jQa2IseU4m&20WnYZ6H=TW9bjCi?!Cdo3yNS0;5cPr{dld(*a
zC&zv#>66U0^u}`zz3HEvjPL&aP6+3t+CELw(oEB{&|{um5s-V&sV2?yr`(e{QFGb$
z{OoD-_I2XMI?Sf;X<FtwAtEboY@TJ8^@6G<%h^wu$=H$pn$#i|b?<uAA|`Kq*RT?6
zEtDXomH^+a=&fhk?j~>cWnA~~dqF$INY|*u0^qw9^)Up-O-{~gu?#mqdDf`J^4ZJF
z?Ypk=fPA;2^+FLhwq@GRez&4BsZkZ9sadUR#t@Z?sWJ+Libe+2YPDLZnjE&ooLLyA
zbp8EFhCEzp#nu{SMd$<&Dn6Dpkm7m*;8vlU=Zs`<Ncdi76L*e`{haFO?=cDFF_OLE
zBI=*J=30jRHj+ey#KKy>ThSD!e-8QCKR&WL5x!edBAIOWk9!se!gnir;&9K}JgDt%
zwphMfQJE%pZFlo1lR5OeBm6_XBUUD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01-25 11:12 [tarantool-patches] [PATCH v1 0/2] fix 2.1.1 migration Kirill Shcherbatov
2019-01-25 11:12 ` [tarantool-patches] [PATCH v1 1/2] box: fix upgrade script for _fk_constraint space Kirill Shcherbatov
2019-01-25 11:12 ` Kirill Shcherbatov [this message]
2019-01-25 11:25   ` [tarantool-patches] Re: [PATCH v1 2/2] box: fix Tarantool upgrade from 2.1.0 to 2.1.1 Kirill Shcherbatov

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=791d55891bd2534a5d4570ab2e71888efc189f3b.1548414536.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='Re: [tarantool-patches] [PATCH v1 2/2] box: fix Tarantool upgrade from 2.1.0 to 2.1.1' \
    /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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox