From d32eb25662b6e58042566aebbd0f53661b935353 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Sat, 20 May 2017 13:21:10 +0530 Subject: [PATCH] Synchronise deletes and compactions. Signed-off-by: Goutham Veeramachaneni --- db.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/db.go b/db.go index 855a5af6e..b3b055844 100644 --- a/db.go +++ b/db.go @@ -125,6 +125,9 @@ type DB struct { compactc chan struct{} donec chan struct{} stopc chan struct{} + + // compMtx is used to control compactions and deletions. + cmtx sync.Mutex } type dbMetrics struct { @@ -271,6 +274,9 @@ func (db *DB) retentionCutoff() (bool, error) { } func (db *DB) compact() (changes bool, err error) { + db.cmtx.Lock() + defer db.cmtx.Unlock() + db.headmtx.RLock() // Check whether we have pending head blocks that are ready to be persisted. @@ -671,14 +677,13 @@ func (a *dbAppender) Rollback() error { // Delete implements deletion of metrics. func (db *DB) Delete(mint, maxt int64, ms ...labels.Matcher) error { - s.mtx.RLock() + db.cmtx.Lock() + defer db.cmtx.Unlock() s.headmtx.RLock() blocks := s.blocksForInterval(mint, maxt) s.headmtx.RUnlock() - // TODO(gouthamve): Wait for pending compactions and stop compactions until - // delete finishes. var g errgroup.Group for _, b := range blocks {