Skip to content

Commit

Permalink
storage: fix core_version string in exports
Browse files Browse the repository at this point in the history
exports_deploy_funcs() used to log the core version as nil. The problem
is the fact, that table.concat was used for core version string, so the
complied exports always had nil instead of core_version.

table.concat doesn't work with non-array tables, as they have no defined
order. Let's explicitly define __tostring function for version and use
it in order to log core version.

Closes tarantool#465

NO_DOC=bugfix
  • Loading branch information
Serpentian committed Jan 11, 2024
1 parent 5bfe03b commit fc3108a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/unit-luatest/storage_exports_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,15 @@ test_group.test_deploy_privs = function(g)
box.schema.role.drop('two')
end)
end

test_group.test_core_version = function(g)
g.server:exec(function()
local exports = _G.ivexports.log[#_G.ivexports.log]
exports = _G.ivexports.compile(exports)

local version = _TARANTOOL
local pos = version:find('-g')
version = version:sub(1, pos - 1)
ilt.assert_equals(exports.core_version, version)
end)
end
14 changes: 14 additions & 0 deletions test/unit-luatest/version_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,19 @@ local lversion = require('vshard.version')

local g = t.group('version')

local function assert_version_str_equals(actual, expected)
-- Remove commit hash, if it exists. It's not saved in version.
local hash_pos = expected:find('-g')
if hash_pos then
expected = expected:sub(1, hash_pos - 1)
end
-- Remove trailing dash.
if expected:sub(-1) == '-' then
expected = expected:sub(1, -2)
end
t.assert_equals(actual, expected)
end

g.test_order = function()
-- Example of a full version: 2.10.0-beta2-86-gc9981a567.
local versions = {
Expand Down Expand Up @@ -215,6 +228,7 @@ g.test_order = function()
t.assert(not (ver > v.ver), ('versions not >, %d'):format(i))
t.assert(ver <= v.ver, ('versions <=, %d'):format(i))
t.assert(ver >= v.ver, ('versions <=, %d'):format(i))
assert_version_str_equals(tostring(ver), v.str)
if i > 1 then
local prev = versions[i - 1].ver
t.assert(prev < ver, ('versions <, %d'):format(i))
Expand Down
2 changes: 1 addition & 1 deletion vshard/storage/exports.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ local function exports_compile(exports)
end
return {
vshard_version = exports.version,
core_version = table.concat(lvutil.core_version, '.'),
core_version = tostring(lvutil.core_version),
funcs = compiled_funcs,
}
end
Expand Down
13 changes: 13 additions & 0 deletions vshard/version.lua
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,19 @@ local version_mt = {
__le = function(l, r)
return version_cmp(l, r) <= 0
end,
__tostring = function(v)
local str = v.id_major .. '.' .. v.id_middle .. '.' .. v.id_minor
if v.rel_type then
str = str .. '-' .. v.rel_type
if v.rel_num ~= 0 then
str = str .. v.rel_num
end
end
if v.id_commit ~= 0 then
str = str .. '-' .. v.id_commit
end
return str
end,
}

local function version_new(id_major, id_middle, id_minor, rel_type, rel_num,
Expand Down

0 comments on commit fc3108a

Please sign in to comment.