Hi Justin, On Wed, May 23, 2012 at 03:11:00PM -0700, Justin Karneges wrote: > (Apologies if this comes through twice. The first time I sent was before > subscription approval, and I don't think it went through.)
It was OK, you don't need to be subscribed to post messages. (...) > 1) Even if haproxy notices within seconds that the mysql master is down, > existing connections remain pointed to the master. I set "timeout server 5m" > so that within 5 minutes of inactivity, haproxy will eventually kill the > connections, causing clients to reconnect and get routed to the slave. This > means that in practice, the failover takes 5 minutes to fully complete. I > could reduce this timeout value futher but this does not feel like the ideal > solution. There is an option at the server level which is "on-marked-down shutdown-session". It achieves exactly what you want, it will kill all connections to a server which is detected as down. > 2) If the master eventually comes back, all connections that ended up routing > to the slave will stay on the slave indefinitely. The only solution I have > for > this is to restart mysql on the slave, which kicks everyone off causing them > to > reconnect and get routed back to the master. This is acceptable if restoring > master required some kind of manual maintenance, since I'd already be getting > my hands dirty anyway. However, if master disappears and comes back due to > brief network outage that resolves itself automatically, it's unfortunate > that > I'd still have to manually react to this by kicking everyone off the slave. There is no universal solution for this. As haproxy doesn't inspect the mysql traffic, it cannot know when a connection remains idle and unused. Making it arbitrarily kill connections to a working server would be the worst thing to do, as it would kill connections on which a transaction is waiting for being completed. I really think the best you can do is to have your slave declared as a backup server and use short enough timeouts so that idle connections expire quickly and are replaced by new connections to the master server. Regards, Willy

