From ca9688131b4ed905befd9aa17d47648f14cc82ff Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Fri, 27 Jun 2025 08:29:02 -0700 Subject: [PATCH] POC for compacting earlier than 1.5x of block size Signed-off-by: Ganesh Vernekar --- tsdb/head.go | 4 +++- tsdb/head_append.go | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tsdb/head.go b/tsdb/head.go index 7763d272b7..c2a1dc0c0e 100644 --- a/tsdb/head.go +++ b/tsdb/head.go @@ -62,6 +62,8 @@ var ( defaultIsolationDisabled = false defaultWALReplayConcurrency = runtime.GOMAXPROCS(0) + + compactibleRatio = 1.1 ) // Head handles reads and writes of time series data within a time window. @@ -1700,7 +1702,7 @@ func (h *Head) compactable() bool { return false } - return h.MaxTime()-h.MinTime() > h.chunkRange.Load()/2*3 + return h.MaxTime()-h.MinTime() > int64(float64(h.chunkRange.Load())*compactibleRatio) } // Close flushes the WAL and closes the head. diff --git a/tsdb/head_append.go b/tsdb/head_append.go index 03800b2455..4a680f4d03 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -194,7 +194,7 @@ func (h *Head) appender() *headAppender { func (h *Head) appendableMinValidTime() int64 { // 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 + cwEnd := h.MaxTime() - int64(float64(h.chunkRange.Load())*(compactibleRatio-1)) // 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.