Skip to content

Commit

Permalink
schema: add "_vcollation" sysview
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
romanhabibov committed Jun 5, 2019
1 parent f720f81 commit e67cd25
Show file tree
Hide file tree
Showing 12 changed files with 190 additions and 13 deletions.
Binary file modified src/box/bootstrap.snap
Binary file not shown.
2 changes: 2 additions & 0 deletions src/box/lua/space.cc
Expand Up @@ -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);
Expand Down
35 changes: 35 additions & 0 deletions src/box/lua/upgrade.lua
Expand Up @@ -778,6 +778,40 @@ local function upgrade_to_2_2_1()
upgrade_sequence_to_2_2_1()
end

--------------------------------------------------------------------------------
-- Tarantool 2.2.2
--------------------------------------------------------------------------------

-- 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

-- 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'}}}
end

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

local function upgrade_to_2_2_2()
upgrade_collation_to_2_2_2()
create_vcollation_space()
end

--------------------------------------------------------------------------------

local function get_version()
Expand Down Expand Up @@ -812,6 +846,7 @@ local function upgrade(options)
{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, 2), func = upgrade_to_2_2_2, auto = true}
}

for _, handler in ipairs(handlers) do
Expand Down
2 changes: 2 additions & 0 deletions src/box/schema_def.h
Expand Up @@ -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. */
Expand Down
13 changes: 13 additions & 0 deletions src/box/sysview.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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),
Expand Down
4 changes: 2 additions & 2 deletions test/app-tap/tarantoolctl.test.lua
Expand Up @@ -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", 51)
end)
end)

Expand Down
13 changes: 11 additions & 2 deletions test/box-py/bootstrap.result
Expand Up @@ -4,7 +4,7 @@ box.internal.bootstrap()
box.space._schema:select{}
---
- - ['max_id', 511]
- ['version', 2, 2, 1]
- ['version', 2, 2, 2]
...
box.space._cluster:select{}
---
Expand All @@ -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',
Expand Down Expand Up @@ -84,7 +88,11 @@ 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']]]
- [276, 1, 'owner', 'tree', {'unique': false}, [[2, 'unsigned']]]
- [276, 2, 'name', 'tree', {'unique': true}, [[1, 'string']]]
- [277, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
- [277, 1, 'owner', 'tree', {'unique': false}, [[2, 'unsigned']]]
- [277, 2, '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']]]
Expand Down Expand Up @@ -151,6 +159,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]
Expand Down
4 changes: 4 additions & 0 deletions test/box/access_misc.result
Expand Up @@ -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',
Expand Down
92 changes: 85 additions & 7 deletions test/box/access_sysview.result
Expand Up @@ -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
Expand All @@ -94,6 +98,10 @@ session.su('guest')
---
- true
...
#box.space._vindex:select(box.space._vcollation.id) > 0
---
- true
...
box.session.su('admin')
---
...
Expand Down Expand Up @@ -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')
---
...
Expand All @@ -138,11 +150,15 @@ box.session.su('guest')
...
#box.space._vspace:select{}
---
- 8
- 9
...
#box.space._vindex:select{}
---
- 20
- 24
...
#box.space._vcollation:select{}
---
- 277
...
box.session.su('admin')
---
Expand Down Expand Up @@ -230,24 +246,28 @@ box.session.su('guest')
...
#box.space._vspace:select{}
---
- 22
- 23
...
#box.space._vindex:select{}
---
- 48
- 52
...
#box.space._vuser:select{}
---
- 5
...
#box.space._vpriv:select{}
---
- 15
- 16
...
#box.space._vfunc:select{}
---
- 1
...
#box.space._vcollation:select{}
---
- 277
...
box.session.su('admin')
---
...
Expand All @@ -262,15 +282,15 @@ box.session.su('guest')
...
#box.space._vindex:select{}
---
- 48
- 52
...
#box.space._vuser:select{}
---
- 5
...
#box.space._vpriv:select{}
---
- 15
- 16
...
#box.space._vfunc:select{}
---
Expand All @@ -280,6 +300,10 @@ box.session.su('guest')
---
- 0
...
#box.space._vcollation:select{}
---
- 277
...
box.session.su('admin')
---
...
Expand Down Expand Up @@ -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' }})
Expand Down

0 comments on commit e67cd25

Please sign in to comment.