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 authored and locker committed Jun 6, 2019
1 parent 8e87dcf commit 3e3ef18
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 10 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 @@ -603,6 +603,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
8 changes: 8 additions & 0 deletions src/box/lua/upgrade.lua
Expand Up @@ -813,9 +813,17 @@ local function upgrade_ck_constraint_to_2_2_1()
end
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_1()
upgrade_sequence_to_2_2_1()
upgrade_ck_constraint_to_2_2_1()
create_vcollation_space()
end

--------------------------------------------------------------------------------
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", 22)
check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 48)
check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 23)
check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 50)
end)
end)

Expand Down
7 changes: 7 additions & 0 deletions test/box-py/bootstrap.result
Expand Up @@ -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 @@ -88,6 +92,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']]]
Expand Down Expand Up @@ -155,6 +161,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
- 22
...
#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{}
---
- 23
- 24
...
#box.space._vindex:select{}
---
- 49
- 51
...
#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{}
---
- 49
- 51
...
#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
30 changes: 30 additions & 0 deletions test/box/access_sysview.test.lua
Expand Up @@ -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')
Expand All @@ -48,13 +50,15 @@ 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')
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')
Expand Down Expand Up @@ -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')
Expand All @@ -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')
Expand Down Expand Up @@ -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
--
Expand Down
2 changes: 2 additions & 0 deletions test/box/alter.result
Expand Up @@ -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']]]
Expand Down
2 changes: 1 addition & 1 deletion test/wal_off/alter.result
Expand Up @@ -28,7 +28,7 @@ end;
...
#spaces;
---
- 65504
- 65503
...
-- cleanup
for k, v in pairs(spaces) do
Expand Down

0 comments on commit 3e3ef18

Please sign in to comment.