From a7aec3225c0a555d5a7a7d99c8f2e376c8c82021 Mon Sep 17 00:00:00 2001 From: Mikhail Fomenko Date: Thu, 12 Dec 2024 13:40:55 +0300 Subject: [PATCH 1/3] roles: fix launch on ro instance with is_master_only = true --- CHANGELOG.md | 2 ++ roles/expirationd.lua | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 397c402..e641c1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### 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. diff --git a/roles/expirationd.lua b/roles/expirationd.lua index cfb38bb..52f94cf 100644 --- a/roles/expirationd.lua +++ b/roles/expirationd.lua @@ -248,7 +248,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 From 6dfe5fb991bfa0c2322dc487adee14853b88917a Mon Sep 17 00:00:00 2001 From: Mikhail Fomenko Date: Fri, 13 Dec 2024 11:41:44 +0300 Subject: [PATCH 2/3] roles: role configuration depending on tarantool version --- CHANGELOG.md | 2 ++ roles/expirationd.lua | 84 ++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e641c1d..7a52232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added +- Role configuration depending on tarantool version + ### Changed ### Fixed diff --git a/roles/expirationd.lua b/roles/expirationd.lua index 52f94cf..d707305 100644 --- a/roles/expirationd.lua +++ b/roles/expirationd.lua @@ -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 @@ -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.3.0') + end -- Finishes tasks from an old configuration for i = #started, 1, -1 do local task_name = started[i] @@ -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 + From 1398fdc6e35654d2f26f0b2ad27750f99467c575 Mon Sep 17 00:00:00 2001 From: Mikhail Fomenko Date: Mon, 23 Dec 2024 09:17:52 +0300 Subject: [PATCH 3/3] roles: fixed error text --- roles/expirationd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/roles/expirationd.lua b/roles/expirationd.lua index d707305..f5fe0ef 100644 --- a/roles/expirationd.lua +++ b/roles/expirationd.lua @@ -298,7 +298,7 @@ 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.3.0') + 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