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)
end
end
end
box.schema.upgrade{auto = true}
end
box.cfg = load_cfg
......
......@@ -2,8 +2,6 @@ local log = require('log')
local bit = require('bit')
local json = require('json')
local VERSION_ID
-- Guest user id - the default user
local GUEST = 0
-- Super User ID
......@@ -28,8 +26,29 @@ local function ismap(tab)
return mt and (mt.__serialize == 'map' or mt.__serialize == 'mapping')
end
local function version_id(major, minor, patch)
return bit.bor(bit.lshift(bit.bor(bit.lshift(major, 8), minor), 8), patch)
local mkversion = {}
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
-- space:truncate() doesn't work with disabled triggers on __index
......@@ -439,10 +458,6 @@ local function upgrade_func_to_1_6_8()
end
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_space_options_to_1_6_8()
upgrade_space_format_to_1_6_8()
......@@ -465,9 +480,6 @@ local function upgrade_to_1_6_8()
log.info("set max_id to %d", id)
box.space._schema:insert{'max_id', id}
end
log.info("set schema version to 1.6.8")
box.space._schema:replace({'version', 1, 6, 8})
end
--------------------------------------------------------------------------------
......@@ -479,14 +491,7 @@ local function upgrade_users_to_1_7_1()
end
local function upgrade_to_1_7_1()
if VERSION_ID >= version_id(1, 7, 0) then
return
end
upgrade_users_to_1_7_1()
log.info("set schema version to 1.7.1")
box.space._schema:replace({'version', 1, 7, 1})
end
--------------------------------------------------------------------------------
......@@ -524,18 +529,11 @@ local function upgrade_field_types_to_1_7_2()
end
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()
log.info("set schema version to 1.7.2")
box.space._schema:replace({'version', 1, 7, 2})
end
--------------------------------------------------------------------------------
-- Tarantool 1.7.4
-- Tarantool 1.7.5
--------------------------------------------------------------------------------
local function create_truncate_space()
......@@ -553,21 +551,16 @@ local function create_truncate_space()
end
end
local function upgrade_to_1_7_4()
if VERSION_ID >= version_id(1, 7, 4) then
return
end
local function upgrade_to_1_7_5()
create_truncate_space()
log.info("set schema version to 1.7.4")
box.space._schema:replace({'version', 1, 7, 4})
end
--------------------------------------------------------------------------------
local function upgrade()
box.cfg{}
local function upgrade(options)
options = options or {}
setmetatable(options, {__index = {auto = false}})
local version = box.space._schema:get{'version'}
if version == nil then
error('Missing "version" in box.space._schema')
......@@ -575,12 +568,34 @@ local function upgrade()
local major = version[2]
local minor = version[3]
local patch = version[4] or 0
VERSION_ID = version_id(major, minor, patch)
upgrade_to_1_6_8()
upgrade_to_1_7_1()
upgrade_to_1_7_2()
upgrade_to_1_7_4()
version = mkversion(major, minor, patch)
local handlers = {
{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
local function bootstrap()
......
......@@ -5,7 +5,7 @@ box.space._schema:select{}
---
- - ['cluster', '<cluster uuid>']
- ['max_id', 511]
- ['version', 1, 7, 4]
- ['version', 1, 7, 5]
...
box.space._cluster:select{}
---
......
......@@ -24,7 +24,7 @@ box.stat.REPLACE.total
...
box.stat.SELECT.total
---
- 0
- 1
...
box.stat.ERROR.total
---
......@@ -59,7 +59,7 @@ box.stat.REPLACE.total
...
box.stat.SELECT.total
---
- 2
- 3
...
-- check exceptions
space:get('Impossible value')
......@@ -90,7 +90,7 @@ box.stat.REPLACE.total
...
box.stat.SELECT.total
---
- 0
- 1
...
box.stat.ERROR.total
---
......
......@@ -4,6 +4,6 @@
},
"upgrade.test.lua": {
"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