Skip to content

Commit

Permalink
Merge pull request grafana#1430 from cortexproject/move-key-encode
Browse files Browse the repository at this point in the history
Encode write-dedupe keys as they are created
  • Loading branch information
csmarchbanks authored May 29, 2019
2 parents c0c5f25 + 15b2d94 commit 68d8919
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
4 changes: 4 additions & 0 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package chunk

import (
"encoding/binary"
"encoding/hex"
"errors"
"fmt"
"strings"
Expand Down Expand Up @@ -134,6 +135,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)
}
Expand Down
10 changes: 1 addition & 9 deletions series_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package chunk

import (
"context"
"encoding/hex"
"fmt"
"net/http"

Expand Down Expand Up @@ -389,14 +388,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 {
Expand Down

0 comments on commit 68d8919

Please sign in to comment.