Skip to content
Snippets Groups Projects
Unverified Commit 4ad4d472 authored by Sergey V's avatar Sergey V
Browse files

refactor: address the review comments

parent ffeefe7e
No related branches found
No related tags found
No related merge requests found
......@@ -369,7 +369,6 @@ fn start_discover(args: &args::Run, to_supervisor: ipc::Sender<IpcMessage>) {
tarantool::set_cfg(&cfg);
traft::Storage::init_schema();
traft::Storage::persist_cluster_id(&args.cluster_id).unwrap();
discovery::init_global(&args.peers);
init_handlers();
......@@ -524,6 +523,8 @@ fn start_join(args: &args::Run, leader_address: String) {
})
.unwrap();
traft::Storage::persist_cluster_id(&args.cluster_id).unwrap();
postjoin(args)
}
......
......@@ -49,8 +49,11 @@ pub enum Error {
#[error("{0}")]
Raft(#[from] RaftError),
/// cluster_id of the joining peer mismatches the cluster_id of the cluster
#[error("cluster_id mismatches the cluster_id of the cluster")]
ClusterIdMismatch,
#[error("cannot join instance to the cluster: cluster_id mismatch: cluster_id of the instance = {instance_cluster_id:?}, cluster_id of the cluster = {cluster_cluster_id:?}")]
ClusterIdMismatch {
instance_cluster_id: String,
cluster_cluster_id: String,
},
}
#[derive(Clone, Debug, tlua::Push, tlua::PushInto)]
......@@ -714,7 +717,10 @@ fn raft_join(req: JoinRequest) -> Result<JoinResponse, Box<dyn StdError>> {
let cluster_id = Storage::cluster_id()?.ok_or("cluster_id is not set yet")?;
if req.cluster_id != cluster_id {
return Err(Box::new(Error::ClusterIdMismatch));
return Err(Box::new(Error::ClusterIdMismatch {
instance_cluster_id: req.cluster_id,
cluster_cluster_id: cluster_id,
}));
}
let instance_id = req.instance_id.clone();
......
from functools import partial
import os
import errno
import signal
......@@ -64,27 +65,11 @@ def test_concurrency(cluster2: Cluster):
# Subsequent requests get batched
executor = ThreadPoolExecutor()
f1 = executor.submit(
raft_join,
peer=i1,
cluster_id=cluster2.id,
instance_id="fake-1",
timeout_seconds=5,
)
f2 = executor.submit(
raft_join,
peer=i1,
cluster_id=cluster2.id,
instance_id="fake-2",
timeout_seconds=5,
)
f3 = executor.submit(
raft_join,
peer=i1,
cluster_id=cluster2.id,
instance_id="fake-3",
timeout_seconds=0.1,
)
submit_join = partial(executor.submit, raft_join, peer=i1, cluster_id=cluster2.id)
f1 = submit_join(instance_id="fake-1", timeout_seconds=5)
f2 = submit_join(instance_id="fake-2", timeout_seconds=5)
f3 = submit_join(instance_id="fake-3", timeout_seconds=0.1)
# Make sure all requests reach the server before resuming i2.
with pytest.raises(OSError) as e1:
......@@ -232,7 +217,10 @@ def test_cluster_id_mismatch(instance: Instance):
assert wrong_cluster_id != instance.cluster_id
with pytest.raises(
TarantoolError, match="cluster_id mismatches the cluster_id of the cluster"
TarantoolError,
match="cluster_id mismatch:"
' cluster_id of the instance = "wrong-cluster-id",'
' cluster_id of the cluster = "cluster-[^"]+"',
):
raft_join(
peer=instance,
......
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