Skip to content

Commit

Permalink
config: use vshard-ee if available
Browse files Browse the repository at this point in the history
The new closed-source `vshard-ee` module was recently introduced. It is
based on the open-source `vshard` module and, as far as I know, provides
the same API.

Let's configure `vshard-ee` in the same way as `vshard` if sharding is
enabled in tarantool's configuration.

Prefer `vshard-ee` if both are available.

Fixes tarantool/tarantool-ee#815

@TarantoolBot document
Title: config: vshard-ee is now supported

The declarative configuration supports `vshard-ee` in addition to
`vshard` since Tarantool 3.1.1 and 3.2+.

`vshard` is mentioned in the documentation at least [here][1]. All such
places should be updated to mention both `vshard-ee` and `vshard`.

[1]: https://www.tarantool.io/en/doc/latest/reference/configuration/configuration_reference/#sharding
  • Loading branch information
Totktonada committed Jun 18, 2024
1 parent 3abd4f9 commit 29519c7
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 20 deletions.
4 changes: 4 additions & 0 deletions changelogs/unreleased/config-support-vshard-ee.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## bugfix/config

* Support for `vshard-ee` in addition to `vshard` in the sharding configuration
logic (ghe-815).
6 changes: 4 additions & 2 deletions src/box/lua/config/applier/credentials.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local expression = require('internal.config.utils.expression')
local log = require('internal.config.utils.log')
local loaders = require('internal.loaders')
local digest = require('digest')
local fiber = require('fiber')

Expand Down Expand Up @@ -318,9 +319,10 @@ local function sharding_role(configdata)
-- The error will be thrown later, in sharding.lua. Here we are simply
-- trying to avoid the "module not found" error.
--
local ok, vshard = pcall(require, 'vshard')
local ok, vshard = pcall(loaders.require_first, 'vshard-ee', 'vshard')
if ok and expression.eval('v >= 0.1.25', {v = vshard.consts.VERSION}) then
local vexports = require('vshard.storage.exports')
local vexports = loaders.require_first('vshard-ee.storage.exports',
'vshard.storage.exports')
local exports = vexports.compile(vexports.log[#vexports.log])
for name in pairs(exports.funcs) do
table.insert(funcs, name)
Expand Down
8 changes: 5 additions & 3 deletions src/box/lua/config/applier/sharding.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local expression = require('internal.config.utils.expression')
local log = require('internal.config.utils.log')
local loaders = require('internal.loaders')
_G.vshard = nil

-- Watcher which will create all the necessary functions.
Expand All @@ -12,9 +13,9 @@ local function apply(config)
return
end
-- Make sure vshard is available and its version is not too old.
local ok, vshard = pcall(require, 'vshard')
local ok, vshard = pcall(loaders.require_first, 'vshard-ee', 'vshard')
if not ok then
error('The vshard module is not available', 0)
error('The vshard-ee/vshard module is not available', 0)
end
if expression.eval('v < 0.1.25', {v = vshard.consts.VERSION}) then
error('The vshard module is too old: the minimum supported version ' ..
Expand All @@ -36,7 +37,8 @@ local function apply(config)
-- Start a watcher which will create all the necessary functions.
if watcher == nil then
local function deploy_funcs()
local vexports = require('vshard.storage.exports')
local vexports = loaders.require_first(
'vshard-ee.storage.exports', 'vshard.storage.exports')
local exports = vexports.compile(vexports.log[#vexports.log])
vexports.deploy_funcs(exports)
end
Expand Down
5 changes: 4 additions & 1 deletion test/box-luatest/upgrade/2.11.0/vshard/storage-gen.lua
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ local names = {
}

-- Start the database with sharding
local vshard = require('vshard')
local ok, vshard = pcall(require, 'vshard-ee')
if not ok then
vshard = require('vshard')
end
vshard.storage.cfg(cfg, names[NAME])

box.once("testapp", function()
Expand Down
34 changes: 22 additions & 12 deletions test/config-luatest/vshard_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,17 @@ local helpers = require('test.config-luatest.helpers')

local g = helpers.group()

local has_vshard = pcall(require, 'vshard')
local has_vshard = pcall(require, 'vshard-ee')
if not has_vshard then
has_vshard = pcall(require, 'vshard')
end

local function skip_if_no_vshard()
t.skip_if(not has_vshard, 'Module "vshard-ee/vshard" is not available')
end

g.test_fixed_masters = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -258,7 +265,7 @@ g.test_fixed_masters = function(g)
end

g.test_rebalancer_role = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -422,7 +429,7 @@ g.test_rebalancer_role = function(g)
end

g.test_too_many_rebalancers = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -470,7 +477,7 @@ end
-- credentials sharding role.
--
g.test_no_sharding_credentials_role_success = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
helpers.success_case(g, {
options = {
['credentials.users.storage.roles'] = {'sharding'},
Expand All @@ -494,7 +501,7 @@ g.test_no_sharding_credentials_role_success = function(g)
end

g.test_no_sharding_credentials_role_error = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -536,7 +543,7 @@ end
-- credentials, its credential sharding role is not checked.
--
g.test_no_storage_user = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
helpers.success_case(g, {
options = {
['sharding.roles'] = {'storage', 'router'},
Expand All @@ -551,7 +558,7 @@ end

-- Make sure that the credential sharding role has all necessary credentials.
g.test_sharding_credentials_role = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -594,7 +601,10 @@ g.test_sharding_credentials_role = function(g)
local role = box.space._user.index.name:get('sharding')
local repl_id = box.space._user.index.name:get('replication').id
t.assert(role ~= nil)
local vexports = require('vshard.storage.exports')
local ok, vexports = pcall(require, 'vshard-ee.storage.exports')
if not ok then
vexports = require('vshard.storage.exports')
end
local exports = vexports.compile(vexports.log[#vexports.log])

-- The role should have the necessary privileges.
Expand All @@ -618,7 +628,7 @@ g.test_sharding_credentials_role = function(g)
end

g.test_no_suitable_uri = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -656,7 +666,7 @@ end
-- Make sure that rebalancing will be disabled if rebalancer_mode == 'off', even
-- if rebalancer sharding role is assigned.
g.test_rebalancer_mode = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down Expand Up @@ -708,7 +718,7 @@ end
-- Make sure the shrading.weight configuration parameter is set
-- correctly in vshard.
g.test_weight = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
skip_if_no_vshard()
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
Expand Down
7 changes: 5 additions & 2 deletions test/config-luatest/vshard_upgrade_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ local fio = require('fio')

local g = t.group()

local has_vshard = pcall(require, 'vshard')
local has_vshard = pcall(require, 'vshard-ee')
if not has_vshard then
has_vshard = pcall(require, 'vshard')
end

--
-- Test, that Tarantool upgrade with vshard happens without downtime:
Expand All @@ -20,7 +23,7 @@ local has_vshard = pcall(require, 'vshard')
-- 6. Vshard works after all names are applied.
--
g.before_all(function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
t.skip_if(not has_vshard, 'Module "vshard-ee/vshard" is not available')
treegen.init(g)
local uuids = {
['rs-001'] = 'cbf06940-0790-498b-948d-042b62cf3d29',
Expand Down

0 comments on commit 29519c7

Please sign in to comment.