Skip to content

Commit

Permalink
Fix race condition when updating lastSeriesID during loading chunk sn…
Browse files Browse the repository at this point in the history
…apshot

Signed-off-by: Xiaochao Dong (@damnever) <the.xcdong@gmail.com>
  • Loading branch information
damnever committed Aug 3, 2022
1 parent a23e950 commit f7b46a3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tsdb/head_wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f7b46a3

Please sign in to comment.