Tarantool development patches archive
 help / color / mirror / Atom feed
From: Roman Khabibov <roman.habibov@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Konstantin Osipov <kostja@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 1/2] schema: add "_vcollation" sysview
Date: Tue, 28 May 2019 18:50:15 +0300	[thread overview]
Message-ID: <D884FEC9-0906-4452-A6A6-91FC5955E586@tarantool.org> (raw)
In-Reply-To: <20190516124329.GO26670@atlas>

Hi! Thanks for the review.

> On May 16, 2019, at 3:43 PM, Konstantin Osipov <kostja@tarantool.org> wrote:
> 
> * Roman Khabibov <roman.habibov@tarantool.org> [19/05/16 14:27]:
>> +    -- 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'}}}
> 
> use :replace, not delete + insert
I think, I can’t, because I change primary key.

> Not update, but create.
> 
> create index 'owner' on space ‘_collation’
+    log.info("create index owner on _collation")
+    box.space._index:insert{_collation.id, 1, 'owner', 'tree', {unique = false},
+                            {{2, 'unsigned'}}}

diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap
index 871a93f98..4e93a794a 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 100da0a79..fbfc2a64d 100644
--- a/src/box/lua/space.cc
+++ b/src/box/lua/space.cc
@@ -525,6 +525,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 89d6e3d52..f2a1be639 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -737,6 +737,30 @@ local function upgrade_to_2_1_3()
     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_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'}}}
+    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}
     }
 
     for _, handler in ipairs(handlers) do
diff --git a/src/box/schema_def.h b/src/box/schema_def.h
index eeeeb950b..77c004690 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..0d1259af0 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..ac1efa0ba 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", 51)
         end)
     end)
 
diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result
index 379f6c51f..f37a28c80 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, 3]
+  - ['version', 2, 1, 4]
 ...
 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',
@@ -83,7 +87,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']]]
@@ -150,6 +158,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 36ebfae09..2b7ca4f97 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..96976babb 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{}
+---
+- 277
 ...
 box.session.su('admin')
 ---
@@ -230,11 +246,11 @@ box.session.su('guest')
 ...
 #box.space._vspace:select{}
 ---
-- 22
+- 23
 ...
 #box.space._vindex:select{}
 ---
-- 48
+- 52
 ...
 #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
+- 52
 ...
 #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 c1b1de135..7fb09b4cd 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']]]
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

  reply	other threads:[~2019-05-28 15:50 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-16 11:24 [tarantool-patches] [PATCH 0/2] Add "_vcollation" sysview and fetch it in net.box 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 [this message]
2019-05-30 11:57   ` Konstantin Osipov
2019-05-16 11:24 ` [tarantool-patches] [PATCH 2/2] net.box: fetch '_vcollation' sysview into the module Roman Khabibov
2019-05-16 12:43   ` [tarantool-patches] " Konstantin Osipov
2019-05-30 11:58   ` Konstantin Osipov
2019-05-30 12:05     ` Vladislav Shpilevoy
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

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=D884FEC9-0906-4452-A6A6-91FC5955E586@tarantool.org \
    --to=roman.habibov@tarantool.org \
    --cc=kostja@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[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