mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-08-06 15:17:01 +02:00
MINOR: lbprm: support for the "none" hash-type function
Allow the use of the "none" hash-type function so that the key resulting from the sample expression is directly used as the hash. This can be useful to do the hashing manually using available hashing converters, or even custom ones, and then inform haproxy that it can directly rely on the sample expression result which is explictly handled as an integer in this case.
This commit is contained in:
parent
e0b4660015
commit
a7563158f7
@ -6060,6 +6060,10 @@ hash-type <method> <function> <modifier>
|
|||||||
a better distribution or less predictable results especially when
|
a better distribution or less predictable results especially when
|
||||||
used on strings.
|
used on strings.
|
||||||
|
|
||||||
|
none don't hash the key, the key will be used as a hash, this can be
|
||||||
|
useful to manually hash the key using a converter for that purpose
|
||||||
|
and let haproxy use the result directly.
|
||||||
|
|
||||||
<modifier> indicates an optional method applied after hashing the key :
|
<modifier> indicates an optional method applied after hashing the key :
|
||||||
|
|
||||||
avalanche This directive indicates that the result from the hash
|
avalanche This directive indicates that the result from the hash
|
||||||
|
@ -118,11 +118,12 @@
|
|||||||
#define BE_LB_HASH_MOD 0x200000 /* get/clear hash modifier */
|
#define BE_LB_HASH_MOD 0x200000 /* get/clear hash modifier */
|
||||||
|
|
||||||
/* BE_LB_HFCN_* is the hash function, to be used with BE_LB_HASH_FUNC */
|
/* BE_LB_HFCN_* is the hash function, to be used with BE_LB_HASH_FUNC */
|
||||||
#define BE_LB_HFCN_SDBM 0x000000 /* sdbm hash */
|
#define BE_LB_HFCN_SDBM 0x000000 /* sdbm hash */
|
||||||
#define BE_LB_HFCN_DJB2 0x400000 /* djb2 hash */
|
#define BE_LB_HFCN_DJB2 0x400000 /* djb2 hash */
|
||||||
#define BE_LB_HFCN_WT6 0x800000 /* wt6 hash */
|
#define BE_LB_HFCN_WT6 0x800000 /* wt6 hash */
|
||||||
#define BE_LB_HFCN_CRC32 0xC00000 /* crc32 hash */
|
#define BE_LB_HFCN_CRC32 0xC00000 /* crc32 hash */
|
||||||
#define BE_LB_HASH_FUNC 0xC00000 /* get/clear hash function */
|
#define BE_LB_HFCN_NONE 0x1000000 /* none - no hash */
|
||||||
|
#define BE_LB_HASH_FUNC 0x1C00000 /* get/clear hash function */
|
||||||
|
|
||||||
|
|
||||||
/* various constants */
|
/* various constants */
|
||||||
|
@ -84,6 +84,14 @@ static unsigned int gen_hash(const struct proxy* px, const char* key, unsigned l
|
|||||||
case BE_LB_HFCN_CRC32:
|
case BE_LB_HFCN_CRC32:
|
||||||
hash = hash_crc32(key, len);
|
hash = hash_crc32(key, len);
|
||||||
break;
|
break;
|
||||||
|
case BE_LB_HFCN_NONE:
|
||||||
|
/* use key as a hash */
|
||||||
|
{
|
||||||
|
const char *_key = key;
|
||||||
|
|
||||||
|
hash = read_int64(&_key, _key + len);
|
||||||
|
}
|
||||||
|
break;
|
||||||
case BE_LB_HFCN_SDBM:
|
case BE_LB_HFCN_SDBM:
|
||||||
/* this is the default hash function */
|
/* this is the default hash function */
|
||||||
default:
|
default:
|
||||||
|
@ -2624,6 +2624,9 @@ int cfg_parse_listen(const char *file, int linenum, char **args, int kwm)
|
|||||||
else if (strcmp(args[2], "crc32") == 0) {
|
else if (strcmp(args[2], "crc32") == 0) {
|
||||||
curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
|
curproxy->lbprm.algo |= BE_LB_HFCN_CRC32;
|
||||||
}
|
}
|
||||||
|
else if (strcmp(args[2], "none") == 0) {
|
||||||
|
curproxy->lbprm.algo |= BE_LB_HFCN_NONE;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
|
ha_alert("parsing [%s:%d] : '%s' only supports 'sdbm', 'djb2', 'crc32', or 'wt6' hash functions.\n", file, linenum, args[0]);
|
||||||
err_code |= ERR_ALERT | ERR_FATAL;
|
err_code |= ERR_ALERT | ERR_FATAL;
|
||||||
|
Loading…
Reference in New Issue
Block a user