Tarantool development patches archive
 help / color / mirror / Atom feed
* [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box
@ 2019-03-22  0:27 Roman Khabibov
  2019-03-22  0:27 ` [PATCH 1/2] schema: add "_vcollation" sysview Roman Khabibov
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Roman Khabibov @ 2019-03-22  0:27 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

As I understood "readable for all" means that filter for
"_vcollation" must always return "true", because the condition
"User has read access to according system space" is always
met.

Roman Khabibov (2):
  schema: add "_vcollation" sysview
  net.box: fetch '_vcollation' sysview into the module

 src/box/bootstrap.snap             | Bin 1831 -> 1873 bytes
 src/box/lua/net_box.lua            |  19 ++++--
 src/box/lua/space.cc               |   2 +
 src/box/lua/upgrade.lua            |  25 +++++++-
 src/box/schema.h                   |   4 ++
 src/box/schema_def.h               |   2 +
 src/box/sysview.c                  |  14 +++++
 test/app-tap/tarantoolctl.test.lua |   4 +-
 test/box-py/bootstrap.result       |  13 +++-
 test/box/access_misc.result        |   4 ++
 test/box/access_sysview.result     |  96 ++++++++++++++++++++++++++---
 test/box/access_sysview.test.lua   |  30 +++++++++
 test/box/alter.result              |   6 +-
 test/box/net.box.result            |   2 +-
 14 files changed, 202 insertions(+), 19 deletions(-)

-- 
2.17.2 (Apple Git-113)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] schema: add "_vcollation" sysview
  2019-03-22  0:27 [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Roman Khabibov
@ 2019-03-22  0:27 ` Roman Khabibov
  2019-03-22  0:27 ` [PATCH 2/2] net.box: fetch '_vcollation' sysview into the module Roman Khabibov
  2019-03-22  8:33 ` [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Vladimir Davydov
  2 siblings, 0 replies; 5+ messages in thread
From: Roman Khabibov @ 2019-03-22  0:27 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

Add "_vcollation" sysview to read it from net.box. This
sysview is always readable, exept when the user doesn't have
"public" role.

Needed for #3941
---
 src/box/bootstrap.snap             | Bin 1831 -> 1873 bytes
 src/box/lua/space.cc               |   2 +
 src/box/lua/upgrade.lua            |  25 +++++++-
 src/box/schema.h                   |   4 ++
 src/box/schema_def.h               |   2 +
 src/box/sysview.c                  |  14 +++++
 test/app-tap/tarantoolctl.test.lua |   4 +-
 test/box-py/bootstrap.result       |  13 +++-
 test/box/access_misc.result        |   4 ++
 test/box/access_sysview.result     |  96 ++++++++++++++++++++++++++---
 test/box/access_sysview.test.lua   |  30 +++++++++
 test/box/alter.result              |   6 +-
 12 files changed, 187 insertions(+), 13 deletions(-)

diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap
index 0bb446fb6903ac3ef630c419b909f7db3df0372a..c2f1ab54cf523d856f6ec3c093de38f3433f91cc 100644
GIT binary patch
delta 1869
zcmV-T2eSC54$%&f8Gkc2Gc9LhIAb#~VK+B03Q2BrbYX5|WjY`*F*r72H8wOYIb$$p
zEi^PTW-U25H)Sn0IW=KnGh$(6W@TjxRzqxWV{1AfdwmKD)w&D1%?8#0&bw;@prrr+
z0000ewJ-euP;E8<nn;KbNzfQK0RUe-z!wj2qdTLCN?x!Gl7CT?NPz>LIKj*4QSetW
zV(*kRxtU^;B)#mCct#+d0;MmfZ^lc_Gtu2g6V)zRXe$sZQ%V8e0NDWR03-sNr6raJ
zQy2tCeR;0^2x8J~X$&h{p9J>lygNUGTubOrXFbcrtY3Bf%IeDiyf-!<6vu9A4#K?G
zU*>w8z1Zq8FMr?fu*hf6!a5c-RK0w~G2Gt_h&~vul5`kM(Y`<U-t~U(SG{+^md@m@
zQfoD8!j%NHHr6?HZUHt+%htxMyhYinfBJXlGoakvA`75L3mLHbUf5+l$|?~@+BQqe
zB~OCr(6J$d#aUm6I!1{&(q?ICtJPuV`$-v-x>;HtRevKd-yh66UEE8hRLe_{iY+N6
zTrPCc$pXOApyl^qCi50)7{nbvX}5QeBo)^F!>;lEWM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?aZr+0cGNIK
z43t=2$s?w>#u23tKrzBb1(Hfa^nV<p45fgF?oxj_`)Ep_UK{`xaiyL&vvbKES-e0i
R9JX=Dom4Gm<qp*lt?dSjU0DDC

diff --git a/src/box/lua/space.cc b/src/box/lua/space.cc
index 7aa0b6661..cd8eb2471 100644
--- a/src/box/lua/space.cc
+++ b/src/box/lua/space.cc
@@ -546,6 +546,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 70cfb4f2e..16cc2a982 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -636,12 +636,35 @@ local function upgrade(options)
         return
     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_1_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("update index owner on _collation")
+    box.space._index:insert{_collation.id, 1, 'owner', 'tree', {unique = false}, {{2, 'unsigned'}}}
+    create_vcollation_space()
+end
+
     local handlers = {
         {version = mkversion(1, 7, 6), func = upgrade_to_1_7_6, auto = true},
         {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, 2), func = upgrade_to_2_1_2, auto = true}
     }
 
     for _, handler in ipairs(handlers) do
diff --git a/src/box/schema.h b/src/box/schema.h
index f3df08b48..223dd9943 100644
--- a/src/box/schema.h
+++ b/src/box/schema.h
@@ -256,6 +256,7 @@ struct entity_access {
        struct access user[BOX_USER_MAX];
        struct access role[BOX_USER_MAX];
        struct access sequence[BOX_USER_MAX];
+       struct access collation[BOX_USER_MAX];
 };
 
 /** A single instance of the global entities. */
@@ -281,6 +282,9 @@ entity_access_get(enum schema_object_type type)
 	case SC_SEQUENCE:
 	case SC_ENTITY_SEQUENCE:
 		return entity_access.sequence;
+	case SC_COLLATION:
+	case SC_ENTITY_COLLATION:
+		return entity_access.collation;
 	default:
 		return NULL;
 	}
diff --git a/src/box/schema_def.h b/src/box/schema_def.h
index a760ecc3f..412e34092 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 63b669d07..4bf402cbd 100644
--- a/src/box/sysview.c
+++ b/src/box/sysview.c
@@ -402,6 +402,15 @@ 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)
 {
@@ -428,6 +437,11 @@ sysview_space_create_index(struct space *space, struct index_def *def)
 		source_index_id = def->iid;
 		filter = vspace_filter;
 		break;
+	case BOX_VCOLLATION_ID:
+		source_space_id = BOX_COLLATION_ID;
+		source_index_id = def->iid;
+		filter = vcollation_filter;
+		break;
 	case BOX_VUSER_ID:
 		source_space_id = BOX_USER_ID;
 		source_index_id = def->iid;
diff --git a/test/app-tap/tarantoolctl.test.lua b/test/app-tap/tarantoolctl.test.lua
index db046e03f..55484d0a8 100755
--- a/test/app-tap/tarantoolctl.test.lua
+++ b/test/app-tap/tarantoolctl.test.lua
@@ -388,8 +388,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", 23)
-            check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 49)
+            check_ctlcat_snap(test_i, dir, "--space=280", "---\n", 24)
+            check_ctlcat_snap(test_i, dir, "--space=288", "---\n", 53)
         end)
     end)
 
diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result
index 3e4394557..91dfd7929 100644
--- a/test/box-py/bootstrap.result
+++ b/test/box-py/bootstrap.result
@@ -4,7 +4,7 @@ box.internal.bootstrap()
 box.space._schema:select{}
 ---
 - - ['max_id', 511]
-  - ['version', 2, 1, 0]
+  - ['version', 2, 1, 2]
 ...
 box.space._cluster:select{}
 ---
@@ -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',
@@ -88,7 +92,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']]]
@@ -158,6 +166,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 4ffeb386a..e15075fff 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 fd8b14248..b65ac4352 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
+- 24
+...
+#box.space._vcollation:select{}
+---
+- 4
 ...
 box.session.su('admin')
 ---
@@ -230,11 +246,11 @@ box.session.su('guest')
 ...
 #box.space._vspace:select{}
 ---
-- 24
+- 25
 ...
 #box.space._vindex:select{}
 ---
-- 50
+- 54
 ...
 #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{}
+---
+- 4
+...
 box.session.su('admin')
 ---
 ...
@@ -262,7 +282,7 @@ box.session.su('guest')
 ...
 #box.space._vindex:select{}
 ---
-- 50
+- 54
 ...
 #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{}
+---
+- 4
+...
 box.session.su('admin')
 ---
 ...
@@ -631,6 +655,64 @@ 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, 'none', 1, 'BINARY', '', {}]
+  - [1, 'unicode', 1, 'ICU', '', {}]
+  - [2, 'unicode_ci', 1, 'ICU', '', {'strength': 'primary'}]
+  - [3, 'binary', 1, 'BINARY', '', {}]
+  - [4, 'test', 1, 'ICU', 'ru-RU', {}]
+...
+#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{}
+---
+- 5
+...
+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 4cc5611a6..287b7bbbe 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{}
+#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 9a1086e0c..bbd4e41f2 100644
--- a/test/box/alter.result
+++ b/test/box/alter.result
@@ -183,7 +183,11 @@ _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']]]
-- 
2.17.2 (Apple Git-113)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 2/2] net.box: fetch '_vcollation' sysview into the module
  2019-03-22  0:27 [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Roman Khabibov
  2019-03-22  0:27 ` [PATCH 1/2] schema: add "_vcollation" sysview Roman Khabibov
@ 2019-03-22  0:27 ` Roman Khabibov
  2019-03-22  8:33 ` [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Vladimir Davydov
  2 siblings, 0 replies; 5+ messages in thread
From: Roman Khabibov @ 2019-03-22  0:27 UTC (permalink / raw)
  To: tarantool-patches; +Cc: vdavydov.dev

Fetch "_vcollation" sysview to show collation name instead collation id.

Closes #3941
---
 src/box/lua/net_box.lua | 19 ++++++++++++++-----
 test/box/net.box.result |  2 +-
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/src/box/lua/net_box.lua b/src/box/lua/net_box.lua
index b3139a3f5..05960fa90 100644
--- a/src/box/lua/net_box.lua
+++ b/src/box/lua/net_box.lua
@@ -30,6 +30,7 @@ local decode_greeting = internal.decode_greeting
 local TIMEOUT_INFINITY = 500 * 365 * 86400
 local VSPACE_ID        = 281
 local VINDEX_ID        = 289
+local VCOLLATION_ID    = 277
 local DEFAULT_CONNECT_TIMEOUT = 10
 
 local IPROTO_STATUS_KEY    = 0x00
@@ -723,11 +724,15 @@ local function create_transport(host, port, user, password, callback,
         end
         local select1_id = new_request_id()
         local select2_id = new_request_id()
+        local select3_id = new_request_id()
         local response = {}
         -- fetch everything from space _vspace, 2 = ITER_ALL
         encode_select(send_buf, select1_id, VSPACE_ID, 0, 2, 0, 0xFFFFFFFF, nil)
         -- fetch everything from space _vindex, 2 = ITER_ALL
         encode_select(send_buf, select2_id, VINDEX_ID, 0, 2, 0, 0xFFFFFFFF, nil)
+        -- fetch everything from space _vcollation, 2 = ITER_ALL
+        encode_select(send_buf, select3_id, VCOLLATION_ID, 0, 2, 0, 0xFFFFFFFF, nil)
+
         schema_version = nil -- any schema_version will do provided that
                              -- it is consistent across responses
         repeat
@@ -735,7 +740,7 @@ local function create_transport(host, port, user, password, callback,
             if err then return error_sm(err, hdr) end
             dispatch_response_iproto(hdr, body_rpos, body_end)
             local id = hdr[IPROTO_SYNC_KEY]
-            if id == select1_id or id == select2_id then
+            if id == select1_id or id == select2_id or id == select3_id then
                 -- response to a schema query we've submitted
                 local status = hdr[IPROTO_STATUS_KEY]
                 local response_schema_version = hdr[IPROTO_SCHEMA_VERSION_KEY]
@@ -754,9 +759,9 @@ local function create_transport(host, port, user, password, callback,
                 body, body_end = decode(body_rpos)
                 response[id] = body[IPROTO_DATA_KEY]
             end
-        until response[select1_id] and response[select2_id]
+        until response[select1_id] and response[select2_id] and response[select3_id]
         callback('did_fetch_schema', schema_version,
-                 response[select1_id], response[select2_id])
+                 response[select1_id], response[select2_id], response[select3_id])
         set_state('active')
         return iproto_sm(schema_version)
     end
@@ -1176,7 +1181,7 @@ function remote_methods:timeout(timeout)
     return self
 end
 
-function remote_methods:_install_schema(schema_version, spaces, indices)
+function remote_methods:_install_schema(schema_version, spaces, indices, collations)
     local sl, space_mt, index_mt = {}, self._space_mt, self._index_mt
     for _, space in pairs(spaces) do
         local name = space[3]
@@ -1244,11 +1249,15 @@ function remote_methods:_install_schema(schema_version, spaces, indices)
                 local pkcollationid = index[PARTS][k].collation
                 local pktype = index[PARTS][k][2] or index[PARTS][k].type
                 local pkfield = index[PARTS][k][1] or index[PARTS][k].field
+                local pkcollation = nil
+                if pkcollationid ~= nil then
+                    pkcollation = collations[pkcollationid + 1][2]
+                end
 
                 local pk = {
                     type = pktype,
                     fieldno = pkfield + 1,
-                    collation_id = pkcollationid,
+                    collation = pkcollation,
                     is_nullable = pknullable
                 }
                 idx.parts[k] = pk
diff --git a/test/box/net.box.result b/test/box/net.box.result
index b800531b4..0bcf3b309 100644
--- a/test/box/net.box.result
+++ b/test/box/net.box.result
@@ -2666,7 +2666,7 @@ c.space.test.index.sk.parts
 ---
 - - type: string
     is_nullable: false
-    collation_id: 4
+    collation: test
     fieldno: 1
 ...
 c:close()
-- 
2.17.2 (Apple Git-113)

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box
  2019-03-22  0:27 [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Roman Khabibov
  2019-03-22  0:27 ` [PATCH 1/2] schema: add "_vcollation" sysview Roman Khabibov
  2019-03-22  0:27 ` [PATCH 2/2] net.box: fetch '_vcollation' sysview into the module Roman Khabibov
@ 2019-03-22  8:33 ` Vladimir Davydov
  2019-03-22 15:39   ` [tarantool-patches] " Konstantin Osipov
  2 siblings, 1 reply; 5+ messages in thread
From: Vladimir Davydov @ 2019-03-22  8:33 UTC (permalink / raw)
  To: Roman Khabibov; +Cc: tarantool-patches

On Fri, Mar 22, 2019 at 03:27:35AM +0300, Roman Khabibov wrote:
> As I understood "readable for all" means that filter for
> "_vcollation" must always return "true", because the condition
> "User has read access to according system space" is always
> met.

Why not simply grant read acces to _collation to each user instead?

Anyway, I don't understand why _collation space stores creator uid.
What would we possibly need it for? Create a collation that is usable
by one user, but not visible by others? It doesn't make any sense to me.
I think that collations should only be created/modified/deleted by the
admin, but allowed to be used by anyone...

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [tarantool-patches] Re: [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box
  2019-03-22  8:33 ` [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Vladimir Davydov
@ 2019-03-22 15:39   ` Konstantin Osipov
  0 siblings, 0 replies; 5+ messages in thread
From: Konstantin Osipov @ 2019-03-22 15:39 UTC (permalink / raw)
  To: tarantool-patches; +Cc: Roman Khabibov

* Vladimir Davydov <vdavydov.dev@gmail.com> [19/03/22 12:43]:
> On Fri, Mar 22, 2019 at 03:27:35AM +0300, Roman Khabibov wrote:
> > As I understood "readable for all" means that filter for
> > "_vcollation" must always return "true", because the condition
> > "User has read access to according system space" is always
> > met.
> 
> Why not simply grant read acces to _collation to each user instead?

We discussed this with Roman and I asked him to create a view.

> Anyway, I don't understand why _collation space stores creator uid.
> What would we possibly need it for? Create a collation that is usable
> by one user, but not visible by others? It doesn't make any sense to me.
> I think that collations should only be created/modified/deleted by the
> admin, but allowed to be used by anyone...

In some databases collations are user-level objects. Basically,
owner id is there to not complicate our security model.

-- 
Konstantin Osipov, Moscow, Russia, +7 903 626 22 32
http://tarantool.io - www.twitter.com/kostja_osipov

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-03-22 15:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-22  0:27 [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Roman Khabibov
2019-03-22  0:27 ` [PATCH 1/2] schema: add "_vcollation" sysview Roman Khabibov
2019-03-22  0:27 ` [PATCH 2/2] net.box: fetch '_vcollation' sysview into the module Roman Khabibov
2019-03-22  8:33 ` [PATCH 0/2] add '_vcollation' sysview and fetch it in net.box Vladimir Davydov
2019-03-22 15:39   ` [tarantool-patches] " Konstantin Osipov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox