From 0e4be5226af22760a12c10d744f8b4f6efbbca2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Knecht?= Date: Wed, 13 Jun 2018 14:58:16 +0200 Subject: [PATCH] db: block MaxTime should not be part of the block MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Block intervals are bound by `block.MinTime`, `block.MaxTime`, but they define a half-open interval: `[block.MinTime, block.MaxTime). However, when deciding if a chunk was part of a block or not, the `intervalOverlap()` function would consider both the chunk and the block intervals as being closed. Rather than modify the login in `intervalOverlap()`, we explicitly remove the last value from the interval when reading from head to persist blocks. Signed-off-by: BenoƮt Knecht --- db.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/db.go b/db.go index 28fafc09b..fa871ebbd 100644 --- a/db.go +++ b/db.go @@ -360,7 +360,13 @@ func (db *DB) compact() (changes bool, err error) { head := &rangeHead{ head: db.head, mint: mint, - maxt: maxt, + // We remove 1 millisecond from maxt because block + // intervals are half-open: [b.MinTime, b.MaxTime). But + // chunk intervals are closed: [c.MinTime, c.MaxTime]; + // so in order to make sure that overlaps are evaluated + // consistently, we explicitly remove the last value + // from the block interval here. + maxt: maxt - 1, } if _, err = db.compactor.Write(db.dir, head, mint, maxt, nil); err != nil { return changes, errors.Wrap(err, "persist head block")