From 79869d9a4d3d29c494d626aa626724688bbcbe3d Mon Sep 17 00:00:00 2001 From: Krasi Georgiev Date: Fri, 14 Dec 2018 14:42:07 +0300 Subject: [PATCH] fix race for minValidTime (#479) it happens when truncating the WAL and another goroutine creates a new Appender() Signed-off-by: Krasi Georgiev --- head.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/head.go b/head.go index 4d917291a..a3e23c03a 100644 --- a/head.go +++ b/head.go @@ -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 { @@ -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(),