From e593ac586bcbe51b6c9267fd09c3e33aa355653e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=9F=8C=B2=20Harry=20=F0=9F=8C=8A=20John=20=F0=9F=8F=94?= Date: Thu, 16 Jul 2020 02:24:08 -0700 Subject: [PATCH 1/2] Use fnv32a hash for user_subring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 🌲 Harry 🌊 John 🏔 --- CHANGELOG.md | 1 + pkg/distributor/distributor.go | 2 +- pkg/ingester/client/fnv.go | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52b746eadb6..d4e30241e38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,6 +68,7 @@ * [BUGFIX] Experimental Delete Series: Fixed a data race in Purger. #2817 * [BUGFIX] KV: Fixed a bug that triggered a panic due to metrics being registered with the same name but different labels when using a `multi` configured KV client. #2837 * [BUGFIX] Query-frontend: Fix passing HTTP `Host` header if `-frontend.downstream-url` is configured. #2880 +* [BUGFIX] Ingester: Improve time-series distribution when `-experimental.distributor.user-subring-size` is enabled. #2757 ## 1.2.0 / 2020-07-01 diff --git a/pkg/distributor/distributor.go b/pkg/distributor/distributor.go index da73d0f0dec..0e92c451c54 100644 --- a/pkg/distributor/distributor.go +++ b/pkg/distributor/distributor.go @@ -512,7 +512,7 @@ func (d *Distributor) Push(ctx context.Context, req *client.WriteRequest) (*clie // Obtain a subring if required if size := d.limits.SubringSize(userID); size > 0 { - h := client.HashAdd32(client.HashNew32(), userID) + h := client.HashAdd32a(client.HashNew32a(), userID) subRing, err = d.ingestersRing.Subring(h, size) if err != nil { return nil, httpgrpc.Errorf(http.StatusInternalServerError, "unable to create subring: %v", err) diff --git a/pkg/ingester/client/fnv.go b/pkg/ingester/client/fnv.go index 0241f16e48b..f2e3b7fb80f 100644 --- a/pkg/ingester/client/fnv.go +++ b/pkg/ingester/client/fnv.go @@ -75,3 +75,25 @@ func HashAddByte32(h uint32, b byte) uint32 { h ^= uint32(b) return h } + +// HashNew32a initializies a new fnv32a hash value. +func HashNew32a() uint32 { + return offset32 +} + +// HashAdd32a adds a string to a fnv32a hash value, returning the updated hash. +// Note this is the same algorithm as Go stdlib `sum32.Write()` +func HashAdd32a(h uint32, s string) uint32 { + for i := 0; i < len(s); i++ { + h ^= uint32(s[i]) + h *= prime32 + } + return h +} + +// HashAddByte32a adds a byte to a fnv32a hash value, returning the updated hash. +func HashAddByte32a(h uint32, b byte) uint32 { + h ^= uint32(b) + h *= prime32 + return h +} From c9b890d38715ad3c310c71b27e06fa174c574263 Mon Sep 17 00:00:00 2001 From: Marco Pracucci Date: Thu, 16 Jul 2020 18:02:59 +0200 Subject: [PATCH 2/2] Update CHANGELOG.md Signed-off-by: Marco Pracucci --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d4e30241e38..0e547ae4269 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -68,7 +68,7 @@ * [BUGFIX] Experimental Delete Series: Fixed a data race in Purger. #2817 * [BUGFIX] KV: Fixed a bug that triggered a panic due to metrics being registered with the same name but different labels when using a `multi` configured KV client. #2837 * [BUGFIX] Query-frontend: Fix passing HTTP `Host` header if `-frontend.downstream-url` is configured. #2880 -* [BUGFIX] Ingester: Improve time-series distribution when `-experimental.distributor.user-subring-size` is enabled. #2757 +* [BUGFIX] Ingester: Improve time-series distribution when `-experimental.distributor.user-subring-size` is enabled. #2887 ## 1.2.0 / 2020-07-01