GetRefByhash will query a label's ref with hash value rather than lset.Hash().

Signed-off-by: tanghengjian <1040104807@qq.com>
This commit is contained in:
tanghengjian 2022-10-24 16:17:45 +08:00 committed by Ganesh Vernekar
parent a5feccae6e
commit 982007ecab
No known key found for this signature in database
GPG key ID: F056451B52F1DC34
3 changed files with 8 additions and 7 deletions

View file

@ -237,7 +237,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

@ -983,9 +983,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

@ -86,9 +86,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
}
@ -455,8 +455,8 @@ func (a *headAppender) UpdateMetadata(ref storage.SeriesRef, lset labels.Labels,
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
}