From 982007ecabc5aa9708751d09697bdc2082b770ec Mon Sep 17 00:00:00 2001 From: tanghengjian <1040104807@qq.com> Date: Mon, 24 Oct 2022 16:17:45 +0800 Subject: [PATCH] GetRefByhash will query a label's ref with hash value rather than lset.Hash(). Signed-off-by: tanghengjian <1040104807@qq.com> --- storage/interface.go | 3 ++- tsdb/db.go | 4 ++-- tsdb/head_append.go | 8 ++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/storage/interface.go b/storage/interface.go index d73ec7220..3e90b4356 100644 --- a/storage/interface.go +++ b/storage/interface.go @@ -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 diff --git a/tsdb/db.go b/tsdb/db.go index 9adff0b9d..dd2aa1f5f 100644 --- a/tsdb/db.go +++ b/tsdb/db.go @@ -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 } diff --git a/tsdb/head_append.go b/tsdb/head_append.go index f843aa1ec..e67bf21e4 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -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 }