From 15b2d94b7ecc675f5eee5689623cfb9f5bb92524 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 29 May 2019 16:48:58 +0000 Subject: [PATCH] Encode write-dedupe keys as they are created This simplifies the code and avoids some allocations. Signed-off-by: Bryan Boreham --- schema.go | 4 ++++ series_store.go | 10 +--------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/schema.go b/schema.go index 307f4c1d60303..c9a8018531e50 100644 --- a/schema.go +++ b/schema.go @@ -2,6 +2,7 @@ package chunk import ( "encoding/binary" + "encoding/hex" "errors" "fmt" "strings" @@ -133,6 +134,9 @@ func (s schema) GetLabelEntryCacheKeys(from, through model.Time, userID string, }, "-", ) + // This is just encoding to remove invalid characters so that we can put them in memcache. + // We're not hashing them as the length of the key is well within memcache bounds. tableName + userid + day + 32Byte(seriesID) + key = hex.EncodeToString([]byte(key)) result = append(result, key) } diff --git a/series_store.go b/series_store.go index 695e2d24b580f..b75a3929bc78e 100644 --- a/series_store.go +++ b/series_store.go @@ -2,7 +2,6 @@ package chunk import ( "context" - "encoding/hex" "fmt" "net/http" @@ -362,14 +361,7 @@ func (c *seriesStore) calculateIndexEntries(from, through model.Time, chunk Chun keys := c.schema.GetLabelEntryCacheKeys(from, through, chunk.UserID, chunk.Metric) - cacheKeys := make([]string, 0, len(keys)) // Keys which translate to the strings stored in the cache. - for _, key := range keys { - // This is just encoding to remove invalid characters so that we can put them in memcache. - // We're not hashing them as the length of the key is well within memcache bounds. tableName + userid + day + 32Byte(seriesID) - cacheKeys = append(cacheKeys, hex.EncodeToString([]byte(key))) - } - - _, _, missing := c.writeDedupeCache.Fetch(context.Background(), cacheKeys) + _, _, missing := c.writeDedupeCache.Fetch(context.Background(), keys) if len(missing) != 0 { labelEntries, err := c.schema.GetLabelWriteEntries(from, through, chunk.UserID, metricName, chunk.Metric, chunk.ExternalKey()) if err != nil {