Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg-jukovec committed Apr 9, 2024
1 parent 35fabfe commit 13fe80d
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 31 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,15 @@ You need to install the Tarantool 3.0.2+ or 3.1+.
1. Add a dependency to your application rockspec.
2. Enable `roles.sharded-queue-router` role on all sharding `router` instances.
3. Enable `roles.sharded-queue-storage` role on all sharding `storage`
isntances.
instances.
4. Configure tubes for both roles.
5. Do not forget to bootstrap the vshard in your application. See
[router.lua][./router.lua] as an example.
[init.lua](./init.lua) as an example.

You could see a full example of the configuration in the [config.yaml][./config.yaml].
You could see a full example of the configuration in the [config.yaml](./config.yaml).

Be careful, it is unable to create or drop tubes dynamically by API calls
with Tarantool 3. You need to update the cluster configuration instead.
Be careful, it is impossible to create or drop tubes dynamically by API calls
with Tarantool 3. You need to update the role configuration instead.

## Usage in a Tarantool Cartridge application

Expand Down Expand Up @@ -184,8 +184,8 @@ Say:
```shell
make deps
make deps-cartridge # For Tarantool <3.
make deps-metrics # For Tarantool <3.
make deps-cartridge # For Tarantool < 3.
make deps-metrics # For Tarantool < 3.
make test
```
Expand Down Expand Up @@ -289,8 +289,8 @@ installed and the feature is not disabled by the configuration.
If you use **fifottl** driver (default), you can log driver's method calls with `log_request` (log router's and storage's operations).
* You could not to create or to drop tubes by API calls with Tarantool 3. You
need to update the cluster configuration instead.
* You can not create or drop tubes by API calls with Tarantool 3. You need
to update the role configuration instead.
[metrics-summary]: https://www.tarantool.io/en/doc/latest/book/monitoring/api_reference/#summary
[queue-statistics]: https://github.com/tarantool/queue?tab=readme-ov-file#getting-statistics
5 changes: 4 additions & 1 deletion roles/sharded-queue-router.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ local queue = require('sharded_queue.router.queue')
local role_name = "roles.sharded-queue-router"

local function validate(conf)
conf = conf or {}
if not roles.is_tarantool_role_supported() then
error(role_name .. ": the role is supported only for Tarantool 3.0.2 or newer")
end
if not roles.is_sharding_role_enabled('router') then
error(role_name .. ": instance must be a sharding router to use the role")
end

conf = conf or {}
local ok, err = utils.validate_tubes(conf.tubes or {}, false)
if not ok then
error(role_name .. ": " .. err)
Expand Down
6 changes: 4 additions & 2 deletions roles/sharded-queue-storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ local role_name = "roles.sharded-queue-storage"
local watcher = nil

local function validate(conf)
conf = conf or {}

if not roles.is_tarantool_role_supported() then
error(role_name .. ": the role is supported only for Tarantool 3.0.2 or newer")
end
if not roles.is_sharding_role_enabled('storage') then
error(role_name .. ": instance must be a sharding storage to use the role")
end

conf = conf or {}
local ok, err = utils.validate_tubes(conf.tubes or {}, true)
if not ok then
error(role_name .. ": " .. err)
Expand Down
12 changes: 12 additions & 0 deletions sharded_queue/roles.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
local config = require('config')
local errors = require('errors')
local utils = require('sharded_queue.utils')

local function is_sharding_role_enabled(expected)
local sharding_roles = config:get('sharding.roles')
Expand All @@ -10,6 +12,16 @@ local function is_sharding_role_enabled(expected)
return false
end

local function is_tarantool_role_supported()
local major, minor, patch = utils.get_tarantool_version()
if major <= 2
or major == 3 and minor == 0 and patch <= 1 then
return false
end
return true
end

return {
is_sharding_role_enabled = is_sharding_role_enabled,
is_tarantool_role_supported = is_tarantool_role_supported,
}
11 changes: 11 additions & 0 deletions sharded_queue/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -145,4 +145,15 @@ function utils.validate_cfg(cfg)
return true
end

function utils.get_tarantool_version()
local version_parts = rawget(_G, '_TARANTOOL'):split('-', 3)

local major_minor_patch_parts = version_parts[1]:split('.', 2)
local major = tonumber(major_minor_patch_parts[1])
local minor = tonumber(major_minor_patch_parts[2])
local patch = tonumber(major_minor_patch_parts[3])

return major, minor, patch
end

return utils
1 change: 0 additions & 1 deletion test/entrypoint/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ groups:
queue-router-1:
database:
instance_uuid: 'aaaaaaaa-aaaa-4000-b000-000000000002'
mode: rw
replicaset-002:
sharding:
roles: [storage]
Expand Down
7 changes: 0 additions & 7 deletions test/helper/config_cartridge.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ local config = {}
config.root = fio.dirname(fio.abspath(package.search('init')))

config.datadir = fio.pathjoin(config.root, 'dev')
config.unitdir = fio.pathjoin(config.datadir, 'unit')

config.cluster = cartridge_helpers.Cluster:new({
datadir = config.datadir,
Expand Down Expand Up @@ -119,12 +118,6 @@ t.before_suite(function()
for _, srv in pairs(config.cluster.servers) do
config.servers[srv.alias] = srv
end

fio.mktree(config.unitdir)
box.cfg{
work_dir=config.unitdir,
wal_mode='none'
}
end)

t.after_suite(function()
Expand Down
23 changes: 12 additions & 11 deletions test/helper/config_tarantool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ local roles = {
}
config.root = fio.dirname(fio.abspath(package.search('init')))
config.datadir = fio.pathjoin(config.root, 'dev')
config.unitdir = fio.pathjoin(config.datadir, 'unit')
config.configpath = fio.pathjoin(config.root, 'test', 'entrypoint', 'config.yml')
config.devconfigpath = fio.pathjoin(config.root, 'dev', 'config.yml')

Expand Down Expand Up @@ -43,8 +42,7 @@ function config.start_example_replicaset()
for _, srv in pairs(config.servers) do
srv:wait_until_ready()
end
config.servers['queue-router']:eval("require('vshard').router.bootstrap()")
config.servers['queue-router-1']:eval("require('vshard').router.bootstrap()")
config.bootstrap()
end

function config.stop_example_replicaset()
Expand All @@ -53,15 +51,24 @@ function config.stop_example_replicaset()
end
end

function config.bootstrap()
local routers = {
config.servers['queue-router'],
config.servers['queue-router-1'],
}
for _, router in ipairs(routers) do
router:eval("require('vshard').router.bootstrap({if_not_bootstrapped = true})")
end
end

function config.reload()
for _, srv in pairs(config.servers) do
srv:eval("require('config'):reload()")
end
for _, srv in pairs(config.servers) do
srv:wait_until_ready()
end
config.servers['queue-router']:eval("require('vshard').router.bootstrap()")
config.servers['queue-router-1']:eval("require('vshard').router.bootstrap()")
config.bootstrap()
end

local function read_config(path)
Expand Down Expand Up @@ -173,12 +180,6 @@ t.before_suite(function()
fio.pathjoin(config.datadir, 'sharded_queue'))

config.start_example_replicaset()

fio.mktree(config.unitdir)
box.cfg{
work_dir=config.unitdir,
wal_mode='none'
}
end)

t.after_suite(function()
Expand Down

0 comments on commit 13fe80d

Please sign in to comment.