From aa8874bc5621ac2d76325fb69bdf8d9bf4bd9c99 Mon Sep 17 00:00:00 2001 From: Dieter Plaetinck Date: Thu, 17 Feb 2022 13:00:48 +0200 Subject: [PATCH] clarify Head.appendableMinValidTime (#10303) Signed-off-by: Dieter Plaetinck --- tsdb/head_append.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tsdb/head_append.go b/tsdb/head_append.go index 7cc5c36881..8f1e9bc54a 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -135,10 +135,18 @@ func (h *Head) appender() *headAppender { } } +// appendableMinValidTime returns the minimum valid timestamp for appends, +// such that samples stay ahead of prior blocks and the head compaction window. func (h *Head) appendableMinValidTime() int64 { - // Setting the minimum valid time to whichever is greater, the head min valid time or the compaction window, - // ensures that no samples will be added within the compaction window to avoid races. - return max(h.minValidTime.Load(), h.MaxTime()-h.chunkRange.Load()/2) + // This boundary ensures that no samples will be added to the compaction window. + // This allows race-free, concurrent appending and compaction. + cwEnd := h.MaxTime() - h.chunkRange.Load()/2 + + // This boundary ensures that we avoid overlapping timeframes from one block to the next. + // While not necessary for correctness, it means we're not required to use vertical compaction. + minValid := h.minValidTime.Load() + + return max(cwEnd, minValid) } // AppendableMinValidTime returns the minimum valid time for samples to be appended to the Head.