-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Improve cluster nodes and slots information #988
Comments
How about the following proposal? We add an instance of On On On |
I found this proposal very interesting. But can we have more than one cluster? I'm asking this because I'm thinking that we can add all those data directly in |
The idea is that |
That makes sense. To isolate those "cluster info" in it. This looks as a good solution for me. @marcosnils @HeartSaVioR what do you guys think? Just another question related to another issue. When we want to execute a command in a specific node, this method will be directly in |
Do we also want to be able to specify a list of nodes, i.e. only look here for the key? Can a Do we need to surface a convenience routine to pick the master to send a command to. Something like: public Node getMasterForKey(String key) { ... }
public List<Node> getSlavesForKey(String key) { ... }
public List<Node> getMastersForKeys(String... keys) { ... }``` |
Yes. Actually when I thought about my proposal the methods you mentioned were there, but when I wrote it here I forgot to add them. By adding all these methods, I think the cluster discovery API is pretty decent and complete and gives a lot of freedom to users. |
So this proposal allows for things like: Running commands on the master that owns key "foo"try (Jedis j = jedisCluster.cluster.getMasterForKey("foo").getPool().getResource()) {
j.ping();
...
} Running commands on one of the slaves which master owns key "foo"try (Jedis j = jedisCluster.cluster.getSlavesForKey("foo")[0].getPool().getResource()) {
j.ping();
...
} etc... |
I think we should also consider getting rid of idea of needing to go to a pool to get a resource to do the operation. That should be hidden. Kind-of like jedisCluster.get(key); some master is chosen and some pool member is used and when I'm done I'm not worried about returning resources. Something like |
Could be. But there are people that dont use the pool. How to deal with
|
@nykolaslima JedisCluster already has internal Pools for each master nodes. |
Though we can make new Jedis instance instead of borrowing, but users still need to close resource since users can send some (not one) commands after getting instance. |
@HeartSaVioR @xetorthio I agree with @allanwax comment about hiding redundant try (Jedis j = jedisCluster.cluster.getSlavesForKey("foo")[0].getConnection()) {
j.ping();
...
} What do you think? I'd like to hear @christophstrobl, @olivergierke and @thomasdarimont opinions about this |
I agree for abstraction of getting instance since we can make it borrowed from pool, or creating new instance at that time. My only concern is just how to clean up resource. It doesn't make sense it can be implicit . |
@HeartSaVioR try-with-resources will clean it up automatically, otherwise we'll add a javadoc to the |
OK, we can document it. :) Btw, I think it's better to create new instance per each getConnection() cause if we share Pool and users doesn't return resource to pool, JedisCluster may stuck, too. |
Please don't forget we can't force users to use JDK7 or upper unless we release Jedis 3.0.0 AT LEAST NOW. We can make it applied to 2.8.0, too. |
@HeartSaVioR I do also agree that a new connection should be returned to avoid JedisCluster pool possible errors. The good thing about this approach is that if user forgets to close connection and it falls out of scope, the GC will close the socket. We still need to remark that connection should be gracefully closed |
Sockets need to be explicitly closed or they stay open in the kernel. GC itself won't do it. SEE http://stackoverflow.com/questions/2454550/should-i-close-sockets-from-both-ends I think the explicit return is a call to I know everyone complains about the use of finalize() but as I've said before, there are cases where it is usefull. If the means to do the call is something like A secondary issue is that Jedis |
@allanwax |
Thanks for the correction. Next time I need to look deeper. |
So we all agree on those design points? Can we proceed with it? |
I totaly agree with hinding the Pool details so that one can call Concerning the
The thing I'm not sure about is if the Nodes should allow access to the connection directly. Would it make sense to keep Nodes as information containers about slots, ids,... while having to ask
This would leave connection handling to |
I somewhat disagree about separating For normal stuff, it should be sufficient to do |
What happens if during processing a |
I add a function to get HostAndPort struct from JedisCluster to delete data from every node using scan and pipeline. And I should judge does this node is master.I think just return HostAndPort is better. Here is how I use these function now.MasterNode and SlaveNode maybe kind of redundancy.
|
Looks like Jedis going in completely different direction from this task, even that minimal ClusterNodeInformation was deleted from current version. Using pipelining and scans in cluster mode became not easier, but more painful in 2.8.0 Any progress on this scope? |
@Spikhalskiy https://twitter.com/antirez/status/691993742606274560 Jedis doesn't have any strategies (different versioning, maven profile, and so on) when Redis breaks backward compatibility. Since active maintainers are only two now, we would like to simplify our work, and let other library wraps Jedis and provide high-level operations. One of them is Spring Data Redis. Anyway, since we can't rely on |
Is this implemented ?? |
Couple thoughts on this thread.
|
@maksymkovalenko I can see a use for getMasterNodeForKey where you want to know where you're writing to and what its slaves are (at least at the moment in time when you ask). Some optimizations in Redis access are to read from the slaves and write to the masters so that in a read heavy application you can spread the reads around among the slaves and get some parallelism. |
This issue is marked stale. It will be closed in 30 days if it is not updated. |
JedisCluster
currently exposes nodes information through thegetClusterNodes
method but this returns very limited information about node information (only host and port). It'd be nice if we could return some sort ofClusterNodeInformation
object with all the information of the corresponding node.It's also necessary to extend the current
ClusterNodeInformation
bean and to add information such as master/slave role.The text was updated successfully, but these errors were encountered: