In essence, Haproxy was not written to work cooperatively with Sentinel, and Sentinel was not written to work cooperatively with Haproxy.
I know there is a blogger on the Internet wrote a post saying this will work. However, as I said in the 3-post thread above, I don't see how they will. As both of the discussion threads describe, trouble arises as soon as a master fails or starts back up again.
In my view it's not best to use both Haproxy and Sentinel. Use one or the other.
-Greg
--
You received this message because you are subscribed to the Google Groups "Redis DB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to redis-db+u...@googlegroups.com.
To post to this group, send email to redi...@googlegroups.com.
Visit this group at https://groups.google.com/group/redis-db.
For more options, visit https://groups.google.com/d/optout.
Sure the people saying to have haproxy do a role check are being shortsighted and promoting a broken configuration. Sure the people promoting haproxy checking in with a sentinel aren't doing any better. And sure the people saying to have haproxy do a check against all sentinels still get it wrong given haproxy' behavior on backend failures. But to say that simply because haproxy isn't suitable to manage itself you can't use it is to throw the baby out with the bath water.
As to the original problem you'll experience this if the client library can not reliably reconnect and it has nothing to do with haproxy or sentinel. From the information presented the perl client library does not appear to properly handle reconnection so you will need to catch the "not connected" error and have your code reconnect on that error.
Of course you'll need to implement a circuit breaker and back off mechanism so as to not flood reconnection attempts or be stuck in a loop trying to reconnect. But fundamentally that is what you need to do: detect connection failure and reconnect. You should also see this same behavior if you connected directly to a Redis server and after establishing and using the connection restart the Redis instance. This will cause a disconnect which ideally the client library catches or at least passes up the specific error so your code can reconnect.
Even some client libraries which retry will only retry once and will do so immediately. Of course if the service isn't back immediately it propagates a disconnected error and can look like it doesn't retry. As such you should've prepared to implement a mechanism to manage that reconnection attempt to fit your specific requirements.
I haven't touched perl in about two decades, much to my coding nirvana, so other than the basic principles of what needs to be done, I am unable to give specific aid in Doing so in that language. Hopefully knowing what is happening and what to do to catch and handle the condition is enough to point you in the right code direction.
Cheers and good luck,
Bill
As someone with first hand experience with over a thousand setups of haproxy with sentinel I will have to disagree entirely. Again the mistake lies in thinking haproxy can automatically interact with sentinel on a reliable basis. It can not.
However there is a myriad of ways to make it work ranging from a simple shell script which the sentinel leader executes to reconfigure haproxy, or something as elegant as and consul-template managing haproxy. To say it can't be done is demonstrably false. While not designed to work specifically together each system has a design that allows the two to work together. The rub is it requires some sort of third party tool. But those tools are easy to write and already exist.