mirror of
https://github.com/prometheus/prometheus.git
synced 2025-01-11 22:07:27 -08:00
GetRef() now returns the label set (#8641)
The purpose of GetRef() is to allow Append() to be called without the caller needing to copy the labels. To avoid a race where a series is removed from TSDB between the calls to GetRef() and Append(), we return TSDB's copy of the labels. Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
This commit is contained in:
parent
b524ca8447
commit
c7a62b95ce
|
@ -183,9 +183,10 @@ type Appender interface {
|
|||
// GetRef is an extra interface on Appenders used by downstream projects
|
||||
// (e.g. Cortex) to avoid maintaining a parallel set of references.
|
||||
type GetRef interface {
|
||||
// Returns reference number that can be used to pass to Appender.Append().
|
||||
// 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) uint64
|
||||
GetRef(lset labels.Labels) (uint64, labels.Labels)
|
||||
}
|
||||
|
||||
// ExemplarAppender provides an interface for adding samples to exemplar storage, which
|
||||
|
|
|
@ -797,11 +797,11 @@ type dbAppender struct {
|
|||
|
||||
var _ storage.GetRef = dbAppender{}
|
||||
|
||||
func (a dbAppender) GetRef(lset labels.Labels) uint64 {
|
||||
func (a dbAppender) GetRef(lset labels.Labels) (uint64, labels.Labels) {
|
||||
if g, ok := a.Appender.(storage.GetRef); ok {
|
||||
return g.GetRef(lset)
|
||||
}
|
||||
return 0
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (a dbAppender) Commit() error {
|
||||
|
|
11
tsdb/head.go
11
tsdb/head.go
|
@ -1109,11 +1109,11 @@ func (a *initAppender) AppendExemplar(ref uint64, l labels.Labels, e exemplar.Ex
|
|||
|
||||
var _ storage.GetRef = &initAppender{}
|
||||
|
||||
func (a *initAppender) GetRef(lset labels.Labels) uint64 {
|
||||
func (a *initAppender) GetRef(lset labels.Labels) (uint64, labels.Labels) {
|
||||
if g, ok := a.app.(storage.GetRef); ok {
|
||||
return g.GetRef(lset)
|
||||
}
|
||||
return 0
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (a *initAppender) Commit() error {
|
||||
|
@ -1342,12 +1342,13 @@ func (a *headAppender) AppendExemplar(ref uint64, _ labels.Labels, e exemplar.Ex
|
|||
|
||||
var _ storage.GetRef = &headAppender{}
|
||||
|
||||
func (a *headAppender) GetRef(lset labels.Labels) uint64 {
|
||||
func (a *headAppender) GetRef(lset labels.Labels) (uint64, labels.Labels) {
|
||||
s := a.head.series.getByHash(lset.Hash(), lset)
|
||||
if s == nil {
|
||||
return 0
|
||||
return 0, nil
|
||||
}
|
||||
return s.ref
|
||||
// returned labels must be suitable to pass to Append()
|
||||
return s.ref, s.lset
|
||||
}
|
||||
|
||||
func (a *headAppender) log() error {
|
||||
|
|
Loading…
Reference in a new issue