Merge pull request #11485 from t00350320/prometheus-office

GetRefByhash() will query a label's ref with hash value rather than lset.Hash().
This commit is contained in:
Ganesh Vernekar 2022-11-16 15:09:49 +01:00 committed by GitHub
commit 42633bd05c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 7 deletions

View File

@ -248,7 +248,8 @@ type GetRef interface {
// Returns reference number that can be used to pass to Appender.Append(),
// and a set of labels that will not cause another copy when passed to Appender.Append().
// 0 means the appender does not have a reference to this series.
GetRef(lset labels.Labels) (SeriesRef, labels.Labels)
// hash should be a hash of lset.
GetRef(lset labels.Labels, hash uint64) (SeriesRef, labels.Labels)
}
// ExemplarAppender provides an interface for adding samples to exemplar storage, which

View File

@ -998,9 +998,9 @@ type dbAppender struct {
var _ storage.GetRef = dbAppender{}
func (a dbAppender) GetRef(lset labels.Labels) (storage.SeriesRef, labels.Labels) {
func (a dbAppender) GetRef(lset labels.Labels, hash uint64) (storage.SeriesRef, labels.Labels) {
if g, ok := a.Appender.(storage.GetRef); ok {
return g.GetRef(lset)
return g.GetRef(lset, hash)
}
return 0, nil
}

View File

@ -98,9 +98,9 @@ func (h *Head) initTime(t int64) {
h.maxTime.CompareAndSwap(math.MinInt64, t)
}
func (a *initAppender) GetRef(lset labels.Labels) (storage.SeriesRef, labels.Labels) {
func (a *initAppender) GetRef(lset labels.Labels, hash uint64) (storage.SeriesRef, labels.Labels) {
if g, ok := a.app.(storage.GetRef); ok {
return g.GetRef(lset)
return g.GetRef(lset, hash)
}
return 0, nil
}
@ -647,8 +647,8 @@ func checkHistogramBuckets(buckets []int64) (uint64, error) {
var _ storage.GetRef = &headAppender{}
func (a *headAppender) GetRef(lset labels.Labels) (storage.SeriesRef, labels.Labels) {
s := a.head.series.getByHash(lset.Hash(), lset)
func (a *headAppender) GetRef(lset labels.Labels, hash uint64) (storage.SeriesRef, labels.Labels) {
s := a.head.series.getByHash(hash, lset)
if s == nil {
return 0, nil
}