From 6c4217276f4ae3a3124d63ff5ee0486bf252a6c0 Mon Sep 17 00:00:00 2001 From: Fabian Reinartz Date: Tue, 28 Feb 2017 15:08:52 +0100 Subject: [PATCH] Periodically trigger compaction This addresses an issue where the compaction triggered on cutting a new block doesn't find anything as the writers are still active on the block that should be ready for compaction. --- db.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/db.go b/db.go index 001509d5d..fb7dedacf 100644 --- a/db.go +++ b/db.go @@ -187,8 +187,16 @@ func Open(dir string, l log.Logger, r prometheus.Registerer, opts *Options) (db func (db *DB) run() { defer close(db.donec) + tick := time.NewTicker(30 * time.Second) + defer tick.Stop() + for { select { + case <-tick.C: + select { + case db.compactc <- struct{}{}: + default: + } case <-db.compactc: db.metrics.compactionsTriggered.Inc()