Redis cluster read replica#7496
Conversation
Signed-off-by: Henry Yang <hyang@lyft.com>
Signed-off-by: Henry Yang <hyang@lyft.com>
|
@msukalski for first pass. /wait |
Signed-off-by: Henry Yang <hyang@lyft.com>
Signed-off-by: Henry Yang <hyang@lyft.com>
|
I'll take a look at this this weekend. |
msukalski
left a comment
There was a problem hiding this comment.
Overall, it looks pretty good at this stage.
| // defaults to 3ms. | ||
| google.protobuf.Duration buffer_flush_timeout = 5 [(gogoproto.stdduration) = true]; | ||
|
|
||
| // All ReadPolicy settings except MASTER may return stale data because replicas replication is |
There was a problem hiding this comment.
nit: "replicas" appears redundant.
| current = slot_array_; | ||
| // The slots is sorted, allowing for a quick comparison to make sure we need to update the slot | ||
| // array sort based on start and end to enable efficient comparison | ||
| sort(slots->begin(), slots->end(), [](const ClusterSlot& lhs, const ClusterSlot& rhs) -> bool { |
There was a problem hiding this comment.
It's not particularly clear whether this sort() is worth it. Mostly I don't see any ordering dependencies in this code that the sort() might alleviate. Your thoughts, please?
There was a problem hiding this comment.
The sort() is useful for the current_cluster_slot_ && *current_cluster_slot_ == *slots.
Let's say K(16384) slots are broken down to M ranges which are assigned to N shards(1 master + 0-n replicas). M and N should normally be < 100 except for the largest clusters.
If we sort the M ranges based on the start and end for each range, then the comparison of whether allocation is changed is O(M log M) + O(M) without allocating additional space. I can't be certain that "Cluster Slots" return a sorted range, as that's not part of the contract. If it does return a sorted range, the sort function is going to be O(M) in most implementations, then it's a small cost to pay.
| if (!shard->replicas_.healthyHosts().empty()) { | ||
| return chooseRandomHost(shard->replicas_, random_); | ||
| } else { | ||
| return chooseRandomHost(shard->all_hosts_, random_); |
There was a problem hiding this comment.
Is there a reason for the lack of symmetry with respect to PreferMaster? In other words, why does the no replicas available in this scenario not return shard->master_ instead of chooseRandomHost(shard->all_hosts_, random_)?
There was a problem hiding this comment.
by doing chooseRandomHost(shard->all_hosts_, random_) will make sure that we pick a random host if the master and replicas are all unhealthy. If only the master is healthy, then that's the host that will be picked.
| } | ||
| // Any connection to replica requires the READONLY command in order to perform read. | ||
| // Also the READONLY command is a no-opt for the master. | ||
| // We only need to send the READONLY command iff it's possible that the host is a replica. |
There was a problem hiding this comment.
I think this is a valid conclusion after looking at the redis 4 server code.
There was a problem hiding this comment.
Thanks for verifying
|
This pull request has been automatically marked as stale because it has not had activity in the last 7 days. It will be closed in 7 days if no further activity occurs. Please feel free to give a status update now, ping for review, or re-open when it's ready. Thank you for your contributions! |
…k status change. Signed-off-by: Henry Yang <hyang@lyft.com>
Signed-off-by: Henry Yang <hyang@lyft.com>
|
@envoyproxy/api-shepherds API LGTM |
Signed-off-by: Henry Yang <hyang@lyft.com>
Signed-off-by: Henry Yang <hyang@lyft.com>
Signed-off-by: Henry Yang <hyang@lyft.com>
Co-Authored-By: Matt Klein <mattklein123@gmail.com> Signed-off-by: Henry Yang <hyang@lyft.com>
Co-Authored-By: Matt Klein <mattklein123@gmail.com> Signed-off-by: Henry Yang <hyang@lyft.com>
Co-Authored-By: Matt Klein <mattklein123@gmail.com> Signed-off-by: Henry Yang <hyang@lyft.com>
5ea702e to
5909e01
Compare
Signed-off-by: Henry Yang <hyang@lyft.com>
Signed-off-by: Henry Yang <hyang@lyft.com>
|
Please merge master. /wait |
Signed-off-by: Henry Yang <hyang@lyft.com>
Description: Add read policy to redis proxy config. Here's the definition of ReadPolicy and descriptions for each option.
Risk Level: Medium, the default will be MASTER which is same as existing case.
Testing: Added unit tests, more integration test to follow.
Docs Changes:
Release Notes:
[Optional Fixes #Issue]
[Optional Deprecated:]