From 217772752d7685060f0931548e4103580f919e3f Mon Sep 17 00:00:00 2001 From: Jonas Hahnfeld Date: Mon, 26 Nov 2018 22:05:37 +0100 Subject: [PATCH] Fix compaction logic on infrequent cache snapshots This change fixes #10511 that manifests when a shard is considered cold faster than its cache is snapshotted. This can happen if WAL is enabled because previously the code only considered the last modification of compacted tsm1 files. Instead Engine.LastModified() also takes the WAL into account if necessary. --- tsdb/engine/tsm1/engine.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsdb/engine/tsm1/engine.go b/tsdb/engine/tsm1/engine.go index 7d83e64217..af7fcf16ae 100644 --- a/tsdb/engine/tsm1/engine.go +++ b/tsdb/engine/tsm1/engine.go @@ -1971,7 +1971,7 @@ func (e *Engine) compact(wg *sync.WaitGroup) { level1Groups := e.CompactionPlan.PlanLevel(1) level2Groups := e.CompactionPlan.PlanLevel(2) level3Groups := e.CompactionPlan.PlanLevel(3) - level4Groups := e.CompactionPlan.Plan(e.FileStore.LastModified()) + level4Groups := e.CompactionPlan.Plan(e.LastModified()) atomic.StoreInt64(&e.stats.TSMOptimizeCompactionsQueue, int64(len(level4Groups))) // If no full compactions are need, see if an optimize is needed