Skip to content
This repository has been archived by the owner on Aug 13, 2019. It is now read-only.

Commit

Permalink
fix race for minValidTime (#479)
Browse files Browse the repository at this point in the history
it happens when truncating the WAL and another goroutine creates a new
Appender()

Signed-off-by: Krasi Georgiev <[email protected]>
  • Loading branch information
krasi-georgiev authored Dec 14, 2018
1 parent 79aa611 commit 79869d9
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions head.go
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ func (h *Head) Truncate(mint int64) (err error) {
return nil
}
atomic.StoreInt64(&h.minTime, mint)
h.minValidTime = mint
atomic.StoreInt64(&h.minValidTime, mint)

// Ensure that max time is at least as high as min time.
for h.MaxTime() < mint {
Expand Down Expand Up @@ -656,7 +656,7 @@ func (h *Head) appender() *headAppender {
head: h,
// Set the minimum valid time to whichever is greater the head min valid time or the compaciton window.
// This ensures that no samples will be added within the compaction window to avoid races.
minValidTime: max(h.minValidTime, h.MaxTime()-h.chunkRange/2),
minValidTime: max(atomic.LoadInt64(&h.minValidTime), h.MaxTime()-h.chunkRange/2),
mint: math.MaxInt64,
maxt: math.MinInt64,
samples: h.getAppendBuffer(),
Expand Down

0 comments on commit 79869d9

Please sign in to comment.