Skip to content
Snippets Groups Projects
Commit 3ec6769a authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon:
Browse files

refactor: pico.raft_timeout_now -> .proc_raft_promote

parent 756f790d
Branches
Tags
1 merge request!855Gmoshkin/service auth
......@@ -695,46 +695,6 @@ pub(crate) fn setup(args: &args::Run) {
),
);
///////////////////////////////////////////////////////////////////////////
luamod_set(
&l,
"raft_timeout_now",
indoc! {"
pico.raft_timeout_now()
=======================
Internal API. Causes this instance to artificially timeout on waiting
for a heartbeat from raft leader. The instance then will start a new
election and transition to a 'PreCandidate' state.
This function yields. It returns when the raft node changes it's state.
Later the instance will likely become a leader, unless there are some
impediments, e.g. the loss of quorum or split-vote.
Example log:
received MsgTimeoutNow from 3 and starts an election
to get leadership., from: 3, term: 4, raft_id: 3
starting a new election, term: 4, raft_id: 3
became candidate at term 5, term: 5, raft_id: 3
broadcasting vote request, to: [4, 1], log_index: 54,
log_term: 4, term: 5, type: MsgRequestVote, raft_id: 3
received votes response, term: 5, type: MsgRequestVoteResponse,
approvals: 2, rejections: 0, from: 4, vote: true, raft_id: 3
became leader at term 5, term: 5, raft_id: 3
"},
tlua::function0(|| -> traft::Result<()> {
traft::node::global()?.timeout_now();
Ok(())
}),
);
///////////////////////////////////////////////////////////////////////////
#[rustfmt::skip]
luamod_set(
......
......@@ -1994,3 +1994,36 @@ fn proc_raft_interact(pbs: Vec<traft::MessagePb>) -> traft::Result<()> {
}
Ok(())
}
/// Internal API. Causes this instance to artificially timeout on waiting
/// for a heartbeat from raft leader. The instance then will start a new
/// election and transition to a 'PreCandidate' state.
///
/// This function yields. It returns when the raft node changes it's state.
///
/// Later the instance will likely become a leader, unless there are some
/// impediments, e.g. the loss of quorum or split-vote.
///
/// Example log:
/// ```ignore
/// received MsgTimeoutNow from 3 and starts an election
/// to get leadership., from: 3, term: 4, raft_id: 3
///
/// starting a new election, term: 4, raft_id: 3
///
/// became candidate at term 5, term: 5, raft_id: 3
///
/// broadcasting vote request, to: [4, 1], log_index: 54,
/// log_term: 4, term: 5, type: MsgRequestVote, raft_id: 3
///
/// received votes response, term: 5, type: MsgRequestVoteResponse,
/// approvals: 2, rejections: 0, from: 4, vote: true, raft_id: 3
///
/// became leader at term 5, term: 5, raft_id: 3
/// ```
#[proc(public = false)]
fn proc_raft_promote() -> traft::Result<()> {
let node = global()?;
node.timeout_now();
Ok(())
}
......@@ -1139,7 +1139,7 @@ class Instance:
eprint(f"{self} is trying to become a leader, {attempt=}")
# 1. Force the node to campaign.
self.call("pico.raft_timeout_now")
self.call(".proc_raft_promote")
# 2. Wait until the miracle occurs.
Retriable(timeout, rps).call(self.assert_raft_status, "Leader")
......
......@@ -97,7 +97,7 @@ def test_restart_both(cluster2: Cluster):
Retriable(timeout=2, rps=10).call(check_alive, i2)
# Speed up elections
i2.call("pico.raft_timeout_now")
i2.promote_or_fail()
i1.wait_online()
assert i1.current_grade() == dict(variant="Online", incarnation=2)
......
......@@ -36,7 +36,7 @@ def test_gl119_panic_on_shutdown(cluster2: Cluster):
# suspend i1 (leader) and force i2 to start a new term
assert i1.process is not None
os.killpg(i1.process.pid, signal.SIGSTOP)
i2.call("pico.raft_timeout_now")
i2.call(".proc_raft_promote")
# it can't win the election because there is no quorum
i2.assert_raft_status("Candidate")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment