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
Improvement: Implement redis READONLY feature for slaves #790
Comments
Great point!
So when we add READONLY feature, user should maintain good slaves and pick one, and send commands. |
Some background. Before we used the cluster, the arrangement was a master and at least one slave. Writes only went to the master and reads only went to the slave(s). Of course the master was keeping the slave(s) updated. This way we could optimize writing the data and more importantly, reading the data. A write would never interfere (atomic operation) with the read, at least conceptually. |
@allanwax Query offloading is definitely possible for Redis and Redis Cluster. Redis Cluster Specification describes query offloading. |
I'm kind-of ignoring "how we can maintain good slaves to query?" for now, not that this is a trivial question. I think we already do a good job of maintaining good slaves according to my understanding of the phrase and intended meaning. My original question was allowing the READONLY command (or equivalent) to be used with the understanding that you take the risks associated with that command. I hope we're talking about the same thing or the same related set of things. |
@allanwax OK, I see your intention about this issue. Just leaving additional note about READONLY with Cluster... tl;dr. We're fine with READONLY with Jedis, but not ready for JedisCluster. |
To be clear the intent was to send a READONLY to one or more of the slaves. The assumption here is that putting a slave in READONLY does not stop updates from the master. Part of my original comment about being able to get a hold of a slave knowing a key, or by being able to enumerate the slaves and pick one, was to enable getting a hold of a single slave. My intent is not to make the whole cluster READONLY, just (a) slave(s). Again, based on the above it would make sense to surface the method(s) that enumerate the master and slaves in such a way that it would be simple to select a jedis instance, put it into READONLY mode and use it. Also when you discontinue use in your thread of that particular host, it would fall back to being in a normal state. I don't know if putting a particular redis instance into READONLY puts it into that state for all users of that instance. If it does, that's an issue to be addressed. |
We should think about slot migration. |
I agree with the potential problems. However, part of what I would like to document is that is is dangerous to use this command. Also, I don't know if replication stops if you use it. Maybe we need a jedis specific command that allows someone to get something from a slave and ignore the MOVED message. This wouldn't break what's already there. But writes would have to be prohibited. |
One thing I'm being afraid of is, many users doesn't read documentations, and post an issue that why this is not working. @xetorthio @marcosnils I'd like you to discuss this issue when you have time. :) Btw, maybe we can find a way to handle it inside JedisCluster, with minimizing potential problems. There may be another issue, clearing READONLY state when returning instance to pool if we borrowed a instance. |
I think that there are 2 things here:
I think 1 is a no brainer and easy to do. Am I missing something? On 21:16, Mon, Nov 24, 2014 Jungtaek Lim notifications@github.com wrote:
|
@xetorthio As I talked before from Google Groups (https://groups.google.com/d/msg/jedis_redis/u6j8slokO3E/Dh5Q94TRjJUJ), it's not that simple. If we add new feature to
Please correct me if I'm wrong. Thanks! |
My intent is not to handle MOVED at all. My needs are less restrictive. If I put a slave in READONLY mode then I am willing to accept the 'loss' of keys without handling the moved responses. I believe that a MOVED is not issued in READONLY mode which is fine for me. The intent is to have writes to the master and reads from the slave. Periodically, rechecks will be made as to where to read from. It is also assumed that the master is updating the slave, wherever the key lies, regardless of READONLY or not. With this the ability to find where a key exists needs to be surfaced as well. Something like Jedis jedis = getSlave(key); |
"NEED CITATION" I just read Redis source code, and READONLY keyword works only in cluster environment. Then we have to manage slaves to serve READONLY feature. |
SEE #830 |
Hi Allan/Heart, |
I will leave this to @heart to respond. I think he knows more about this than I. I can say that Jedis takes care of handling MOVED messages and directing requests to the proper place. |
a) JedisSentinelPool doesn't care about slaves, cause Redis Sentinel doesn't take care of slave odown / failover. |
Thanks Allan and Heart.. |
Wondering to know if this is still not supported where sentinel pool can be used to talk to slaves for read so that load is distributed. And @franklinjohnv-flipkart how you managed for (a) to load balanced slaves? |
+1 on this one, even if I know it's hard to implement properly ... :/ |
This issue is marked stale. It will be closed in 30 days if it is not updated. |
Redis (cluster?) currently allows you to issue a READONLY command on a slave that will allow you to read keys that normally would issue a MOVED response. In cases where you can tolerate the slave not being entirely up to date with the master, it would be nice if there is a way to do something like hand waving here find a slave for a key resident on a master, (b) connect to the slave in READONLY mode, (c) read key:values. This would help with throughput in certain cases.
The text was updated successfully, but these errors were encountered: