mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-02-17 19:16:56 +00:00
MINOR: stick-table: change the API of the function used to calculate the shard
The function used to calculate the shard number currently requires a stktable_key on input for this. Unfortunately, it happens that peers currently miss this calculation and they do not provide stktable_key at all, instead they're open-coding all the low-level stick-table work (hence why it's missing). Thus we'll need to be able to calculate the shard number in keys coming from peers as well but the current API does not make it possible. This commit addresses this by inverting the order where the length and the shard number are used. Now the low-level function is independent on stksess and stktable_key, it takes a table, pointer and length and does all the job. The upper function takes care of the type and key to get the its length, and is for use only from stick-table code. This doesn't change anything except that the low-level one will be usable from outside (hence why it's exported now).
This commit is contained in:
parent
061a098c5c
commit
d5cae6a0c7
@ -43,6 +43,7 @@ struct stksess *stksess_new(struct stktable *t, struct stktable_key *key);
|
||||
void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key *key);
|
||||
void stksess_free(struct stktable *t, struct stksess *ts);
|
||||
int stksess_kill(struct stktable *t, struct stksess *ts, int decrefcount);
|
||||
int stktable_get_key_shard(struct stktable *t, const void *key, size_t len);
|
||||
|
||||
int stktable_init(struct stktable *t);
|
||||
int stktable_parse_type(char **args, int *idx, unsigned long *type, size_t *key_size);
|
||||
|
@ -156,13 +156,27 @@ void stksess_setkey(struct stktable *t, struct stksess *ts, struct stktable_key
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize or update the key hash in the sticky session <ts> present in table <t>
|
||||
* from the value present in <key>.
|
||||
/* return a shard number for key <key> of len <len> present in table <t>. This
|
||||
* takes into account the presence or absence of a peers section with shards
|
||||
* and the number of shards, the table's hash_seed, and of course the key. The
|
||||
* caller must pass a valid <key> and <len>. The shard number to be used by the
|
||||
* entry is returned (from 1 to nb_shards, otherwise 0 for none).
|
||||
*/
|
||||
static unsigned long long stksess_getkey_hash(struct stktable *t,
|
||||
struct stksess *ts,
|
||||
struct stktable_key *key)
|
||||
int stktable_get_key_shard(struct stktable *t, const void *key, size_t len)
|
||||
{
|
||||
/* no peers section or no shards in the peers section */
|
||||
if (!t->peers.p || !t->peers.p->nb_shards)
|
||||
return 0;
|
||||
|
||||
return XXH64(key, len, t->hash_seed) % t->peers.p->nb_shards + 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the shard for <key> key of <ts> sticky session attached to <t> stick table.
|
||||
* Use zero for stick-table without peers synchronisation.
|
||||
*/
|
||||
static void stksess_setkey_shard(struct stktable *t, struct stksess *ts,
|
||||
struct stktable_key *key)
|
||||
{
|
||||
size_t keylen;
|
||||
|
||||
@ -171,24 +185,7 @@ static unsigned long long stksess_getkey_hash(struct stktable *t,
|
||||
else
|
||||
keylen = t->key_size;
|
||||
|
||||
return XXH64(key->key, keylen, t->hash_seed);
|
||||
}
|
||||
|
||||
/*
|
||||
* Set the shard for <key> key of <ts> sticky session attached to <t> stick table.
|
||||
* Do nothing for stick-table without peers synchronisation.
|
||||
*/
|
||||
static void stksess_setkey_shard(struct stktable *t, struct stksess *ts,
|
||||
struct stktable_key *key)
|
||||
{
|
||||
if (!t->peers.p)
|
||||
/* This stick-table is not attached to any peers section */
|
||||
return;
|
||||
|
||||
if (!t->peers.p->nb_shards)
|
||||
ts->shard = 0;
|
||||
else
|
||||
ts->shard = stksess_getkey_hash(t, ts, key) % t->peers.p->nb_shards + 1;
|
||||
ts->shard = stktable_get_key_shard(t, key->key, keylen);
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user