Skip to content
Snippets Groups Projects
Commit 298d5d40 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon: Committed by Yaroslav Dynnikov
Browse files

fix: used to panic during shut down when leader id is None

parent 3066a6b6
No related branches found
No related tags found
1 merge request!205Fix/panic in on shutdown
Pipeline #9999 passed
...@@ -720,10 +720,6 @@ fn postjoin(args: &args::Run) { ...@@ -720,10 +720,6 @@ fn postjoin(args: &args::Run) {
box_cfg.listen = Some(args.listen.clone()); box_cfg.listen = Some(args.listen.clone());
tarantool::set_cfg(&box_cfg); tarantool::set_cfg(&box_cfg);
if let Err(e) = tarantool::on_shutdown(traft::failover::on_shutdown) {
tlog!(Error, "failed setting on_shutdown trigger: {e}");
}
tlog!(Debug, "Getting a read barrier..."); tlog!(Debug, "Getting a read barrier...");
loop { loop {
if node.status().leader_id == None { if node.status().leader_id == None {
...@@ -746,6 +742,10 @@ fn postjoin(args: &args::Run) { ...@@ -746,6 +742,10 @@ fn postjoin(args: &args::Run) {
} }
tlog!(Info, "Read barrier aquired, raft is ready"); tlog!(Info, "Read barrier aquired, raft is ready");
if let Err(e) = tarantool::on_shutdown(traft::failover::on_shutdown) {
tlog!(Error, "failed setting on_shutdown trigger: {e}");
}
let peer = traft::Storage::peer_by_raft_id(raft_id).unwrap().unwrap(); let peer = traft::Storage::peer_by_raft_id(raft_id).unwrap().unwrap();
box_cfg.replication = traft::Storage::box_replication(&peer.replicaset_id, None).unwrap(); box_cfg.replication = traft::Storage::box_replication(&peer.replicaset_id, None).unwrap();
tarantool::set_cfg(&box_cfg); tarantool::set_cfg(&box_cfg);
......
...@@ -2,6 +2,7 @@ use std::time::{Duration, Instant}; ...@@ -2,6 +2,7 @@ use std::time::{Duration, Instant};
use ::tarantool::fiber::sleep; use ::tarantool::fiber::sleep;
use ::tarantool::proc; use ::tarantool::proc;
use ::tarantool::unwrap_or;
use crate::{stringify_cfunc, tarantool, tlog}; use crate::{stringify_cfunc, tarantool, tlog};
...@@ -33,8 +34,11 @@ pub fn on_shutdown() { ...@@ -33,8 +34,11 @@ pub fn on_shutdown() {
// will run until we get successfully deactivate or tarantool shuts down // will run until we get successfully deactivate or tarantool shuts down
// the on_shutdown fiber (after 3 secs) // the on_shutdown fiber (after 3 secs)
loop { loop {
let status = node::global().unwrap().status(); let node = node::global().unwrap();
let leader_id = status.leader_id.expect("leader_id deinitialized"); let leader_id = unwrap_or!(node.status().leader_id, {
node.wait_status();
continue;
});
let leader = Storage::peer_by_raft_id(leader_id).unwrap().unwrap(); let leader = Storage::peer_by_raft_id(leader_id).unwrap().unwrap();
let wait_before_retry = Duration::from_millis(300); let wait_before_retry = Duration::from_millis(300);
let now = Instant::now(); let now = Instant::now();
......
import funcy # type: ignore import funcy # type: ignore
import pytest import pytest
from conftest import Cluster, Instance from conftest import Cluster, Instance
from time import sleep
@funcy.retry(tries=20, timeout=0.1) @funcy.retry(tries=20, timeout=0.1)
...@@ -179,3 +180,20 @@ def test_deactivation(cluster2: Cluster): ...@@ -179,3 +180,20 @@ def test_deactivation(cluster2: Cluster):
assert raft_update_peer(i2, target=i2, is_active=True) == [{}] assert raft_update_peer(i2, target=i2, is_active=True) == [{}]
assert raft_update_peer(i2, target=i2, is_active=True) == [{}] assert raft_update_peer(i2, target=i2, is_active=True) == [{}]
def test_gl119_panic_in_on_shutdown(cluster2: Cluster):
i1, i2 = cluster2.instances
i2.call("picolib.raft_timeout_now", timeout=0.01)
assert i2.terminate() == 0
# second instance terminates first, so it becomes a follower
i2.terminate()
# terminate the leader, so the follower can't acquire the read barrier
i1.terminate()
i2.start()
# wait for the follower to start acquiring the read barrier
sleep(1)
assert i2.terminate() == 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment