Skip to content
Snippets Groups Projects
Commit 29a197cf authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Roman Tsisyk
Browse files

box: auto upgrade to 1.7.5

We added _truncate space to 1.7.5 and we are going to add new system
spaces for storing sequences and triggers. Without upgrade, the
corresponding operations won't work. Since 1.7.5 is a minor upgrade,
users may not call box.schema.upgrade(), so we need to call it for them
automatically. This patch introduces infrastructure for automatic
upgrades and sets upgrade to 1.7.5 to be called automatically.

While we are at it, rename schema version 1.7.4 to 1.7.5 (1.7.4 has
already been released).

Closes #2517
parent e126d26c
No related branches found
No related tags found
No related merge requests found
Showing
with 62 additions and 47 deletions
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -359,6 +359,7 @@ local function load_cfg(cfg) ...@@ -359,6 +359,7 @@ local function load_cfg(cfg)
end end
end end
end end
box.schema.upgrade{auto = true}
end end
box.cfg = load_cfg box.cfg = load_cfg
......
...@@ -2,8 +2,6 @@ local log = require('log') ...@@ -2,8 +2,6 @@ local log = require('log')
local bit = require('bit') local bit = require('bit')
local json = require('json') local json = require('json')
local VERSION_ID
-- Guest user id - the default user -- Guest user id - the default user
local GUEST = 0 local GUEST = 0
-- Super User ID -- Super User ID
...@@ -28,8 +26,29 @@ local function ismap(tab) ...@@ -28,8 +26,29 @@ local function ismap(tab)
return mt and (mt.__serialize == 'map' or mt.__serialize == 'mapping') return mt and (mt.__serialize == 'map' or mt.__serialize == 'mapping')
end end
local function version_id(major, minor, patch) local mkversion = {}
return bit.bor(bit.lshift(bit.bor(bit.lshift(major, 8), minor), 8), patch) mkversion.__index = mkversion
setmetatable(mkversion, {__call = function(c, ...) return c.new(...) end})
function mkversion.new(major, minor, patch)
local self = setmetatable({}, mkversion)
self.major = major
self.minor = minor
self.patch = patch
self.id = bit.bor(bit.lshift(bit.bor(bit.lshift(major, 8), minor), 8), patch)
return self
end
function mkversion.__tostring(self)
return string.format('%s.%s.%s', self.major, self.minor, self.patch)
end
function mkversion.__eq(lhs, rhs)
return lhs.id == rhs.id
end
function mkversion.__lt(lhs, rhs)
return lhs.id < rhs.id
end end
-- space:truncate() doesn't work with disabled triggers on __index -- space:truncate() doesn't work with disabled triggers on __index
...@@ -439,10 +458,6 @@ local function upgrade_func_to_1_6_8() ...@@ -439,10 +458,6 @@ local function upgrade_func_to_1_6_8()
end end
local function upgrade_to_1_6_8() local function upgrade_to_1_6_8()
if VERSION_ID >= version_id(1, 6, 8) then
return
end
upgrade_index_options_to_1_6_8() upgrade_index_options_to_1_6_8()
upgrade_space_options_to_1_6_8() upgrade_space_options_to_1_6_8()
upgrade_space_format_to_1_6_8() upgrade_space_format_to_1_6_8()
...@@ -465,9 +480,6 @@ local function upgrade_to_1_6_8() ...@@ -465,9 +480,6 @@ local function upgrade_to_1_6_8()
log.info("set max_id to %d", id) log.info("set max_id to %d", id)
box.space._schema:insert{'max_id', id} box.space._schema:insert{'max_id', id}
end end
log.info("set schema version to 1.6.8")
box.space._schema:replace({'version', 1, 6, 8})
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
...@@ -479,14 +491,7 @@ local function upgrade_users_to_1_7_1() ...@@ -479,14 +491,7 @@ local function upgrade_users_to_1_7_1()
end end
local function upgrade_to_1_7_1() local function upgrade_to_1_7_1()
if VERSION_ID >= version_id(1, 7, 0) then
return
end
upgrade_users_to_1_7_1() upgrade_users_to_1_7_1()
log.info("set schema version to 1.7.1")
box.space._schema:replace({'version', 1, 7, 1})
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
...@@ -524,18 +529,11 @@ local function upgrade_field_types_to_1_7_2() ...@@ -524,18 +529,11 @@ local function upgrade_field_types_to_1_7_2()
end end
local function upgrade_to_1_7_2() local function upgrade_to_1_7_2()
if VERSION_ID >= version_id(1, 7, 2) then
return
end
upgrade_field_types_to_1_7_2() upgrade_field_types_to_1_7_2()
log.info("set schema version to 1.7.2")
box.space._schema:replace({'version', 1, 7, 2})
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
-- Tarantool 1.7.4 -- Tarantool 1.7.5
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local function create_truncate_space() local function create_truncate_space()
...@@ -553,21 +551,16 @@ local function create_truncate_space() ...@@ -553,21 +551,16 @@ local function create_truncate_space()
end end
end end
local function upgrade_to_1_7_4() local function upgrade_to_1_7_5()
if VERSION_ID >= version_id(1, 7, 4) then
return
end
create_truncate_space() create_truncate_space()
log.info("set schema version to 1.7.4")
box.space._schema:replace({'version', 1, 7, 4})
end end
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
local function upgrade() local function upgrade(options)
box.cfg{} options = options or {}
setmetatable(options, {__index = {auto = false}})
local version = box.space._schema:get{'version'} local version = box.space._schema:get{'version'}
if version == nil then if version == nil then
error('Missing "version" in box.space._schema') error('Missing "version" in box.space._schema')
...@@ -575,12 +568,34 @@ local function upgrade() ...@@ -575,12 +568,34 @@ local function upgrade()
local major = version[2] local major = version[2]
local minor = version[3] local minor = version[3]
local patch = version[4] or 0 local patch = version[4] or 0
VERSION_ID = version_id(major, minor, patch)
upgrade_to_1_6_8() version = mkversion(major, minor, patch)
upgrade_to_1_7_1()
upgrade_to_1_7_2() local handlers = {
upgrade_to_1_7_4() {version = mkversion(1, 6, 8), func = upgrade_to_1_6_8, auto = false},
{version = mkversion(1, 7, 1), func = upgrade_to_1_7_1, auto = false},
{version = mkversion(1, 7, 2), func = upgrade_to_1_7_2, auto = false},
{version = mkversion(1, 7, 5), func = upgrade_to_1_7_5, auto = true},
}
for _, handler in ipairs(handlers) do
if version >= handler.version then
goto continue
end
if options.auto and not handler.auto then
log.warn("cannot auto upgrade schema version to %s, " ..
"please call box.schema.upgrade() manually",
handler.version)
return
end
handler.func()
log.info("set schema version to %s", handler.version)
box.space._schema:replace({'version',
handler.version.major,
handler.version.minor,
handler.version.patch})
::continue::
end
end end
local function bootstrap() local function bootstrap()
......
...@@ -5,7 +5,7 @@ box.space._schema:select{} ...@@ -5,7 +5,7 @@ box.space._schema:select{}
--- ---
- - ['cluster', '<cluster uuid>'] - - ['cluster', '<cluster uuid>']
- ['max_id', 511] - ['max_id', 511]
- ['version', 1, 7, 4] - ['version', 1, 7, 5]
... ...
box.space._cluster:select{} box.space._cluster:select{}
--- ---
......
...@@ -24,7 +24,7 @@ box.stat.REPLACE.total ...@@ -24,7 +24,7 @@ box.stat.REPLACE.total
... ...
box.stat.SELECT.total box.stat.SELECT.total
--- ---
- 0 - 1
... ...
box.stat.ERROR.total box.stat.ERROR.total
--- ---
...@@ -59,7 +59,7 @@ box.stat.REPLACE.total ...@@ -59,7 +59,7 @@ box.stat.REPLACE.total
... ...
box.stat.SELECT.total box.stat.SELECT.total
--- ---
- 2 - 3
... ...
-- check exceptions -- check exceptions
space:get('Impossible value') space:get('Impossible value')
...@@ -90,7 +90,7 @@ box.stat.REPLACE.total ...@@ -90,7 +90,7 @@ box.stat.REPLACE.total
... ...
box.stat.SELECT.total box.stat.SELECT.total
--- ---
- 0 - 1
... ...
box.stat.ERROR.total box.stat.ERROR.total
--- ---
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
}, },
"upgrade.test.lua": { "upgrade.test.lua": {
"1.7.4": {"version": "1.7.4"}, "1.7.4": {"version": "1.7.4"},
"1.7.4-126": {"version": "1.7.4-126"} "1.7.5": {"version": "1.7.5"}
} }
} }
File deleted
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File deleted
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
1.7.4-126-g2ba51ab2
File added
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File added
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
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