Skip to content

Commit

Permalink
feat: support config.enforce_ro(true|false)
Browse files Browse the repository at this point in the history
  * This method is needed for autofailover mechanisms mainly to enforce
    read_only=true during loading phase of tarantool.

  Before this patch race condition existed between autofailover and
  moonlibs/config recovering behaviour.

  If master crashes but fastly restartes then it initiates long running
  loading phase. Master recovers as read_only=true but after returning
  from box.cfg moonlibs/config retrieves config from ETCD and rechecks
  read_only option.

  This lead to situation when autofailover may change ETCD configuration
  when master is about to leave loading phase but autofailover already
  confirmed that master is "loading".

  Having method config.enforce_ro it is now possible for external
  autofailover to firstly enforce_ro of loading master and then change
  ETCD configuration and promote other candidate fixing races and
  stabilizes FSM
  • Loading branch information
Vladislav Grubov committed Oct 3, 2023
1 parent 2568efb commit 44efeaf
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ local function etcd_load( M, etcd_conf, local_cfg )
" with replication:"..table.concat(cfg.box.replication,", "),
string.format("timeout: %s, quorum: %s, lag: %s",
cfg.box.replication_connect_timeout
or ('def:%s'):format(load_cfg.default_cfg.replication_connect_quorum or 30),
or ('def:%s'):format(load_cfg.default_cfg.replication_connect_timeout or 30),
cfg.box.replication_connect_quorum or 'def:full',
cfg.box.replication_sync_lag
or ('def:%s'):format(load_cfg.default_cfg.replication_sync_lag or 10)
Expand Down Expand Up @@ -751,6 +751,7 @@ end
---@field public _load_cfg table
---@field public _flat table
---@field public _fencing_f? Fiber
---@field public _enforced_ro? boolean
---@operator call(moonlibs.config.opts): moonlibs.config

---@type moonlibs.config
Expand Down Expand Up @@ -779,7 +780,20 @@ local M
return
end
end
end
end,
enforce_ro = function(enabler)
local previous = M._enforced_ro
if enabler == true then
M._enforced_ro = true
elseif enabler == false then
M._enforced_ro = false
end
return previous == M._enforced_ro, {
info_ro = box.info.ro,
cfg_ro = box.cfg.read_only,
_enforced_ro = M._enforced_ro,
}
end,
},{
---Reinitiates moonlibs.config
---@param args moonlibs.config.opts
Expand Down Expand Up @@ -1014,6 +1028,9 @@ local M
log.info("Reloading config after start")

local new_cfg = load_config()
if M._enforced_ro then
new_cfg.box.read_only = true
end
local diff_box = value_diff(cfg.box, new_cfg.box)

-- since load_config loads config also for reloading it removes non-dynamic options
Expand Down

0 comments on commit 44efeaf

Please sign in to comment.