From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 93F7126190 for ; Wed, 30 Jan 2019 03:59:20 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zVtprZqf5jwT for ; Wed, 30 Jan 2019 03:59:20 -0500 (EST) Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id D756926192 for ; Wed, 30 Jan 2019 03:59:19 -0500 (EST) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v2 3/9] box: fix Tarantool upgrade from 2.1.0 to 2.1.1 Date: Wed, 30 Jan 2019 11:59:10 +0300 Message-Id: <1e4434445b60b5a5e0c3b289505595b0e00c8f8c.1548838034.git.kshcherbatov@tarantool.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org, korablev@tarantool.org Cc: Kirill Shcherbatov 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/bootstrap.snap | Bin 1911 -> 1914 bytes src/box/index_def.c | 1 + src/box/lua/upgrade.lua | 24 +++++++- src/box/opt_def.c | 3 + src/box/opt_def.h | 12 ++-- test/box-py/bootstrap.result | 2 +- test/sql/upgrade.result | 52 ++++++++++++++++++ test/sql/upgrade.test.lua | 17 ++++++ .../upgrade/2.1.0/00000000000000000003.snap | Bin 0 -> 2124 bytes 9 files changed, 105 insertions(+), 6 deletions(-) create mode 100644 test/sql/upgrade/2.1.0/00000000000000000003.snap diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index d6cc821fbf449852b62aace82a2c751e7f328365..662d6411544a3374ab97cf83dd8912ba7e05f6bd 100644 GIT binary patch delta 1180 delta 1177 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..cc172dc15 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -615,6 +615,27 @@ 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 + if opts['sql'] ~= nil then + opts['sql'] = nil + _index:replace(box.tuple.new({index.id, index.iid, index.name, + index.type, opts, index.parts})) + end + 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 +663,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/box-py/bootstrap.result b/test/box-py/bootstrap.result index 506aca3d6..2532b704a 100644 --- a/test/box-py/bootstrap.result +++ b/test/box-py/bootstrap.result @@ -5,7 +5,7 @@ box.space._schema:select{} --- - - ['cluster', ''] - ['max_id', 511] - - ['version', 2, 1, 0] + - ['version', 2, 1, 1] ... box.space._cluster:select{} --- diff --git a/test/sql/upgrade.result b/test/sql/upgrade.result index 79c7eb245..d3392e88b 100644 --- a/test/sql/upgrade.result +++ b/test/sql/upgrade.result @@ -158,3 +158,55 @@ test_run:cmd('cleanup server upgrade') --- - true ... +-- 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 .. '"') +--- +- true +... +test_run:cmd('start server upgrade210') +--- +- true +... +test_run:switch('upgrade210') +--- +- true +... +s = box.space._space.index['name']:get('T2') +--- +... +s +--- +- [512, 1, 'T2', 'memtx', 3, {'sql': 'CREATE TABLE t2(x INTEGER CONSTRAINT aaa CHECK + ( x<5 ), y REAL CHECK( y>x ), z INT primary key)', 'checks': [{'name': 'AAA', + 'expr': 'x<5'}, {'expr': 'y>x'}]}, [{'affinity': 68, 'type': 'scalar', 'nullable_action': 'none', + 'name': 'X', 'is_nullable': true}, {'affinity': 69, 'type': 'scalar', 'nullable_action': 'none', + 'name': 'Y', 'is_nullable': true}, {'affinity': 68, 'type': 'integer', 'nullable_action': 'abort', + 'name': 'Z', 'is_nullable': false}]] +... +i = box.space._index:select(s.id) +--- +... +i +--- +- - [512, 0, 'pk_T2_1', 'tree', {'unique': true}, [{'sort_order': 'asc', 'type': 'integer', + 'field': 2, 'nullable_action': 'abort', 'is_nullable': false}]] +... +i[1].opts.sql == nil +--- +- true +... +test_run:switch('default') +--- +- true +... +test_run:cmd('stop server upgrade210') +--- +- true +... +test_run:cmd('cleanup server upgrade210') +--- +- true +... 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 -- 2.19.2