From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Vladislav Shpilevoy Subject: [PATCH 6/8] box: introduce _promotion space Date: Wed, 8 Aug 2018 01:03:49 +0300 Message-Id: In-Reply-To: References: In-Reply-To: References: To: tarantool-patches@freelists.org Cc: vdavydov.dev@gmail.com List-ID: Promotion space keeps info about finished and going promotions. Needed for #3055 --- src/box/alter.cc | 11 +++++++++++ src/box/alter.h | 1 + src/box/bootstrap.snap | Bin 1540 -> 1635 bytes src/box/lua/space.cc | 2 ++ src/box/lua/upgrade.lua | 19 +++++++++++++++++++ src/box/schema.cc | 15 +++++++++++++++ src/box/schema_def.h | 14 ++++++++++++++ test/app-tap/tarantoolctl.test.lua | 4 ++-- test/box-py/bootstrap.result | 8 +++++++- test/box/access_misc.result | 4 ++++ test/box/access_sysview.result | 6 +++--- test/box/alter.result | 6 ++++-- test/wal_off/alter.result | 2 +- test/xlog/upgrade.result | 8 +++++++- 14 files changed, 90 insertions(+), 10 deletions(-) diff --git a/src/box/alter.cc b/src/box/alter.cc index d13ecb783..7a7325038 100644 --- a/src/box/alter.cc +++ b/src/box/alter.cc @@ -2924,6 +2924,13 @@ on_replace_dd_cluster(struct trigger *trigger, void *event) txn_on_commit(txn, on_commit); } +static void +on_replace_dd_promotion(struct trigger *trigger, void *event) +{ + (void) trigger; + (void) event; +} + /* }}} cluster configuration */ /* {{{ sequence */ @@ -3240,6 +3247,10 @@ struct trigger alter_space_on_replace_index = { RLIST_LINK_INITIALIZER, on_replace_dd_index, NULL, NULL }; +struct trigger alter_space_on_replace_promotion = { + RLIST_LINK_INITIALIZER, on_replace_dd_promotion, NULL, NULL +}; + struct trigger on_replace_truncate = { RLIST_LINK_INITIALIZER, on_replace_dd_truncate, NULL, NULL }; diff --git a/src/box/alter.h b/src/box/alter.h index fb5f65a68..c62ca3c95 100644 --- a/src/box/alter.h +++ b/src/box/alter.h @@ -34,6 +34,7 @@ extern struct trigger alter_space_on_replace_space; extern struct trigger alter_space_on_replace_index; +extern struct trigger alter_space_on_replace_promotion; extern struct trigger on_replace_truncate; extern struct trigger on_replace_schema; extern struct trigger on_replace_user; diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index b610828c9c9ae9a22acdd8c150c16c6838b7a273..ece20feaa47441dcf4b56fe90d91dfcf29e30341 100644 GIT binary patch delta 1630 zcmV-k2BGGBGhNXE!rrFfcG;Wn~IUZgX^DZewLSAU82MF)=qVI4xmh zH#IFZFg9c@I5;;pEjeLjHe)qrIb$<4GYVEiY;R+0Iv{&7Iv_B83JTS_3%bn(xx;eJWSo1A= z@x^05KtZMtZ-0HOysc+>yPHuJibO;!1+aCFFMV5Bi!&Bq<=1=@3Bg`xQ~}sJ#~?;- zoM=gr`hh`Y~OZiPBJpj zolrA1G^h7e-iiC|qHH!93{v#--9c|gYASS2C@Mc8dVi+Kn50C>c>b&f3FFHHaLT}d~UATM{7tCLZf1-8zy z^WQ;U?y9b&FA9XT1p1049uo5TFXK)|T@Vy;bw<>5z}7i-@VZKp->*wTDHyPIj`=;%kl&y2Lp*H8 zTwq9-7t;ol22%#szAOqDS}wF$Xwg_)SSqlXYAsQqBv2DtYAH>iRD!K@Tw$3ckdyB~ zaPBf8|C-093PlpqTuM$JY&55uo9~{u?FNP7P&XK)P*TI$Q9%dIfn#x0og1kglns~~8V%D7$|7ThB9%1; z%^~Jq?kb{6VHyV`DJcmGePQbyOY^sW7k|#3$c3$Q1W+f1X`GIJvG0;rXyIW{e0@YM ziw8p;^DxNMMH#IyZCjCX>$@eTDr}wOh?R;ZzBZWSLWS3X29NJ~#o(LhqUT*K7ZcQF z?UQ&}UXc*}yT|zczAEX2Xn0i?;M z#j;oy%VGqdoxqvgQD!$QywxRHVY@5)uFS!t7~+P^g(3NjfsstSGrom30n03ligsi% zyvsgq=nPHcsW{;Mt@5X`k8WZW$bY8?cn6~;-<_{-&*BadbQ=>!W-r}AL02DBR1fq3fHjabdGh{}oKXzmoUu+xJ$^E0Ui>~8* zjFJltmP^z|%u8da4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TX-lUJ$ zzkkQk8h`!+Ak42Gb5O~I9X_GL4xhR(RGq@`<8YEmeGLBa%Ed{YaV#4wH7X6(wXrob zRx(mCOfa|?Bo}qm;#z9jPz5?Ii>k-mKV61Bw$iw6MNm)>lUj2vHAVFK{#e#!kBV!l ziDGG`ab1f2WXaFUg5t{}`TM8d6EBXt_J3uuRg$)9X&lOg&M*+4wU)S+njl=^il77Rj$ynhqj zxeG%W18Ui|uoin^FOJH&6BE>1-;h#Us!zr2@yPWOP}$xk=>TS*Ej6Q8ZgBx&}sXh}Wym z;Yvs=Xm6s&oTIkS5VXc28)t^2+kc4qR4r1#;*gdpU~^0s$pG8pm?G)gVGer7p5*j@ zrQSOro_cGm&fR}<@b8h^=iXW!%4reE=RqJFWsqt`1BcS0HC@As3ba#z^Ko9Pi8avYk$Oa!!S#& zSx3_!A8xyrpfT#3Y0zk_Hi}Y>p%$pI61F+5M3N&%2xKJAC;$CDD}<6?=$#5uoTZ5Z zCNj}EgB|fKv=$L@ag>MEJ_76DnN*W1Z`O`MZ9ptwx|K1yxMV1V1(Ltx%(4y7obk4E zW?=^8GIQ=kv4A0`wS7N1*>`Z!opukPx!_g@c{8|RJi<`!QS!z#<&+X#nnV8V6uo^% zFL^|hfwSZ-+|LAZ&d5i?Zt>-$tMH_1UnT!Yb{@SussOv@WfJ50JyfLCQd9Bw_N-dh k2=V>Mm|$S01}gnuSl5OyKJnJxL~`9Mur5?WUI5(f|Me diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 580e0ea2c..c1a1efb7d 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -554,6 +554,8 @@ box_lua_space_init(struct lua_State *L) lua_setfield(L, -2, "VSEQUENCE_ID"); lua_pushnumber(L, BOX_SPACE_SEQUENCE_ID); lua_setfield(L, -2, "SPACE_SEQUENCE_ID"); + lua_pushnumber(L, BOX_PROMOTION_ID); + lua_setfield(L, -2, "PROMOTION_ID"); lua_pushnumber(L, BOX_SYSTEM_ID_MIN); lua_setfield(L, -2, "SYSTEM_ID_MIN"); lua_pushnumber(L, BOX_SYSTEM_ID_MAX); diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 0293f6ef8..39ab0df7d 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -964,6 +964,24 @@ local function upgrade_to_1_10_0() create_vsequence_space() end +local function upgrade_to_1_10_2() + log.info('create space _promotion') + local format = { + {name = 'id', type = 'unsigned'}, + {name = 'round_uuid', type = 'string'}, + {name = 'step', type = 'unsigned'}, + {name = 'source_uuid', type = 'string'}, + {name = 'ts', type = 'number'}, + {name = 'type', type = 'string'}, + {name = 'value', type = 'map', is_nullable = true} + } + box.space._space:insert({box.space._promotion.id, ADMIN, '_promotion', + 'memtx', 0, setmap({}), format}) + log.info('create index primary on _promotion') + box.space._index:insert({box.space._promotion.id, 0, 'primary', 'tree', + {unique = true}, {{0, 'unsigned'}, {1, 'string'}, + {2, 'unsigned'}, {3, 'string'}}}) +end local function get_version() local version = box.space._schema:get{'version'} @@ -991,6 +1009,7 @@ local function upgrade(options) {version = mkversion(1, 7, 6), func = upgrade_to_1_7_6, auto = false}, {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}, } for _, handler in ipairs(handlers) do diff --git a/src/box/schema.cc b/src/box/schema.cc index 433f52c08..adacb2569 100644 --- a/src/box/schema.cc +++ b/src/box/schema.cc @@ -338,8 +338,23 @@ schema_init() */ sc_space_new(BOX_CLUSTER_ID, "_cluster", key_def, &on_replace_cluster, NULL); + key_def_delete(key_def); + key_def = key_def_new(4); + if (key_def == NULL) + diag_raise(); + key_def_set_part(key_def, 0, 0, FIELD_TYPE_UNSIGNED, false, NULL, + COLL_NONE); + key_def_set_part(key_def, 1, 1, FIELD_TYPE_STRING, false, NULL, + COLL_NONE); + key_def_set_part(key_def, 2, 2, FIELD_TYPE_UNSIGNED, false, NULL, + COLL_NONE); + key_def_set_part(key_def, 3, 3, FIELD_TYPE_STRING, false, NULL, + COLL_NONE); + sc_space_new(BOX_PROMOTION_ID, "_promotion", key_def, + &alter_space_on_replace_promotion, NULL); key_def_delete(key_def); + key_def = key_def_new(2); /* part count */ if (key_def == NULL) diag_raise(); diff --git a/src/box/schema_def.h b/src/box/schema_def.h index 2edb8d37f..079afd45a 100644 --- a/src/box/schema_def.h +++ b/src/box/schema_def.h @@ -102,6 +102,8 @@ enum { BOX_TRUNCATE_ID = 330, /** Space id of _space_sequence. */ BOX_SPACE_SEQUENCE_ID = 340, + /** Space id of _promotion. */ + BOX_PROMOTION_ID = 348, /** End of the reserved range of system spaces. */ BOX_SYSTEM_ID_MAX = 511, BOX_ID_NIL = 2147483647 @@ -212,6 +214,18 @@ enum { BOX_SPACE_SEQUENCE_FIELD_IS_GENERATED = 2, }; +/** _promotion fields. */ +enum { + BOX_PROMOTION_FIELD_ID = 0, + BOX_PROMOTION_FIELD_ROUND_UUID = 1, + BOX_PROMOTION_FIELD_PHASE = 2, + BOX_PROMOTION_FIELD_SOURCE_UUID = 3, + BOX_PROMOTION_FIELD_STEP = 4, + BOX_PROMOTION_FIELD_TS = 5, + BOX_PROMOTION_FIELD_TYPE = 6, + BOX_PROMOTION_FIELD_VALUE = 7, +}; + /* * Different objects which can be subject to access * control. diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index 6946c8312..599519543 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -338,8 +338,8 @@ do check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1", "\n", 3) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 1 --replica 2", "\n", 3) check_ctlcat_xlog(test_i, dir, "--from=3 --to=6 --format=json --show-system --replica 2", "\n", 0) - check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 18) - check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 43) + check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 19) + check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 44) end) end) diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result index 16c2027cf..a78c23945 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', 1, 10, 0] + - ['version', 1, 10, 2] ... box.space._cluster:select{} --- @@ -68,6 +68,10 @@ box.space._space:select{} 'type': 'unsigned'}]] - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'sequence_id', 'type': 'unsigned'}, {'name': 'is_generated', 'type': 'boolean'}]] + - [348, 1, '_promotion', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, { + 'name': 'round_uuid', 'type': 'string'}, {'name': 'step', 'type': 'unsigned'}, + {'name': 'source_uuid', 'type': 'string'}, {'name': 'ts', 'type': 'number'}, + {'name': 'type', 'type': 'string'}, {'type': 'map', 'name': 'value', 'is_nullable': true}]] ... box.space._index:select{} --- @@ -116,6 +120,8 @@ box.space._index:select{} - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]] + - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 'string'], + [2, 'unsigned'], [3, 'string']]] ... box.space._user:select{} --- diff --git a/test/box/access_misc.result b/test/box/access_misc.result index 2d87fa2d5..40b8a8118 100644 --- a/test/box/access_misc.result +++ b/test/box/access_misc.result @@ -807,6 +807,10 @@ box.space._space:select() 'type': 'unsigned'}]] - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'sequence_id', 'type': 'unsigned'}, {'name': 'is_generated', 'type': 'boolean'}]] + - [348, 1, '_promotion', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, { + 'name': 'round_uuid', 'type': 'string'}, {'name': 'step', 'type': 'unsigned'}, + {'name': 'source_uuid', 'type': 'string'}, {'name': 'ts', 'type': 'number'}, + {'name': 'type', 'type': 'string'}, {'type': 'map', 'name': 'value', 'is_nullable': true}]] ... box.space._func:select() --- diff --git a/test/box/access_sysview.result b/test/box/access_sysview.result index 20efd2bbc..8a0079407 100644 --- a/test/box/access_sysview.result +++ b/test/box/access_sysview.result @@ -230,11 +230,11 @@ box.session.su('guest') ... #box.space._vspace:select{} --- -- 19 +- 20 ... #box.space._vindex:select{} --- -- 44 +- 45 ... #box.space._vuser:select{} --- @@ -262,7 +262,7 @@ box.session.su('guest') ... #box.space._vindex:select{} --- -- 44 +- 45 ... #box.space._vuser:select{} --- diff --git a/test/box/alter.result b/test/box/alter.result index eb7014d8b..72f451938 100644 --- a/test/box/alter.result +++ b/test/box/alter.result @@ -107,7 +107,7 @@ space = box.space[t[1]] ... space.id --- -- 341 +- 349 ... space.field_count --- @@ -152,7 +152,7 @@ space_deleted ... space:replace{0} --- -- error: Space '341' does not exist +- error: Space '349' does not exist ... _index:insert{_space.id, 0, 'primary', 'tree', 1, 1, 0, 'unsigned'} --- @@ -226,6 +226,8 @@ _index:select{} - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]] + - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 'string'], + [2, 'unsigned'], [3, 'string']]] ... -- modify indexes of a system space _index:delete{_index.id, 0} diff --git a/test/wal_off/alter.result b/test/wal_off/alter.result index afac1e55d..76fae0511 100644 --- a/test/wal_off/alter.result +++ b/test/wal_off/alter.result @@ -28,7 +28,7 @@ end; ... #spaces; --- -- 65515 +- 65514 ... -- cleanup for k, v in pairs(spaces) do diff --git a/test/xlog/upgrade.result b/test/xlog/upgrade.result index f02996bba..f9409c7dc 100644 --- a/test/xlog/upgrade.result +++ b/test/xlog/upgrade.result @@ -36,7 +36,7 @@ box.space._schema:select() --- - - ['cluster', ''] - ['max_id', 513] - - ['version', 1, 10, 0] + - ['version', 1, 10, 2] ... box.space._space:select() --- @@ -95,6 +95,10 @@ box.space._space:select() 'type': 'unsigned'}]] - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'sequence_id', 'type': 'unsigned'}, {'name': 'is_generated', 'type': 'boolean'}]] + - [348, 1, '_promotion', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, { + 'name': 'round_uuid', 'type': 'string'}, {'name': 'step', 'type': 'unsigned'}, + {'name': 'source_uuid', 'type': 'string'}, {'name': 'ts', 'type': 'number'}, + {'name': 'type', 'type': 'string'}, {'type': 'map', 'name': 'value', 'is_nullable': true}]] - [512, 1, 'distro', 'memtx', 0, {}, [{'name': 'os', 'type': 'str'}, {'name': 'dist', 'type': 'str'}, {'name': 'version', 'type': 'num'}, {'name': 'time', 'type': 'num'}]] - [513, 1, 'temporary', 'memtx', 0, {'temporary': true}, []] @@ -146,6 +150,8 @@ box.space._index:select() - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]] + - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 'string'], + [2, 'unsigned'], [3, 'string']]] - [512, 0, 'primary', 'hash', {'unique': true}, [[0, 'string'], [1, 'string'], [ 2, 'unsigned']]] - [512, 1, 'codename', 'hash', {'unique': true}, [[1, 'string']]] -- 2.15.2 (Apple Git-101.1)