clarify Head.appendableMinValidTime (#10303)

Signed-off-by: Dieter Plaetinck <dieter@grafana.com>
This commit is contained in:
Dieter Plaetinck 2022-02-17 13:00:48 +02:00 committed by GitHub
parent 5a6e26556b
commit aa8874bc56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 { func (h *Head) appendableMinValidTime() int64 {
// Setting the minimum valid time to whichever is greater, the head min valid time or the compaction window, // This boundary ensures that no samples will be added to the compaction window.
// ensures that no samples will be added within the compaction window to avoid races. // This allows race-free, concurrent appending and compaction.
return max(h.minValidTime.Load(), h.MaxTime()-h.chunkRange.Load()/2) 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. // AppendableMinValidTime returns the minimum valid time for samples to be appended to the Head.