Fix race condition when updating lastSeriesID during loading chunk snapshot (#11099)

Signed-off-by: Xiaochao Dong (@damnever) <the.xcdong@gmail.com>
This commit is contained in:
Xiaochao Dong 2022-08-04 16:09:14 +08:00 committed by GitHub
parent 4035b38c59
commit 1078081aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -921,8 +921,12 @@ func (h *Head) loadChunkSnapshot() (int, int, map[chunks.HeadSeriesRef]*memSerie
return
}
localRefSeries[csr.ref] = series
if chunks.HeadSeriesRef(h.lastSeriesID.Load()) < series.ref {
h.lastSeriesID.Store(uint64(series.ref))
for {
seriesID := uint64(series.ref)
lastSeriesID := h.lastSeriesID.Load()
if lastSeriesID >= seriesID || h.lastSeriesID.CAS(lastSeriesID, seriesID) {
break
}
}
series.chunkRange = csr.chunkRange