Skip to content
Snippets Groups Projects
Commit 0c9b0c97 authored by Georgy Moshkin's avatar Georgy Moshkin :speech_balloon: Committed by Dmitry Ivanov
Browse files

fix: used to fail sending RPC requests if replicaset consisted of 1 instance

parent a413b2f4
No related branches found
No related tags found
1 merge request!1412Gmoshkin/fix plugin rpc bug
......@@ -388,11 +388,14 @@ fn resolve_rpc_target(
}
};
let mut skipped_self = false;
// XXX: this shouldn't be a problem if replicasets aren't too big,
// but if they are we might want to construct a HashSet from candidates
for instance_name in replicas {
if my_instance_name == instance_name && candidates.len() > 1 {
if my_instance_name == instance_name {
// Prefer someone else instead of self
skipped_self = true;
continue;
}
if all_instances_with_service.contains(&instance_name) {
......@@ -400,6 +403,11 @@ fn resolve_rpc_target(
}
}
// In case there's no other suitable candidates, fallback to calling self
if skipped_self && all_instances_with_service.contains(&my_instance_name) {
return Ok(my_instance_name);
}
#[rustfmt::skip]
return Err(BoxError::new(ErrorCode::ServiceNotAvailable, format!("no {replicaset_uuid} replicas are available for service {ident}.{service}")).into());
} else {
......
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