stksess_setkey_shard() hashes string keys on the raw sample length, while
the stored key is truncated to the table's "len" and stops at the first
NUL. Peers send and hash the stored key, so for longer keys the creating
node and its peers disagree on the shard, and entries are pushed to the
wrong peers.
Let's compute the shard on the stored key length. This was introduced in
2.7 by commit
36d156564 ("MINOR: peers: Support for peer shards") and
should be backported to all stable versions.
{
size_t keylen;
- if (t->type == SMP_T_STR)
- keylen = key->key_len;
+ if (t->type == SMP_T_STR) {
+ /* must match the stored key, which is truncated and stops at
+ * the first NUL, since it's what peers will use.
+ */
+ keylen = key->key_len + 1 < t->key_size ? key->key_len : t->key_size - 1;
+ keylen = strnlen2(key->key, keylen);
+ }
else
keylen = t->key_size;