Skip to content
Snippets Groups Projects
Commit 3e6393d5 authored by Ilya Verbin's avatar Ilya Verbin Committed by Vladimir Davydov
Browse files

box: use dd_version_id instead of _schema.version in get_version

By default a user might not have privileges to access the _schema space,
that will cause an error during schema_needs_upgrade(), which calls
get_version(). Fix this by using C variable dd_version_id, which is
updated in the _schema.version replace trigger.

There's a special case for upgrade() during bootstrap() - triggers are
disabled during bootstrap, that's why dd_version_id is not being updated.
Handle this by passing _initial_version=1.7.5 to the upgrade function.

Part of #7149

NO_DOC=internal
NO_CHANGELOG=internal
parent 98fcd437
No related branches found
No related tags found
No related merge requests found
......@@ -12,6 +12,7 @@
base64_bufsize
base64_decode
base64_encode
box_dd_version_id
box_decimal_abs
box_decimal_add
box_decimal_compare
......
......@@ -3,6 +3,9 @@ local bit = require('bit')
local json = require('json')
local fio = require('fio')
local xlog = require('xlog')
local ffi = require('ffi')
ffi.cdef('uint32_t box_dd_version_id(void);')
-- Guest user id - the default user
local GUEST = 0
......@@ -1288,13 +1291,10 @@ local handlers = {
-- Schema version of the snapshot.
local function get_version()
local version = box.space._schema:get{'version'}
if version == nil then
error('Missing "version" in box.space._schema')
end
local major = version[2]
local minor = version[3]
local patch = version[4] or 0
local version = ffi.C.box_dd_version_id()
local major = bit.band(bit.rshift(version, 16), 0xff)
local minor = bit.band(bit.rshift(version, 8), 0xff)
local patch = bit.band(version, 0xff)
return mkversion(major, minor, patch),
string.format("%s.%s.%s", major, minor, patch)
......@@ -1398,7 +1398,7 @@ local function upgrade(options)
options = options or {}
setmetatable(options, {__index = {auto = false}})
local version = get_version()
local version = options._initial_version or get_version()
if version < mkversion(1, 6, 8) then
log.warn('can upgrade from 1.6.8 only')
return
......@@ -1432,7 +1432,7 @@ local function bootstrap()
-- insert initial schema
initial_1_7_5()
-- upgrade schema to the latest version
upgrade()
upgrade{_initial_version = mkversion(1, 7, 5)}
set_system_triggers(true)
......
......@@ -69,13 +69,18 @@ struct rlist on_alter_func = RLIST_HEAD_INITIALIZER(on_alter_func);
struct entity_access entity_access;
/** Return current schema version */
uint32_t
box_schema_version(void)
{
return schema_version;
}
uint32_t
box_dd_version_id(void)
{
return dd_version_id;
}
static int
on_replace_dd_system_space(struct trigger *trigger, void *event)
{
......
......@@ -49,9 +49,14 @@ extern uint32_t dd_version_id;
/** Triggers invoked after schema initialization. */
extern struct rlist on_schema_init;
/** Return current monotonic schema version. */
uint32_t
box_schema_version(void);
/** Return current persistent schema version. */
uint32_t
box_dd_version_id(void);
/**
* Try to look up object name by id and type of object.
*
......
local t = require('luatest')
local g = t.group('gh-7149')
local server = require('test.luatest_helpers.server')
g.after_each(function()
g.server:drop()
end)
g.before_test('test_schema_access', function()
g.server = server:new{alias = 'master'}
g.server:start()
end)
-- Check that get_version() from upgrade.lua can be executed by any user without
-- getting an error: Read access to space '_schema' is denied for user 'user'.
g.test_schema_access = function()
g.server:exec(function()
box.cfg()
box.schema.user.create('user')
box.session.su('user')
box.schema.upgrade()
end)
end
......@@ -24,7 +24,7 @@ box.stat.REPLACE.total
...
box.stat.SELECT.total
---
- 2
- 0
...
box.stat.ERROR.total
---
......@@ -59,7 +59,7 @@ box.stat.REPLACE.total
...
box.stat.SELECT.total
---
- 6
- 4
...
-- check exceptions
space:get('Impossible value')
......@@ -77,14 +77,14 @@ space:get(1)
...
box.stat.SELECT.total
---
- 7
- 5
...
space:get(11)
---
...
box.stat.SELECT.total
---
- 8
- 6
...
space:select(5)
---
......@@ -92,7 +92,7 @@ space:select(5)
...
box.stat.SELECT.total
---
- 9
- 7
...
space:select(15)
---
......@@ -100,14 +100,14 @@ space:select(15)
...
box.stat.SELECT.total
---
- 10
- 8
...
for _ in space:pairs() do end
---
...
box.stat.SELECT.total
---
- 11
- 9
...
-- reset
box.stat.reset()
......@@ -157,7 +157,7 @@ box.stat.REPLACE.total
...
box.stat.SELECT.total
---
- 2
- 0
...
box.stat.ERROR.total
---
......
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