Add support for auto reconneting in Jedis
Best explained in the comments at https://jira.springsource.org/browse/DATAKV-29
This is interesting. I wonder why testOnBorrow wouldn't be enough.
I think it should be (not sure how expensive the validation query is or whether multi/pipeline support affect this). It would be nice to know what impact it has on performance as it might be worth enabling it by default.
yeah, even if PING is not an expensive operation, executing one every time you get a connection from the pool seems too pessimistic. probably we should trust on the pool most of the time, so maybe it is better to assume the connection is OK and if it fails, just return it broken and ask for a new connection and repeat the operation. probably Jedis should do this automatically and leave the amount of times to do this as a configuration somewhere.
It's important to make sure the behaviour is configurable - for example one might not want the operation to be retried (which can be configured on and off through a setting). As for defaults, I think it's important to use simple, intuitive defaults that give great performance - restarting the server is somewhat unusual. It's nice to be able to cope with it but if enabling this has side effects (like retries), then the application might want to know about it - for example, how can I test if the database is restarted if my PING requests are being retried instead of just failing...
We tried the testOnBorrow property and the impact on performance was horrible to say the least. I'd suggest straying away from it as a long term solution.
Ok. I will work on a reconnect mechanism ASAP and if you can let me know how it works!
reconnectting is an important feature.
for high throughout environment, testonborrow is not a good way.
we can use do and catching exception pattern:
Get a connection from pool; try { do something; } catch (Exception e) { redis.clients.util.returnBrokenResource(resource); }
Issue 43 should improve on this by differentiating between connection exceptions and protocol/application exceptions. That way one can know whether the connection is actually broken or not.
please check issue #123 as I think it may impact on this. Many connection errors were not modifying connection state in jedis so jedis would never know it was disconnected even when throwing broken pipe exceptions. I think my fix would reconnect on sending commands for most cases
no movement since april... should we close this?
I think this issue is not relevant now as of Jedis 2.0.0 when connection is broken, Jedis will close it and reopen it on the next command. It is something in the middle between. Reconnection is not that good for some cases. For example multi/exec blocks, pipelines, etc. So this gives you a good way to handle this, without the need to use testOnBorrow. Closing now. If the current solution is not enough we can reopen and re-discuss :)
Does Jedis provides this auto reconnecting / auto retry feature? if yes then how can i configure it?
@PriyankaRanjan no, because otherwise Jedis would have to queue all pending operations and retry them in a different thread until the server comes back online (or similar). Jedis returns a JedisConnectionException whenever the server is down or something happened in the communication. It's up to the user to decide how / when to retry the operation. You can re-use the same Jedis instance as it'll try to re-connect if a connection error has been received in the past.
The reason why we decided not to do any retry logic is because usually users have different requirements for retry policies depending on their situation. That's why we encourage the community to come up with their own retry-library and open source it so others can use it.