mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Add fast past to validation after lock switch
This commit is contained in:
parent
1b39887baa
commit
5e028710d5
12
head.go
12
head.go
|
@ -298,31 +298,33 @@ func (h *headBlock) appendBatch(samples []hashedSample) (int, error) {
|
||||||
// be no further failures.
|
// be no further failures.
|
||||||
if len(newSeries) > 0 {
|
if len(newSeries) > 0 {
|
||||||
newLabels = make([]labels.Labels, 0, len(newSeries))
|
newLabels = make([]labels.Labels, 0, len(newSeries))
|
||||||
|
base0 := len(h.series)
|
||||||
|
|
||||||
h.mtx.RUnlock()
|
h.mtx.RUnlock()
|
||||||
h.mtx.Lock()
|
h.mtx.Lock()
|
||||||
|
|
||||||
base := len(h.series)
|
base1 := len(h.series)
|
||||||
i := 0
|
i := 0
|
||||||
|
|
||||||
for hash, ser := range newSeries {
|
for hash, ser := range newSeries {
|
||||||
lset := ser[0].labels
|
lset := ser[0].labels
|
||||||
// We switched locks and have to re-validate that the series were not
|
// We switched locks and have to re-validate that the series were not
|
||||||
// created by another goroutine in the meantime.
|
// created by another goroutine in the meantime.
|
||||||
ms := h.get(hash, lset)
|
if base1 != base0 {
|
||||||
if ms != nil {
|
if ms := h.get(hash, lset); ms != nil {
|
||||||
for _, s := range ser {
|
for _, s := range ser {
|
||||||
s.ref = ms.ref
|
s.ref = ms.ref
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// Series is still new.
|
// Series is still new.
|
||||||
newLabels = append(newLabels, lset)
|
newLabels = append(newLabels, lset)
|
||||||
|
|
||||||
h.create(hash, lset)
|
h.create(hash, lset)
|
||||||
// Set sample references to the series we just created.
|
// Set sample references to the series we just created.
|
||||||
for _, s := range ser {
|
for _, s := range ser {
|
||||||
s.ref = uint32(base + i)
|
s.ref = uint32(base1 + i)
|
||||||
}
|
}
|
||||||
i++
|
i++
|
||||||
}
|
}
|
||||||
|
@ -343,9 +345,11 @@ func (h *headBlock) appendBatch(samples []hashedSample) (int, error) {
|
||||||
)
|
)
|
||||||
for _, s := range samples {
|
for _, s := range samples {
|
||||||
ser := h.series[s.ref]
|
ser := h.series[s.ref]
|
||||||
|
|
||||||
ser.mtx.Lock()
|
ser.mtx.Lock()
|
||||||
ok := ser.append(s.t, s.v)
|
ok := ser.append(s.t, s.v)
|
||||||
ser.mtx.Unlock()
|
ser.mtx.Unlock()
|
||||||
|
|
||||||
if !ok {
|
if !ok {
|
||||||
total--
|
total--
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue