diff --git a/tsdb/head.go b/tsdb/head.go index f469e5e34..ee7b377f7 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -1149,14 +1149,16 @@ func (h *Head) truncateMemory(mint int64) (err error) { h.memTruncationCallBack() } + // Set the minTime that new queries will see, before waiting for queries to finish. + h.minTime.Store(mint) + // Don't allow samples to be added before this time. + h.minValidTime.Store(mint) + // We wait for pending queries to end that overlap with this truncation. if initialized { h.WaitForPendingReadersInTimeRange(h.MinTime(), mint) } - h.minTime.Store(mint) - h.minValidTime.Store(mint) - // Ensure that max time is at least as high as min time. for h.MaxTime() < mint { h.maxTime.CompareAndSwap(h.MaxTime(), mint)