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

fix: used to fail sdk rpc in case target was self

parent ecc4e2c4
No related branches found
No related tags found
1 merge request!1282fix: used to fail sdk rpc in case target was self
Pipeline #51104 passed
......@@ -389,8 +389,8 @@ fn resolve_rpc_target(
// 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_id in replicas {
if my_instance_id == instance_id {
// Don't want to call self
if my_instance_id == instance_id && candidates.len() > 1 {
// Prefer someone else instead of self
continue;
}
if candidates.contains(&instance_id) {
......@@ -406,8 +406,8 @@ fn resolve_rpc_target(
// TODO: find a better strategy then just the random one
let random_index = rand::random::<usize>() % candidates.len();
let mut instance_id = std::mem::take(&mut candidates[random_index]);
if instance_id == my_instance_id {
// Don't want to call self
if instance_id == my_instance_id && candidates.len() > 1 {
// Prefer someone else instead of self
let index = (random_index + 1) % candidates.len();
instance_id = std::mem::take(&mut candidates[index]);
}
......
......@@ -2477,6 +2477,36 @@ cluster:
# TODO: check calling to poisoned service
def test_plugin_rpc_sdk_single_instance(cluster: Cluster):
i1 = cluster.add_instance(wait_online=True, init_replication_factor=1)
plugin_name = _PLUGIN_W_SDK
service_name = SERVICE_W_RPC
install_and_enable_plugin(i1, plugin_name, [service_name], migrate=True)
# Check sending request with `master = false` when there's ony one instance
context = make_context()
input = dict(
service_info=(plugin_name, service_name, _PLUGIN_VERSION_1),
path="/ping",
input="by-bucket-id",
bucket_id=13,
to_master=False,
)
i1.call(".proc_rpc_dispatch", "/proxy", msgpack.dumps(input), context)
# Check sending request with `master = false` when there's ony one instance
context = make_context()
input = dict(
service_info=(plugin_name, service_name, _PLUGIN_VERSION_1),
path="/ping",
input="by-replicaset-id",
replicaset_id=i1.call(".proc_instance_info")["replicaset_id"],
to_master=False,
)
i1.call(".proc_rpc_dispatch", "/proxy", msgpack.dumps(input), context)
def test_sdk_internal(cluster: Cluster):
[i1] = cluster.deploy(instance_count=1)
......
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