summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7b64cc9)
raw | patch | inline | side by side (parent: 7b64cc9)
author | Vincent Bernat <vincent@bernat.im> | |
Wed, 15 Jun 2016 07:53:07 +0000 (09:53 +0200) | ||
committer | Vincent Bernat <vincent@bernat.im> | |
Wed, 15 Jun 2016 07:54:09 +0000 (09:54 +0200) |
Otherwise, partition is selected solely on the first letter of the
key. If all your hosts are starting with the same letter, everything
ends up in a single partition.
key. If all your hosts are starting with the same letter, everything
ends up in a single partition.
src/write_kafka.c | patch | blob | history |
diff --git a/src/write_kafka.c b/src/write_kafka.c
index e881593b65161e20af6b697dd122ca2e402829c0..614ce0f084df7f9ba09181b21983a2fdbec277a5 100644 (file)
--- a/src/write_kafka.c
+++ b/src/write_kafka.c
}
#endif
+static uint32_t kafka_hash(const char *keydata, size_t keylen)
+{
+ uint32_t hash = 5381;
+ for (; keylen > 0; keylen--)
+ hash = ((hash << 5) + hash) + keydata[keylen - 1];
+ return hash;
+}
+
static int32_t kafka_partition(const rd_kafka_topic_t *rkt,
const void *keydata, size_t keylen,
int32_t partition_cnt, void *p, void *m)
{
- uint32_t key = *((uint32_t *)keydata );
+ uint32_t key = kafka_hash(keydata, keylen);
uint32_t target = key % partition_cnt;
int32_t i = partition_cnt;