]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MEDIUM: lb-chash: Deterministic node hashes based on server address
authorAnthony Deschamps <anthony.j.deschamps@gmail.com>
Fri, 16 Feb 2024 21:00:35 +0000 (16:00 -0500)
committerWilly Tarreau <w@1wt.eu>
Tue, 2 Apr 2024 05:00:10 +0000 (07:00 +0200)
commitfaa8c3e024b1e4e5833a8deaa6545675036544c6
tree1aadc6af5dc1f0619d635e1e03f4de300e0d35ac
parentda03396bb3a15b94c5514b3f4e10478e5bbabc3a
MEDIUM: lb-chash: Deterministic node hashes based on server address

Motivation: When services are discovered through DNS resolution, the order in
which DNS records get resolved and assigned to servers is arbitrary. Therefore,
even though two HAProxy instances using chash balancing might agree that a
particular request should go to server3, it is likely the case that they have
assigned different IPs and ports to the server in that slot.

This patch adds a server option, "hash-key <key>" which can be set to "id" (the
existing behaviour, default), "addr", or "addr-port". By deriving the keys for
the chash tree nodes from a server's address and port we ensure that independent
HAProxy instances will agree on routing decisions. If an address is not known
then the key is derived from the server's puid as it was previously.

When adjusting a server's weight, we now check whether the server's hash has
changed. If it has, we have to remove all its nodes first, since the node keys
will also have to change.
doc/configuration.txt
include/haproxy/server-t.h
src/lb_chash.c
src/server.c