Repository navigation
[core] Improve the workflow finding Redis leader. - #34108
Conversation
Signed-off-by: Yi Cheng <[email protected]>
Signed-off-by: Yi Cheng <[email protected]>
Signed-off-by: Yi Cheng <[email protected]>
Signed-off-by: Yi Cheng <[email protected]>
| redisFreeSSLContext(ssl_context_); | ||
| ssl_context_ = nullptr; | ||
| } | ||
| redis_async_context_.reset(); |
There was a problem hiding this comment.
just for the confirmation, this context is not used from other threads right?
There was a problem hiding this comment.
it'll be used from other threads, but it's thread safe. (link)
There was a problem hiding this comment.
So for other code path, they all handle nullptr redis_async_context_ right?
|
|
||
| Disconnect(); | ||
| // Connect to the true leader. | ||
| return Connect(ip_port[0], std::stoi(ip_port[1]), sharding, password, enable_ssl); |
There was a problem hiding this comment.
We don't need ConnectWithRetries in this case?
There was a problem hiding this comment.
We need this to prevent any ephemeral errors.
|
|
||
| if (redis_reply->type == REDIS_REPLY_ERROR) { | ||
| // This should be a MOVED error | ||
| // MOVED 14946 10.xx.xx.xx:7001 |
There was a problem hiding this comment.
this means the master has been moved to this address? Can you comment that clearly here?
There was a problem hiding this comment.
wondering if this message can change in the future, and is there a way for us to detect that?
| int cluster_size = 0; | ||
|
|
||
| // Check the cluster status first | ||
| for (auto &part : parts) { |
There was a problem hiding this comment.
| for (auto &part : parts) { | |
| for (const auto &part : parts) { |
nit
|
|
||
| // Check the cluster status first | ||
| for (auto &part : parts) { | ||
| if (part.empty() || part[0] == '#') { |
There was a problem hiding this comment.
Is there any way to test this method with real redis? Is it in CI test?
There was a problem hiding this comment.
We have redis e2e test (ci) for this one. We tested the system with cluster mode redis and also non-cluster redis with multiple replicas.
| cluster_mode = true; | ||
| } else if (kv[1] == "fail") { | ||
| RAY_LOG(FATAL) | ||
| << "The Redis cluster is not healthy. cluster_state shows failed status: " |
There was a problem hiding this comment.
Not sure if it is possible, but can we improve the comment to add an action item in this case?
|
|
||
| if (cluster_mode) { | ||
| RAY_CHECK(cluster_size == 1) | ||
| << "Ray currently doesn't support sharded Redis cluster. " |
There was a problem hiding this comment.
| << "Ray currently doesn't support sharded Redis cluster. " | |
| << "The Redis cluster size is " << cluster_size << ". Ray currently doesn't support sharded Redis cluster. " |
There was a problem hiding this comment.
Maybe I am ignorant in Redis, but "not supporting shared cluster, and provide cluster with 1 shard" sounds contradicting. Does this mean we can have only 1 shard cluster? (master + 1 shard)
There was a problem hiding this comment.
Oh, 1 shard and for each shard you still can have multiple replicas.
| } | ||
| } | ||
|
|
||
| std::vector<std::string> ResolveDNS(const std::string &address, int port) { |
There was a problem hiding this comment.
comment to use only the first ip address? Btw, when is the return value has size > 1?
There was a problem hiding this comment.
Trying to make this method generic. I'll put comments in the caller side.
|
@rkooo567 sometimes the user will pass a domain name, for example, MemoryDB it provides a domain name. You'll get several ip address behind that. Some are replicas and some are the leader of the shard. If the first connection connects to the leader, it's OK and otherwise, we need to switch to the leader. Redis can have multiple shards and each shard can have several replicas. Right now, we only support 1 shard the whole redis cluster. |
Signed-off-by: Yi Cheng <[email protected]>
Make sense. It'd be great to add this comment to the code! |
| bool sharding, | ||
| const std::string &password, | ||
| bool enable_ssl) { | ||
| // Connect to the leader of the Redis cluster: |
The current way of finding Redis leader sometimes giving error information. The main reason is because the ip address is not resolved.
If in the initialization stage, it connect to the master, it'll use passed in address as the leader which later might make Ray pick follower redis.
This PR fixed the issue and also uses the way redis-cli used to pick the leader.
The PR makes the checking more strict to give better error message. New protocol as below:
- use boost to resolve the ip address from domain name.
- connect to the first ip address
- if it's cluster mode,
- make sure it's healthy; make sure only 1 shard
- send a dummy write and check the return
- if return OK, use the ip address directly
- otherwise, use the one mentioned in the error message
- if not cluster mode, just use the ip address
Refactoring is also done in this PR. Moving connection related information to redis context
The current way of finding Redis leader sometimes giving error information. The main reason is because the ip address is not resolved.
If in the initialization stage, it connect to the master, it'll use passed in address as the leader which later might make Ray pick follower redis.
This PR fixed the issue and also uses the way redis-cli used to pick the leader.
The PR makes the checking more strict to give better error message. New protocol as below:
- use boost to resolve the ip address from domain name.
- connect to the first ip address
- if it's cluster mode,
- make sure it's healthy; make sure only 1 shard
- send a dummy write and check the return
- if return OK, use the ip address directly
- otherwise, use the one mentioned in the error message
- if not cluster mode, just use the ip address
Refactoring is also done in this PR. Moving connection related information to redis context
The current way of finding Redis leader sometimes giving error information. The main reason is because the ip address is not resolved.
If in the initialization stage, it connect to the master, it'll use passed in address as the leader which later might make Ray pick follower redis.
This PR fixed the issue and also uses the way redis-cli used to pick the leader.
The PR makes the checking more strict to give better error message. New protocol as below:
- use boost to resolve the ip address from domain name.
- connect to the first ip address
- if it's cluster mode,
- make sure it's healthy; make sure only 1 shard
- send a dummy write and check the return
- if return OK, use the ip address directly
- otherwise, use the one mentioned in the error message
- if not cluster mode, just use the ip address
Refactoring is also done in this PR. Moving connection related information to redis context
Signed-off-by: elliottower <[email protected]>
The current way of finding Redis leader sometimes giving error information. The main reason is because the ip address is not resolved.
If in the initialization stage, it connect to the master, it'll use passed in address as the leader which later might make Ray pick follower redis.
This PR fixed the issue and also uses the way redis-cli used to pick the leader.
The PR makes the checking more strict to give better error message. New protocol as below:
- use boost to resolve the ip address from domain name.
- connect to the first ip address
- if it's cluster mode,
- make sure it's healthy; make sure only 1 shard
- send a dummy write and check the return
- if return OK, use the ip address directly
- otherwise, use the one mentioned in the error message
- if not cluster mode, just use the ip address
Refactoring is also done in this PR. Moving connection related information to redis context
Signed-off-by: Jack He <[email protected]>
Signed-off-by: Yi Cheng [email protected]
Why are these changes needed?
The current way of finding Redis leader sometimes giving error information. The main reason is because the ip address is not resolved.
If in the initialization stage, it connect to the master, it'll use passed in address as the leader which later might make Ray pick follower redis.
This PR fixed the issue and also uses the way redis-cli used to pick the leader.
The PR makes the checking more strict to give better error message. New protocol as below:
Refactoring is also done in this PR. Moving connection related information to redis context
Related issue number
Checks
git commit -s) in this PR.scripts/format.shto lint the changes in this PR.method in Tune, I've added it in
doc/source/tune/api/under thecorresponding
.rstfile.