Hi, On Wed, Sep 28, 2016 at 01:07:22PM +0300, Camarero wrote: > Hello! > > I would like to build a proxy for galera cluster which will be switch > incoming connections between two servers. > Both servers are equal - there is no master or slave. However, all > connections must be redirected to the single server and when it goes down, > they must be switched to the second one. If the first server goes up, the > connections must remain to another server (which accepted connections when > the first server was offline). > > I found in HAProxy so called "stick tables" but unfortunately, I couldn't > understand how to implement eternal sticky sessions - I can only specify > 24d (I suspect that this is INT_MAX) as maximum value for expiration > parameter for stick-table.
You guessed right. But first, the "expire" parameter is not mandatory, so by default it's eternal. Second, it's not a good idea to make it eternal because the expiration is refreshed every time a new session matches. So I'm not sure you're interested in matching a session more than 24 days after the previous match, but that's your choice :-) > And the second question - what rule should I create to achieve the behavior > described above? I tried to use "stick on dst_port" - seems it works but > I'm not sure. I chose "dst_port" because it is always the same for all > client connections. We used to do exactly this for some active-backup setups indeed. You can also use "always_true" or "always_false" which are both constants (so may be even more robust), or "int(0)" or any other form of constant. > And the third question - does it make a difference what type of balance > policy is used? For my config below, stickiness seems to work, however my > understanding is that the type of balance policy shouldn't play a role when > choosing server (because I've created stick-table). > However, if I change 'leastconn' to 'roundrobin', stickiness will disappear > in my environment. There is no reason for this. Stickiness is an exception to load balancing. So the principle is that if an entry is found, then the matching server is used, otherwise the balancing algorithm is applied to pick the server. > listen galera 192.168.77.77:7777 > balance leastconn > stick-table type ip size 1k expire 24d > stick on dst_port Oh I guess I found the problem : stick-table is of type "ip" and the key is "dsp_port" so the conversion very likely fails. Please use "type integer" instead. Note that you can always connect to your stats socket and show the table to see what's in it : echo "show table galera" | socat /path/to/socket - Regards, Willy

