Skip to content

[core] Improve the workflow finding Redis leader. - #34108

Merged
fishbone merged 9 commits into
ray-project:masterfrom
fishbone:better-find-leader
Apr 7, 2023
Merged

fishbone merged 9 commits into
ray-project:masterfrom
fishbone:better-find-leader

Conversation

@fishbone

@fishbone fishbone commented Apr 5, 2023 •

Copy link
Copy Markdown
Contributor

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:

  • 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

Related issue number

Checks

fishbone added 2 commits April 5, 2023 17:20
Signed-off-by: Yi Cheng <[email protected]>
Signed-off-by: Yi Cheng <[email protected]>
@fishbone fishbone linked an issue Apr 5, 2023 that may be closed by this pull request
@fishbone fishbone changed the title fix [core] Improve the workflow finding Redis leader. Apr 5, 2023
@fishbone
fishbone marked this pull request as ready for review April 5, 2023 23:48
@fishbone
fishbone requested a review from a team as a code owner April 5, 2023 23:48
@fishbone fishbone added release-blocker P0 Issue that blocks the release P0 Issues that should be fixed in short order Ray 2.4 labels Apr 5, 2023
fishbone added 2 commits April 6, 2023 04:07
Signed-off-by: Yi Cheng <[email protected]>
Signed-off-by: Yi Cheng <[email protected]>

@rkooo567 rkooo567 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Mostly nits

redisFreeSSLContext(ssl_context_);
ssl_context_ = nullptr;
}
redis_async_context_.reset();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just for the confirmation, this context is not used from other threads right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'll be used from other threads, but it's thread safe. (link)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need ConnectWithRetries in this case?

@fishbone fishbone Apr 6, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this means the master has been moved to this address? Can you comment that clearly here?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wondering if this message can change in the future, and is there a way for us to detect that?

Comment thread src/ray/gcs/redis_context.cc Outdated
int cluster_size = 0;

// Check the cluster status first
for (auto &part : parts) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto &part : parts) {
for (const auto &part : parts) {

nit


// Check the cluster status first
for (auto &part : parts) {
if (part.empty() || part[0] == '#') {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any way to test this method with real redis? Is it in CI test?

@fishbone fishbone Apr 6, 2023 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if it is possible, but can we improve the comment to add an action item in this case?

Comment thread src/ray/gcs/redis_context.cc Outdated

if (cluster_mode) {
RAY_CHECK(cluster_size == 1)
<< "Ray currently doesn't support sharded Redis cluster. "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<< "Ray currently doesn't support sharded Redis cluster. "
<< "The Redis cluster size is " << cluster_size << ". Ray currently doesn't support sharded Redis cluster. "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, 1 shard and for each shard you still can have multiple replicas.

}
}

std::vector<std::string> ResolveDNS(const std::string &address, int port) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment to use only the first ip address? Btw, when is the return value has size > 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying to make this method generic. I'll put comments in the caller side.

@fishbone

fishbone commented Apr 6, 2023

Copy link
Copy Markdown
Contributor Author

@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.
If it's not the leader, we'll get MOVED error and the right leader will be put in the msg.

Redis can have multiple shards and each shard can have several replicas. Right now, we only support 1 shard the whole redis cluster.

fishbone added 2 commits April 6, 2023 17:53
Signed-off-by: Yi Cheng <[email protected]>
@rkooo567

rkooo567 commented Apr 7, 2023

Copy link
Copy Markdown
Contributor

@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.
If it's not the leader, we'll get MOVED error and the right leader will be put in the msg.

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:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rkooo567 comments has been added here.

@fishbone
fishbone merged commit a1a6902 into ray-project:master Apr 7, 2023
@fishbone
fishbone deleted the better-find-leader branch April 7, 2023 19:58
fishbone added a commit to fishbone/ray that referenced this pull request Apr 10, 2023
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
clarng pushed a commit that referenced this pull request Apr 11, 2023
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
elliottower pushed a commit to elliottower/ray that referenced this pull request Apr 22, 2023
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]>
ProjectsByJackHe pushed a commit to ProjectsByJackHe/ray that referenced this pull request May 4, 2023
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 Issues that should be fixed in short order release-blocker P0 Issue that blocks the release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Core] Better handling of redis errors

4 participants