Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
raft: make promote bump term and vote at once
box.ctl.promote() was implemented as follows: an instance bumps the term and marks itself a candidate, but doesn't vote for self immediately. Instead it relies on the machinery which makes a candidate vote for self as soon as it persists a new term. This differs from a normal election start due to leader timeout: there term and vote are bumped at once. Besides, this increases probability of box.ctl.promote() resulting in other node getting elected: if a node first broadcasts a term without a vote, it is not considered a candidate, so other candidates might start elections and vote for themselves. Let's bring promote into line with automatic elections. Closes #8497 NO_DOC=bugfix (cherry picked from commit 1737121)
- Loading branch information
1 parent
657e3f9
commit 27c550c
Showing
7 changed files
with
70 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
## bugfix/replication | ||
|
||
* Fixed a possible failure to promote the desired node by `box.ctl.promote()` on | ||
a cluster with nodes configured with `election_mode = "candidate"` (gh-8497). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
local t = require('luatest') | ||
local server = require('luatest.server') | ||
local replica_set = require('luatest.replica_set') | ||
|
||
local g = t.group('gh-8497-atomic-promote') | ||
|
||
g.before_each(function(cg) | ||
t.tarantool.skip_if_not_debug() | ||
cg.replica_set = replica_set:new({}) | ||
cg.box_cfg = { | ||
replication_timeout = 0.1, | ||
replication = { | ||
server.build_listen_uri('server1', cg.replica_set.id), | ||
server.build_listen_uri('server2', cg.replica_set.id), | ||
}, | ||
} | ||
cg.box_cfg.election_mode = 'candidate' | ||
cg.server1 = cg.replica_set:build_and_add_server{ | ||
alias = 'server1', | ||
box_cfg = cg.box_cfg, | ||
} | ||
cg.box_cfg.election_mode = 'voter' | ||
cg.server2 = cg.replica_set:build_and_add_server{ | ||
alias = 'server2', | ||
box_cfg = cg.box_cfg, | ||
} | ||
cg.replica_set:start() | ||
cg.replica_set:wait_for_fullmesh() | ||
cg.server1:wait_for_election_leader() | ||
end) | ||
|
||
g.after_each(function(cg) | ||
cg.replica_set:drop() | ||
end) | ||
|
||
g.test_election_promote_finishes_in_one_term = function(cg) | ||
cg.server2:update_box_cfg{election_mode = 'candidate'} | ||
local term = cg.server1:get_election_term() | ||
t.assert_equals(term, cg.server2:get_election_term(), | ||
'The cluster is stable') | ||
local ok, err = cg.server2:exec(function() | ||
local fiber = require('fiber') | ||
box.error.injection.set('ERRINJ_WAL_DELAY_COUNTDOWN', 1) | ||
local fib = fiber.new(box.ctl.promote) | ||
fib:set_joinable(true) | ||
fiber.sleep(2 * box.cfg.replication_timeout) | ||
box.error.injection.set('ERRINJ_WAL_DELAY', false) | ||
return fib:join() | ||
end) | ||
t.assert_equals({ok, err}, {true, nil}, 'No error in promote') | ||
cg.server2:wait_for_election_leader() | ||
t.assert_equals(term + 1, cg.server1:get_election_term(), | ||
'The term is bumped once') | ||
t.assert_equals(term + 1, cg.server2:get_election_term(), | ||
'The term is bumped once') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters