-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[4.x] Fix how hash slot assignment is retrieved and stored #407
Conversation
The test failure is not caused by this PR, it fails on the current 4.x branch too (as well as in #406). |
thanks @Ladicek let me fix the build and then you can rebase :-) |
} | ||
} | ||
} | ||
|
||
private void getSlots(String endpoint, RedisConnection conn, Handler<AsyncResult<Slots>> onGetSlots) { | ||
private Future<Slots> getSlots() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead here we should have a context
private Future<Slots> getSlots() { | ||
Slots slots = this.slots.get(); | ||
if (slots != null) { | ||
return Future.succeededFuture(slots); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and use context.succeededFuture(slot)
return Future.succeededFuture(slots); | ||
} | ||
|
||
Promise<Slots> promise = vertx.promise(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or context.promise()
src/main/java/io/vertx/redis/client/impl/RedisClusterClient.java
Outdated
Show resolved
Hide resolved
Previously, the `RedisClusterClient` used to obtain the hash slot assignment as the first step of each `connect()` call. This is fairly expensive and increases the load on the first endpoint in the list (because we target the first endpoint when issuing `CLUSTER SLOTS`). It is also unnecessary. Redis always sends a redirection when the node to which a command is sent is not assigned the hash slot targetted by the command. Until we observe such redirection, the hash slot assignment we observed before is still valid. Hence, we can store the hash slot assignment in the `RedisClusterClient` and reuse it for all `RedisClusterConnection` objects, until the `MOVED` error is seen. In such case, we reset the hash slot assignment so that the next `connect()` call fetches it again. To avoid spurious failures (it could happen that the cluster is resharded such that a command that would fail under the existing hash slot assignment will no longer fail, because the hash slots that were previously assigned to multiple nodes are now assigned to a single node), the hash slot assignment is not kept permanently. Instead, it is treated as a cache with configurable TTL, defaulting to 1 second.
f1025a5
to
7a25220
Compare
Refactored as discussed on Friday:
|
Backport of #405 to 4.x.