Skip to content
Snippets Groups Projects
Commit 34db8970 authored by Konstantin Osipov's avatar Konstantin Osipov
Browse files

Implement space:format(). Set format for system spaces.

parent 0c448147
No related branches found
No related tags found
No related merge requests found
...@@ -20,42 +20,79 @@ _schema:insert{'version', 1, 6} ...@@ -20,42 +20,79 @@ _schema:insert{'version', 1, 6}
-- --
-- _schema -- _schema
-- --
_space:insert{_schema.id, ADMIN, '_schema', 'memtx', 0, ''} _space:insert{_schema.id, ADMIN, '_schema', 'memtx', 0, '', {}}
-- --
-- _space -- _space
-- --
_space:insert{_space.id, ADMIN, '_space', 'memtx', 0, ''} _space:insert{_space.id, ADMIN, '_space', 'memtx', 0, '', {}}
-- --
-- _index -- _index
-- --
_space:insert{_index.id, ADMIN, '_index', 'memtx', 0, ''} _space:insert{_index.id, ADMIN, '_index', 'memtx', 0, '', {}}
-- --
-- _func -- _func
-- --
_space:insert{_func.id, ADMIN, '_func', 'memtx', 0, ''} _space:insert{_func.id, ADMIN, '_func', 'memtx', 0, '', {}}
-- --
-- _user -- _user
-- --
_space:insert{_user.id, ADMIN, '_user', 'memtx', 0, ''} _space:insert{_user.id, ADMIN, '_user', 'memtx', 0, '', {}}
-- --
-- _priv -- _priv
-- --
_space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, ''} _space:insert{_priv.id, ADMIN, '_priv', 'memtx', 0, '', {}}
-- --
-- _cluster -- _cluster
-- --
_space:insert{_cluster.id, ADMIN, '_cluster', 'memtx', 0, ''} _space:insert{_cluster.id, ADMIN, '_cluster', 'memtx', 0, ''}
-- define formats.
-- stick to the following convention:
-- prefer user id (owner id) in field #2 (base-1)
-- prefer object name in field #3 (base-1)
--
format={}
format[1] = {type='str', name='key'}
_schema:format(format)
format={}
format[1] = {name='id', type='num'}
format[2] = {name='owner', type='num'}
format[3] = {name='name', type='str'}
format[4] = {name='engine', type='str'}
format[5] = {name='field_count', type='num'}
format[6] = {name='flags', type='str'}
format[7] = {name='format', type='*'}
_space:format(format)
format={}
format[1] = {name='id', type='num'}
format[2] = {name='owner', type='num'}
format[3] = {name='name', type='str'}
format[4] = {name='setuid', type='num'}
_func:format(format)
format={}
format[1] = {name='id', type='num'}
format[2] = {name='owner', type='num'}
format[3] = {name='name', type='str'}
format[4] = {name='type', type='str'}
format[5] = {name='auth', type='*'}
_user:format(format)
format={}
format[1] = {name='grantor', type='num'}
format[2] = {name='grantee', type='num'}
format[3] = {name='object_type', type='str'}
format[4] = {name='object_id', type='num'}
format[5] = {name='privilege', type='num'}
_priv:format(format)
format = {}
format[1] = {name='id', type='num'}
format[2] = {name='uuid', type='str'}
_cluster:format(format)
-- define indexes -- define indexes
_index:insert{_schema.id, 0, 'primary', 'tree', 1, 1, 0, 'str'}
-- stick to the following convention: -- stick to the following convention:
-- prefer user id (owner id) in field #1 -- index on owner id is index #1 (base-0)
-- prefer object name in field #2 -- index on object name is index #2 (base-0)
-- index on owner id is index #1
-- index on object name is index #2
--
-- space name is unique -- space name is unique
_index:insert{_schema.id, 0, 'primary', 'tree', 1, 1, 0, 'str'}
_index:insert{_space.id, 0, 'primary', 'tree', 1, 1, 0, 'num'} _index:insert{_space.id, 0, 'primary', 'tree', 1, 1, 0, 'num'}
_index:insert{_space.id, 1, 'owner', 'tree', 0, 1, 1, 'num'} _index:insert{_space.id, 1, 'owner', 'tree', 0, 1, 1, 'num'}
_index:insert{_space.id, 2, 'name', 'tree', 1, 1, 2, 'str'} _index:insert{_space.id, 2, 'name', 'tree', 1, 1, 2, 'str'}
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -189,6 +189,7 @@ box.schema.space.create = function(name, options) ...@@ -189,6 +189,7 @@ box.schema.space.create = function(name, options)
id = 'number', id = 'number',
field_count = 'number', field_count = 'number',
user = 'string, number', user = 'string, number',
format = 'table'
} }
local options_defaults = { local options_defaults = {
engine = 'memtx', engine = 'memtx',
...@@ -222,10 +223,23 @@ box.schema.space.create = function(name, options) ...@@ -222,10 +223,23 @@ box.schema.space.create = function(name, options)
uid = session.uid() uid = session.uid()
end end
local temporary = options.temporary and "temporary" or "" local temporary = options.temporary and "temporary" or ""
_space:insert{id, uid, name, options.engine, options.field_count, temporary} local format = options.format and options.format or {}
_space:insert{id, uid, name, options.engine, options.field_count, temporary, format}
return box.space[id], "created" return box.space[id], "created"
end end
-- space format - the metadata about space fields
function box.schema.space.format(id, format)
_space = box.space._space
check_param(id, 'id', 'number')
check_param(format, 'format', 'table')
if format == nil then
return _space:get(id)[7]
else
_space:update(id, {{'=', 7, format}})
end
end
box.schema.create_space = box.schema.space.create box.schema.create_space = box.schema.space.create
box.schema.space.drop = function(space_id) box.schema.space.drop = function(space_id)
...@@ -809,6 +823,9 @@ function box.schema.space.bless(space) ...@@ -809,6 +823,9 @@ function box.schema.space.bless(space)
_index:insert(keys[i]) _index:insert(keys[i])
end end
end end
space_mt.format = function(space, format)
return box.schema.space.format(space.id, format)
end
space_mt.drop = function(space) space_mt.drop = function(space)
return box.schema.space.drop(space.id) return box.schema.space.drop(space.id)
end end
......
...@@ -253,7 +253,10 @@ box.space._user:select(1) ...@@ -253,7 +253,10 @@ box.space._user:select(1)
... ...
box.space._space:select(280) box.space._space:select(280)
--- ---
- - [280, 1, '_space', 'memtx', 0, ''] - - [280, 1, '_space', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'},
{'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, {
'name': 'format', 'type': '*'}]]
... ...
us = box.schema.create_space('uniuser_space') us = box.schema.create_space('uniuser_space')
--- ---
...@@ -577,13 +580,22 @@ box.space._user:select() ...@@ -577,13 +580,22 @@ box.space._user:select()
... ...
box.space._space:select() box.space._space:select()
--- ---
- - [272, 1, '_schema', 'memtx', 0, ''] - - [272, 1, '_schema', 'memtx', 0, '', [{'type': 'str', 'name': 'key'}]]
- [280, 1, '_space', 'memtx', 0, ''] - [280, 1, '_space', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'},
{'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, {
'name': 'format', 'type': '*'}]]
- [288, 1, '_index', 'memtx', 0, ''] - [288, 1, '_index', 'memtx', 0, '']
- [296, 1, '_func', 'memtx', 0, ''] - [296, 1, '_func', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
- [304, 1, '_user', 'memtx', 0, ''] 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'setuid', 'type': 'num'}]]
- [312, 1, '_priv', 'memtx', 0, ''] - [304, 1, '_user', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
- [320, 1, '_cluster', 'memtx', 0, ''] 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'type', 'type': 'str'},
{'name': 'auth', 'type': '*'}]]
- [312, 1, '_priv', 'memtx', 0, '', [{'name': 'grantor', 'type': 'num'}, {'name': 'grantee',
'type': 'num'}, {'name': 'object_type', 'type': 'str'}, {'name': 'object_id',
'type': 'num'}, {'name': 'privilege', 'type': 'num'}]]
- [320, 1, '_cluster', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'uuid',
'type': 'str'}]]
... ...
box.space._func:select() box.space._func:select()
--- ---
......
...@@ -273,7 +273,7 @@ box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}}) ...@@ -273,7 +273,7 @@ box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 1}})
-- remove field_count - ok -- remove field_count - ok
box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}}) box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 0}})
--- ---
- [512, 1, 'test', 'memtx', 0, ''] - [512, 1, 'test', 'memtx', 0, '', []]
... ...
s:select{} s:select{}
--- ---
...@@ -294,7 +294,7 @@ s:select{} ...@@ -294,7 +294,7 @@ s:select{}
-- set field_count of an empty space -- set field_count of an empty space
box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}}) box.space['_space']:update(s.id, {{"=", FIELD_COUNT + 1, 3}})
--- ---
- [512, 1, 'test', 'memtx', 3, ''] - [512, 1, 'test', 'memtx', 3, '', []]
... ...
s:select{} s:select{}
--- ---
......
...@@ -47,13 +47,22 @@ box.space._cluster:select{} ...@@ -47,13 +47,22 @@ box.space._cluster:select{}
... ...
box.space._space:select{} box.space._space:select{}
--- ---
- - [272, 1, '_schema', 'memtx', 0, ''] - - [272, 1, '_schema', 'memtx', 0, '', [{'type': 'str', 'name': 'key'}]]
- [280, 1, '_space', 'memtx', 0, ''] - [280, 1, '_space', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
- [288, 1, '_index', 'memtx', 0, ''] 'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'engine', 'type': 'str'},
- [296, 1, '_func', 'memtx', 0, ''] {'name': 'field_count', 'type': 'num'}, {'name': 'flags', 'type': 'str'}, {
- [304, 1, '_user', 'memtx', 0, ''] 'name': 'format', 'type': '*'}]]
- [312, 1, '_priv', 'memtx', 0, ''] - [288, 1, '_index', 'memtx', 0, '', []]
- [320, 1, '_cluster', 'memtx', 0, ''] - [296, 1, '_func', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'setuid', 'type': 'num'}]]
- [304, 1, '_user', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'owner',
'type': 'num'}, {'name': 'name', 'type': 'str'}, {'name': 'type', 'type': 'str'},
{'name': 'auth', 'type': '*'}]]
- [312, 1, '_priv', 'memtx', 0, '', [{'name': 'grantor', 'type': 'num'}, {'name': 'grantee',
'type': 'num'}, {'name': 'object_type', 'type': 'str'}, {'name': 'object_id',
'type': 'num'}, {'name': 'privilege', 'type': 'num'}]]
- [320, 1, '_cluster', 'memtx', 0, '', [{'name': 'id', 'type': 'num'}, {'name': 'uuid',
'type': 'str'}]]
... ...
box.space._index:select{} box.space._index:select{}
--- ---
......
...@@ -55,7 +55,7 @@ s:len() ...@@ -55,7 +55,7 @@ s:len()
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}})
--- ---
- [512, 1, 't', 'memtx', 0, 'temporary'] - [512, 1, 't', 'memtx', 0, 'temporary', []]
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ''}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ''}})
--- ---
...@@ -79,7 +79,7 @@ s.temporary ...@@ -79,7 +79,7 @@ s.temporary
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}})
--- ---
- [512, 1, 't', 'memtx', 0, 'no-temporary'] - [512, 1, 't', 'memtx', 0, 'no-temporary', []]
... ...
s.temporary s.temporary
--- ---
...@@ -87,7 +87,7 @@ s.temporary ...@@ -87,7 +87,7 @@ s.temporary
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ',:asfda:temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, ',:asfda:temporary'}})
--- ---
- [512, 1, 't', 'memtx', 0, ',:asfda:temporary'] - [512, 1, 't', 'memtx', 0, ',:asfda:temporary', []]
... ...
s.temporary s.temporary
--- ---
...@@ -95,7 +95,7 @@ s.temporary ...@@ -95,7 +95,7 @@ s.temporary
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'a,b,c,d,e'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'a,b,c,d,e'}})
--- ---
- [512, 1, 't', 'memtx', 0, 'a,b,c,d,e'] - [512, 1, 't', 'memtx', 0, 'a,b,c,d,e', []]
... ...
s.temporary s.temporary
--- ---
...@@ -103,7 +103,7 @@ s.temporary ...@@ -103,7 +103,7 @@ s.temporary
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}})
--- ---
- [512, 1, 't', 'memtx', 0, 'temporary'] - [512, 1, 't', 'memtx', 0, 'temporary', []]
... ...
s.temporary s.temporary
--- ---
...@@ -118,7 +118,7 @@ s:insert{1, 2, 3} ...@@ -118,7 +118,7 @@ s:insert{1, 2, 3}
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'temporary'}})
--- ---
- [512, 1, 't', 'memtx', 0, 'temporary'] - [512, 1, 't', 'memtx', 0, 'temporary', []]
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}})
--- ---
...@@ -130,7 +130,7 @@ s:delete{1} ...@@ -130,7 +130,7 @@ s:delete{1}
... ...
box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}}) box.space[box.schema.SPACE_ID]:update(s.id, {{'=', FLAGS, 'no-temporary'}})
--- ---
- [512, 1, 't', 'memtx', 0, 'no-temporary'] - [512, 1, 't', 'memtx', 0, 'no-temporary', []]
... ...
s:drop() s:drop()
--- ---
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment