Skip to content

roles: fix launch on ro instance with is_master_only = true #171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Added

- Role configuration depending on tarantool version

### Changed

### Fixed

- Fix launch on ro instance with is_master_only = true

## 1.6.0 - 2024-03-25

The release introduces a role for Tarantool 3.0.
Expand Down
86 changes: 80 additions & 6 deletions roles/expirationd.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ local role_name = "roles.expirationd"
local started = {}


local function pars_tarantool_version()
local version = rawget(_G, "_TARANTOOL"):split('-', 1)[1]
local major_minor_patch = version:split('.', 2)
local result = {
major = tonumber(major_minor_patch[1]),
minor = tonumber(major_minor_patch[2]),
patch = tonumber(major_minor_patch[3])
}
return result
end


local tarantool_version = pars_tarantool_version()


local function load_function(func_name)
if func_name == nil or type(func_name) ~= 'string' then
return nil
Expand Down Expand Up @@ -248,7 +263,7 @@ local function load_task(task_conf, task_name)

fiber.name(role_name .. ":" .. task_name)

local skip = task_conf.is_master_only and not box.info.ro
local skip = task_conf.is_master_only and box.info.ro
if skip then
return
end
Expand Down Expand Up @@ -281,6 +296,10 @@ local function load_task(task_conf, task_name)
end

local function apply_config(conf)
-- Check tarantool major version
if tarantool_version.major < 3 then
error('Tarantool version must be greater than or equal to 3.0.0')
end
-- Finishes tasks from an old configuration
for i = #started, 1, -1 do
local task_name = started[i]
Expand Down Expand Up @@ -317,8 +336,63 @@ local function stop()
end
end

return {
validate = validate_config,
apply = apply_config,
stop = stop,
}
local function on_event_3_3_0(config, key, value)
local role_conf = config:get('roles_cfg')[role_name]
if key == 'box.status' then
if value.is_ro then
for _, task_name in pairs(expirationd.tasks()) do
if role_conf[task_name].is_master_only then
local task = expirationd.task(task_name)
task:stop()
end
end
elseif #expirationd.tasks() == 0 then
apply_config(role_conf)
end
elseif key == 'config.apply' then
apply_config(role_conf)
end
end

local function on_event(config, key, value)
if key == 'box.status' then
if value.is_ro then
for _, task_name in pairs(expirationd.tasks()) do
if config[task_name].is_master_only then
local task = expirationd.task(task_name)
task:stop()
end
end
elseif #expirationd.tasks() == 0 then
apply_config(config)
end
elseif key == 'config.apply' then
apply_config(config)
end
end



if tarantool_version.minor <= 2 then
return {
validate = validate_config,
apply = apply_config,
stop = stop
}
elseif tarantool_version.minor == 3 and tarantool_version.patch == 0 then
return {
name = role_name,
validate = validate_config,
apply = apply_config,
stop = stop,
on_event = on_event_3_3_0
}
else
return {
validate = validate_config,
apply = apply_config,
stop = stop,
on_event = on_event
}
end