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 e90e753
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pkg/receive/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ func Heap(dir string) (err error) {
return err
}

f, err := os.Create(filepath.Join(dir, "impr4-go1.16.3.pprof"))
f, err := os.Create(filepath.Join(dir, "impr5-go1.16.3.pprof"))
if err != nil {
return err
}
Expand Down
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
5 changes: 3 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,13 +318,12 @@ 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.
b := make([]byte, 0, 1024)
b = append(b, prefix...)
b = append(b, sep[0])

for i, v := range lbls {
if len(b)+len(v.Name)+len(v.Value)+2 >= cap(b) {
Expand Down

0 comments on commit e90e753

Please sign in to comment.