Skip to content

Commit

Permalink
Fixes.
Browse files Browse the repository at this point in the history
Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka committed Apr 20, 2021
1 parent 0c73663 commit dc264f8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/receive/hashring.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package receive
import (
"context"
"fmt"
"sort"
"sync"

"github.com/pkg/errors"
Expand Down Expand Up @@ -65,6 +66,10 @@ func (s simpleHashring) GetN(tenant string, ts *prompb.TimeSeries, n uint64) (st
if n >= uint64(len(s)) {
return "", &insufficientNodesError{have: uint64(len(s)), want: n + 1}
}

// TODO(bwplotka): This might be not needed, double check.
sort.Slice(ts.Labels, func(i, j int) bool { return ts.Labels[i].Name < ts.Labels[j].Name })

return s[(labelpb.HashWithPrefix(tenant, ts.Labels)+n)%uint64(len(s))], nil
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/store/labelpb/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
"github.com/prometheus/prometheus/pkg/labels"
)

var sep = []byte{'\xff'}

func noAllocString(buf []byte) string {
return *(*string)(unsafe.Pointer(&buf))
}
Expand Down Expand Up @@ -316,8 +318,6 @@ func DeepCopy(lbls []ZLabel) []ZLabel {
return ret
}

var sep = []byte{'\xff'}

// HashWithPrefix returns a hash for the given prefix and labels.
func HashWithPrefix(prefix string, lbls []ZLabel) uint64 {
// Use xxhash.Sum64(b) for fast path as it's faster.
Expand Down

0 comments on commit dc264f8

Please sign in to comment.