Skip to content

Commit

Permalink
Fix box.ctl.promote error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Dec 19, 2024
1 parent 7046671 commit f6f7c91
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ Unreleased
[2.13.0] - 2024-11-28
-------------------------------------------------------------------------------

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Fixed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

- Errors from ``box.ctl.promote`` and ``box.ctl.demote`` now are logged.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Changed
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
58 changes: 48 additions & 10 deletions cartridge/failover.lua
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,12 @@ local function synchro_promote()
and not vars.failover_suppressed
and box.ctl.promote ~= nil
then
local err = box.ctl.promote()
if err ~= nil then
local ok, err = pcall(box.ctl.promote)
fiber.testcancel()
if ok ~= true then
log.error('Failed to promote: %s', err)
end
return err
end
end

Expand All @@ -443,10 +445,12 @@ local function synchro_demote()
and box_info.synchro.queue.owner ~= 0
and box_info.synchro.queue.owner == box_info.id
and box.ctl.demote ~= nil then
local err = box.ctl.demote()
if err ~= nil then
local ok, err = pcall(box.ctl.demote)
fiber.testcancel()
if ok ~= true then
log.error('Failed to demote: %s', err)
end
return err
end
end

Expand Down Expand Up @@ -614,7 +618,10 @@ function reconfigure_all(active_leaders)
box.cfg({
read_only = not vars.cache.is_rw,
})
synchro_promote()
err = synchro_promote()
if err ~= nil then
error(err)
end

local state = 'RolesConfigured'
for _, role_name in ipairs(vars.all_roles) do
Expand Down Expand Up @@ -786,11 +793,23 @@ local function cfg(clusterwide_config, opts)

-- disable raft if it was enabled
if vars.mode == 'raft' and failover_cfg.mode ~= 'raft' then
raft_failover.disable()
local err = raft_failover.disable()
if err ~= nil then
ApplyConfigError:new(
'Unable to disable Raft failover: %q',
err
)
end
end

if vars.mode == 'stateful' and failover_cfg.mode ~= 'stateful' and failover_cfg.mode ~= 'raft' then
synchro_demote()
local err = synchro_demote()
if err ~= nil then
ApplyConfigError:new(
'Unable to demote: %q',
err
)
end
end

if failover_cfg.mode == 'disabled' then
Expand Down Expand Up @@ -819,12 +838,25 @@ local function cfg(clusterwide_config, opts)
-- Replicasets with all_rw flag imply that
-- consistent switchover isn't necessary
vars.consistency_needed = false
synchro_demote()
local err = synchro_demote()
if err ~= nil then
ApplyConfigError:new(
'Unable to demote: %q',
err
)
end

elseif #topology.get_leaders_order(topology_cfg, replicaset_uuid, nil) == 1 then
-- Replicaset consists of a single server
-- consistent switchover isn't necessary
vars.consistency_needed = false
synchro_demote()
local err = synchro_demote()
if err ~= nil then
ApplyConfigError:new(
'Unable to demote: %q',
err
)
end
else
vars.consistency_needed = true
end
Expand Down Expand Up @@ -975,7 +1007,13 @@ local function cfg(clusterwide_config, opts)
})

vars.mode = failover_cfg.mode
synchro_promote()
err = synchro_promote()
if err ~= nil then
ApplyConfigError:new(
'Unable to promote: %q',
err
)
end

return true
end
Expand Down
3 changes: 2 additions & 1 deletion cartridge/failover/raft.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ local function disable()
and box_info.synchro.queue ~= nil
and box_info.synchro.queue.owner ~= 0
and box_info.synchro.queue.owner == box_info.id then
local err = box.ctl.demote()
local err = pcall(box.ctl.demote)
if err ~= nil then
log.error('Failed to demote: %s', err)
end
return err
end
end

Expand Down

0 comments on commit f6f7c91

Please sign in to comment.