From: Roman Khabibov <roman.habibov@tarantool.org> To: tarantool-patches@freelists.org Cc: Vladimir Davydov <vdavydov.dev@gmail.com> Subject: Re: [tarantool-patches] Re: [PATCH 1/2] schema: add "_vcollation" sysview Date: Thu, 6 Jun 2019 18:18:10 +0300 [thread overview] Message-ID: <C337C03E-505A-49C7-9C0C-4B5067F23382@tarantool.org> (raw) In-Reply-To: <20190605175645.wm3gyqtyb5i22oq4@esperanza> > On Jun 5, 2019, at 8:56 PM, Vladimir Davydov <vdavydov.dev@gmail.com> wrote: > > On Wed, Jun 05, 2019 at 08:08:46PM +0300, Roman Khabibov wrote: >>>> +local function upgrade_to_2_1_4() >>>> + local _collation = box.space._collation >>>> + local _index = box.space._index >>>> + >>>> + -- System space format usually is in order "id, owner, name...". >>>> + -- The fields "name", "owner" are swapped in "_collation" format, >>>> + -- due to the field "owner" was added after the "_collation" creation. >>>> + box.space._index:delete{276, 1} >>>> + log.info("update index name on _collation") >>>> + box.space._index:insert{_collation.id, 2, 'name', 'tree', {unique = true}, >>>> + {{1, 'string'}}} >>>> + log.info("create index owner on _collation") >>>> + box.space._index:insert{_collation.id, 1, 'owner', 'tree', {unique = false}, >>>> + {{2, 'unsigned'}}} >>> >>> I don't understand this part. Why do you need to create 'owner' index? >>> Why do you need to update 'name' index? >> create_sysview() can’t work otherwise. > > I fail to see why is that. Could you please elaborate You were right. I actually don’t need it. Removed. >> >> + >> +-- Fit _collation indexes to be suitable forcreate_sysview(). >> +local function upgrade_collation_to_2_2_2() >> + local _collation = box.space._collation >> + local _index = box.space._index >> >>> >>>> + create_vcollation_space() >>>> +end >>>> + >>>> local function get_version() >>>> local version = box.space._schema:get{'version'} >>>> if version == nil then >>>> @@ -768,6 +792,7 @@ local function upgrade(options) >>>> {version = mkversion(2, 1, 1), func = upgrade_to_2_1_1, auto = true}, >>>> {version = mkversion(2, 1, 2), func = upgrade_to_2_1_2, auto = true}, >>>> {version = mkversion(2, 1, 3), func = upgrade_to_2_1_3, auto = true}, >>>> + {version = mkversion(2, 1, 4), func = upgrade_to_2_1_4, auto = true} >>> >>> Should be in upgrade_to_2_2_1. >> To 2.2.2 maybe? > > No. The last release was 2.2.0 so the next one will be 2.2.1. Done. +local function create_vcollation_space() + local _collation = box.space._collation + local format = _collation:format() + create_sysview(box.schema.COLLATION_ID, box.schema.VCOLLATION_ID) + box.space[box.schema.VCOLLATION_ID]:format(format) +end + -- Add sequence field to _space_sequence table local function upgrade_sequence_to_2_2_1() log.info("add sequence field to space _space_sequence") @@ -776,6 +783,7 @@ end local function upgrade_to_2_2_1() upgrade_sequence_to_2_2_1() + create_vcollation_space() end commit f13d3f0ce8a2d7af8a11ebc1003d1145652a46a3 Author: Roman Khabibov <roman.habibov@tarantool.org> Date: Thu May 16 02:06:39 2019 +0300 schema: add "_vcollation" sysview Add "_vcollation" sysview to read it from net.box. This sysview is always readable, except when a user doesn't have "public" role. Needed for #3941 @TarantoolBot document Title: box.space._vcollation _vcollation is a system space that represents a virtual view. The structure of its tuples is identical to that of _collation. Tuples of this sysview is always readable, except when the user doesn't have "public" role. diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap index bb8fbeba1..eb9297d7c 100644 Binary files a/src/box/bootstrap.snap and b/src/box/bootstrap.snap differ diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc index 87adaeb16..5d837eda6 100644 --- a/src/box/lua/space.cc +++ b/src/box/lua/space.cc @@ -540,6 +540,8 @@ box_lua_space_init(struct lua_State *L) lua_setfield(L, -2, "FUNC_ID"); lua_pushnumber(L, BOX_COLLATION_ID); lua_setfield(L, -2, "COLLATION_ID"); + lua_pushnumber(L, BOX_VCOLLATION_ID); + lua_setfield(L, -2, "VCOLLATION_ID"); lua_pushnumber(L, BOX_VFUNC_ID); lua_setfield(L, -2, "VFUNC_ID"); lua_pushnumber(L, BOX_PRIV_ID); diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua index 070662698..fe62fb0a9 100644 --- a/src/box/lua/upgrade.lua +++ b/src/box/lua/upgrade.lua @@ -749,6 +749,13 @@ end -- Tarantool 2.2.1 -------------------------------------------------------------------------------- +local function create_vcollation_space() + local _collation = box.space._collation + local format = _collation:format() + create_sysview(box.schema.COLLATION_ID, box.schema.VCOLLATION_ID) + box.space[box.schema.VCOLLATION_ID]:format(format) +end + -- Add sequence field to _space_sequence table local function upgrade_sequence_to_2_2_1() log.info("add sequence field to space _space_sequence") @@ -776,6 +783,7 @@ end local function upgrade_to_2_2_1() upgrade_sequence_to_2_2_1() + create_vcollation_space() end -------------------------------------------------------------------------------- @@ -811,7 +819,7 @@ local function upgrade(options) {version = mkversion(2, 1, 1), func = upgrade_to_2_1_1, auto = true}, {version = mkversion(2, 1, 2), func = upgrade_to_2_1_2, auto = true}, {version = mkversion(2, 1, 3), func = upgrade_to_2_1_3, auto = true}, - {version = mkversion(2, 2, 1), func = upgrade_to_2_2_1, auto = true}, + {version = mkversion(2, 2, 1), func = upgrade_to_2_2_1, auto = true} } for _, handler in ipairs(handlers) do diff --git a/src/box/schema_def.h b/src/box/schema_def.h index b817b49f6..e0febb640 100644 --- a/src/box/schema_def.h +++ b/src/box/schema_def.h @@ -72,6 +72,8 @@ enum { BOX_SCHEMA_ID = 272, /** Space id of _collation. */ BOX_COLLATION_ID = 276, + /** Space id of _vcollation. */ + BOX_VCOLLATION_ID = 277, /** Space id of _space. */ BOX_SPACE_ID = 280, /** Space id of _vspace view. */ diff --git a/src/box/sysview.c b/src/box/sysview.c index 96c5e78ca..46cf1e13f 100644 --- a/src/box/sysview.c +++ b/src/box/sysview.c @@ -402,6 +402,14 @@ vsequence_filter(struct space *source, struct tuple *tuple) ((PRIV_WRDA | PRIV_X) & effective); } +static bool +vcollation_filter(struct space *source, struct tuple *tuple) +{ + (void) source; + (void) tuple; + return true; +} + static struct index * sysview_space_create_index(struct space *space, struct index_def *def) { @@ -448,6 +456,11 @@ sysview_space_create_index(struct space *space, struct index_def *def) source_index_id = def->iid; filter = vsequence_filter; break; + case BOX_VCOLLATION_ID: + source_space_id = BOX_COLLATION_ID; + source_index_id = def->iid; + filter = vcollation_filter; + break; default: diag_set(ClientError, ER_MODIFY_INDEX, def->name, space_name(space), diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua index c1e1490ca..7a72acda2 100755 --- a/test/app-tap/tarantoolctl.test.lua +++ b/test/app-tap/tarantoolctl.test.lua @@ -405,8 +405,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", 21) - check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 47) + check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 22) + check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 49) end) end) diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result index 0684914c0..d2cca9017 100644 --- a/test/box-py/bootstrap.result +++ b/test/box-py/bootstrap.result @@ -21,6 +21,10 @@ box.space._space:select{} 'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'}, {'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, { 'name': 'opts', 'type': 'map'}]] + - [277, 1, '_vcollation', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'}, + {'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'}, { + 'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, { + 'name': 'opts', 'type': 'map'}]] - [280, 1, '_space', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner', 'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'engine', 'type': 'string'}, {'name': 'field_count', 'type': 'unsigned'}, {'name': 'flags', @@ -85,6 +89,8 @@ box.space._index:select{} - - [272, 0, 'primary', 'tree', {'unique': true}, [[0, 'string']]] - [276, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [276, 1, 'name', 'tree', {'unique': true}, [[1, 'string']]] + - [277, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] + - [277, 1, 'name', 'tree', {'unique': true}, [[1, 'string']]] - [280, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [280, 1, 'owner', 'tree', {'unique': false}, [[1, 'unsigned']]] - [280, 2, 'name', 'tree', {'unique': true}, [[2, 'string']]] @@ -151,6 +157,7 @@ box.space._priv:select{} - [1, 1, 'universe', 0, 4294967295] - [1, 2, 'function', 1, 4] - [1, 2, 'space', 276, 2] + - [1, 2, 'space', 277, 1] - [1, 2, 'space', 281, 1] - [1, 2, 'space', 286, 1] - [1, 2, 'space', 289, 1] diff --git a/test/box/access_misc.result b/test/box/access_misc.result index 24bdd9d63..d5bb8b208 100644 --- a/test/box/access_misc.result +++ b/test/box/access_misc.result @@ -761,6 +761,10 @@ box.space._space:select() 'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'}, {'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, { 'name': 'opts', 'type': 'map'}]] + - [277, 1, '_vcollation', 'sysview', 0, {}, [{'name': 'id', 'type': 'unsigned'}, + {'name': 'name', 'type': 'string'}, {'name': 'owner', 'type': 'unsigned'}, { + 'name': 'type', 'type': 'string'}, {'name': 'locale', 'type': 'string'}, { + 'name': 'opts', 'type': 'map'}]] - [280, 1, '_space', 'memtx', 0, {}, [{'name': 'id', 'type': 'unsigned'}, {'name': 'owner', 'type': 'unsigned'}, {'name': 'name', 'type': 'string'}, {'name': 'engine', 'type': 'string'}, {'name': 'field_count', 'type': 'unsigned'}, {'name': 'flags', diff --git a/test/box/access_sysview.result b/test/box/access_sysview.result index c6a2b22ed..4d1f0c779 100644 --- a/test/box/access_sysview.result +++ b/test/box/access_sysview.result @@ -74,6 +74,10 @@ session.su('guest') --- - true ... +#box.space._vspace.index[2]:select('_vcollation') ~= 0 +--- +- true +... #box.space._vindex:select(box.space._vspace.id) > 0 --- - true @@ -94,6 +98,10 @@ session.su('guest') --- - true ... +#box.space._vindex:select(box.space._vcollation.id) > 0 +--- +- true +... box.session.su('admin') --- ... @@ -127,6 +135,10 @@ box.session.su('guest') --- - error: Read access to space '_vsequence' is denied for user 'guest' ... +#box.space._vcollation:select{} +--- +- error: Read access to space '_vcollation' is denied for user 'guest' +... box.session.su('admin') --- ... @@ -138,11 +150,15 @@ box.session.su('guest') ... #box.space._vspace:select{} --- -- 8 +- 9 ... #box.space._vindex:select{} --- -- 20 +- 22 +... +#box.space._vcollation:select{} +--- +- 277 ... box.session.su('admin') --- @@ -230,11 +246,11 @@ box.session.su('guest') ... #box.space._vspace:select{} --- -- 22 +- 23 ... #box.space._vindex:select{} --- -- 48 +- 50 ... #box.space._vuser:select{} --- @@ -242,12 +258,16 @@ box.session.su('guest') ... #box.space._vpriv:select{} --- -- 15 +- 16 ... #box.space._vfunc:select{} --- - 1 ... +#box.space._vcollation:select{} +--- +- 277 +... box.session.su('admin') --- ... @@ -262,7 +282,7 @@ box.session.su('guest') ... #box.space._vindex:select{} --- -- 48 +- 50 ... #box.space._vuser:select{} --- @@ -270,7 +290,7 @@ box.session.su('guest') ... #box.space._vpriv:select{} --- -- 15 +- 16 ... #box.space._vfunc:select{} --- @@ -280,6 +300,10 @@ box.session.su('guest') --- - 0 ... +#box.space._vcollation:select{} +--- +- 277 +... box.session.su('admin') --- ... @@ -631,6 +655,60 @@ seq:drop() --- ... -- +-- _vcollation +-- +box.session.su('admin') +--- +... +box.internal.collation.create('test', 'ICU', 'ru-RU') +--- +... +-- Only admin can create collation. +coll_cnt = #box.space._collation:select{} +--- +... +box.schema.user.grant("guest", "read, write, alter, execute", "space", "_collation") +--- +... +box.session.su("guest") +--- +... +box.internal.collation.create('guest0', 'ICU', 'ru-RU') +--- +- error: Create access to collation 'guest0' is denied for user 'guest' +... +box.space._vcollation:select{0} +--- +- - [0, 'none', 1, 'BINARY', '', {}] +... +#box.space._vcollation:select{} == coll_cnt +--- +- true +... +box.session.su('admin') +--- +... +-- _vcollation is readable anyway. +box.schema.user.revoke("guest", "read", "space", "_collation") +--- +... +box.session.su("guest") +--- +... +#box.space._vcollation:select{} +--- +- 278 +... +session.su('admin') +--- +... +box.internal.collation.drop('test') +--- +... +box.internal.collation.drop('guest0') +--- +... +-- -- view:alter() tests -- box.space._vspace.index[1]:alter({parts = { 2, 'string' }}) diff --git a/test/box/access_sysview.test.lua b/test/box/access_sysview.test.lua index c62458407..031df28aa 100644 --- a/test/box/access_sysview.test.lua +++ b/test/box/access_sysview.test.lua @@ -31,12 +31,14 @@ session.su('guest') #box.space._vspace.index[2]:select('_vuser') ~= 0 #box.space._vspace.index[2]:select('_vfunc') ~= 0 #box.space._vspace.index[2]:select('_vpriv') ~= 0 +#box.space._vspace.index[2]:select('_vcollation') ~= 0 #box.space._vindex:select(box.space._vspace.id) > 0 #box.space._vindex:select(box.space._vindex.id) > 0 #box.space._vindex:select(box.space._vuser.id) > 0 #box.space._vindex:select(box.space._vfunc.id) > 0 #box.space._vindex:select(box.space._vpriv.id) > 0 +#box.space._vindex:select(box.space._vcollation.id) > 0 box.session.su('admin') box.schema.user.revoke('guest', 'public') @@ -48,6 +50,7 @@ box.session.su('guest') #box.space._vpriv:select{} #box.space._vfunc:select{} #box.space._vsequence:select{} +#box.space._vcollation:select{} box.session.su('admin') box.schema.user.grant('guest', 'public') @@ -55,6 +58,7 @@ box.session.su('guest') #box.space._vspace:select{} #box.space._vindex:select{} +#box.space._vcollation:select{} box.session.su('admin') s = box.schema.space.create('test') @@ -96,6 +100,7 @@ box.session.su('guest') #box.space._vuser:select{} #box.space._vpriv:select{} #box.space._vfunc:select{} +#box.space._vcollation:select{} box.session.su('admin') box.schema.user.revoke('guest', 'read', 'universe') @@ -107,6 +112,7 @@ box.session.su('guest') #box.space._vpriv:select{} #box.space._vfunc:select{} #box.space._vsequence:select{} +#box.space._vcollation:select{} box.session.su('admin') box.schema.user.revoke('guest', 'write', 'universe') @@ -264,6 +270,30 @@ box.session.su("guest") session.su('admin') seq:drop() +-- +-- _vcollation +-- + +box.session.su('admin') +box.internal.collation.create('test', 'ICU', 'ru-RU') + +-- Only admin can create collation. +coll_cnt = #box.space._collation:select{} +box.schema.user.grant("guest", "read, write, alter, execute", "space", "_collation") +box.session.su("guest") +box.internal.collation.create('guest0', 'ICU', 'ru-RU') +box.space._vcollation:select{0} +#box.space._vcollation:select{} == coll_cnt +box.session.su('admin') + +-- _vcollation is readable anyway. +box.schema.user.revoke("guest", "read", "space", "_collation") +box.session.su("guest") +#box.space._vcollation:select{} +session.su('admin') +box.internal.collation.drop('test') +box.internal.collation.drop('guest0') + -- -- view:alter() tests -- diff --git a/test/box/alter.result b/test/box/alter.result index e83c0b7ef..3e9c5e180 100644 --- a/test/box/alter.result +++ b/test/box/alter.result @@ -169,6 +169,8 @@ _index:select{} - - [272, 0, 'primary', 'tree', {'unique': true}, [[0, 'string']]] - [276, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [276, 1, 'name', 'tree', {'unique': true}, [[1, 'string']]] + - [277, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] + - [277, 1, 'name', 'tree', {'unique': true}, [[1, 'string']]] - [280, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]] - [280, 1, 'owner', 'tree', {'unique': false}, [[1, 'unsigned']]] - [280, 2, 'name', 'tree', {'unique': true}, [[2, 'string']]] diff --git a/test/wal_off/alter.result b/test/wal_off/alter.result index ee280fcbb..8040efa1a 100644 --- a/test/wal_off/alter.result +++ b/test/wal_off/alter.result @@ -28,7 +28,7 @@ end; ... #spaces; --- -- 65505 +- 65504 ... -- cleanup for k, v in pairs(spaces) do
next prev parent reply other threads:[~2019-06-06 15:18 UTC|newest] Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-05-30 12:36 [tarantool-patches] [PATCH 0/2] Add _vcollation and fetch in net.box Roman Khabibov 2019-05-30 12:36 ` [tarantool-patches] [PATCH 1/2] schema: add "_vcollation" sysview Roman Khabibov 2019-06-04 16:31 ` Vladimir Davydov 2019-06-05 17:08 ` [tarantool-patches] " Roman Khabibov 2019-06-05 17:56 ` Vladimir Davydov 2019-06-06 15:18 ` Roman Khabibov [this message] 2019-05-30 12:36 ` [tarantool-patches] [PATCH 2/2] net.box: fetch '_vcollation' sysview into the module Roman Khabibov 2019-06-04 16:36 ` Vladimir Davydov 2019-06-05 17:08 ` [tarantool-patches] " Roman Khabibov 2019-06-05 17:28 ` Vladimir Davydov 2019-06-06 15:22 ` Roman Khabibov 2019-06-06 16:00 ` Roman Khabibov 2019-06-06 17:00 ` Vladimir Davydov 2019-06-03 18:45 ` [tarantool-patches] Re: [PATCH 0/2] Add _vcollation and fetch in net.box Vladislav Shpilevoy 2019-06-04 15:54 ` [tarantool-patches] " Vladimir Davydov -- strict thread matches above, loose matches on Subject: below -- 2019-05-16 11:24 [tarantool-patches] [PATCH 0/2] Add "_vcollation" sysview and fetch it " Roman Khabibov 2019-05-16 11:24 ` [tarantool-patches] [PATCH 1/2] schema: add "_vcollation" sysview Roman Khabibov 2019-05-16 12:43 ` [tarantool-patches] " Konstantin Osipov 2019-05-28 15:50 ` Roman Khabibov 2019-05-30 11:57 ` Konstantin Osipov
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=C337C03E-505A-49C7-9C0C-4B5067F23382@tarantool.org \ --to=roman.habibov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=vdavydov.dev@gmail.com \ --subject='Re: [tarantool-patches] Re: [PATCH 1/2] schema: add "_vcollation" sysview' \ /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