assigned ID values that are evenly distributed over the 32-bit
space.
+ guid The node keys will be derived from the server's guid, when
+ available, otherwise they will fall back on "id". The benefit
+ is that it does not depend on ordering at all, only on an
+ internal stable identifier that can be replicated across many
+ load balancers.
+
addr The node keys will be derived from the server's address, when
available, or else fall back on "id".
enum srv_hash_key {
SRV_HASH_KEY_ID = 0, /* derived from server puid, 28 LSB used */
SRV_HASH_KEY_ID32, /* derived from server puid, 32 bits used */
+ SRV_HASH_KEY_GUID, /* derived from server guid */
SRV_HASH_KEY_ADDR, /* derived from server address */
SRV_HASH_KEY_ADDR_PORT /* derived from server address and port */
};
#include <haproxy/api.h>
#include <haproxy/backend.h>
#include <haproxy/errors.h>
+#include <haproxy/guid.h>
#include <haproxy/queue.h>
#include <haproxy/server.h>
#include <haproxy/tools.h>
{
enum srv_hash_key hash_key = s->hash_key;
struct server_inetaddr srv_addr;
+ const char *guid_key = NULL;
u32 key;
/* If hash-key is addr or addr-port then we need the address, but if we
}
break;
+ case SRV_HASH_KEY_GUID:
+ guid_key = guid_get(&s->guid);
+ if (!guid_key)
+ hash_key = SRV_HASH_KEY_ID;
+ break;
default:
break;
}
}
break;
+ case SRV_HASH_KEY_GUID:
+ key = XXH32(guid_key, strlen(guid_key), 0);
+ break;
+
case SRV_HASH_KEY_ID32:
key = full_hash(htonl(s->puid));
break;
struct proxy *curproxy, struct server *newsrv, char **err)
{
if (!args[*cur_arg + 1]) {
- memprintf(err, "'%s expects 'id', 'id32', 'addr', or 'addr-port' value", args[*cur_arg]);
+ memprintf(err, "'%s expects 'id', 'id32', 'guid', 'addr', or 'addr-port' value", args[*cur_arg]);
return ERR_ALERT | ERR_FATAL;
}
else if (strcmp(args[*cur_arg + 1], "id32") == 0) {
newsrv->hash_key = SRV_HASH_KEY_ID32;
}
+ else if (strcmp(args[*cur_arg + 1], "guid") == 0) {
+ newsrv->hash_key = SRV_HASH_KEY_GUID;
+ }
else if (strcmp(args[*cur_arg + 1], "addr") == 0) {
newsrv->hash_key = SRV_HASH_KEY_ADDR;
}
newsrv->hash_key = SRV_HASH_KEY_ADDR_PORT;
}
else {
- memprintf(err, "'%s' has to be 'id', 'id32', 'addr', or 'addr-port'", args[*cur_arg]);
+ memprintf(err, "'%s' has to be 'id', 'id32', 'guid', 'addr', or 'addr-port'", args[*cur_arg]);
return ERR_ALERT | ERR_FATAL;
}