db: block MaxTime should not be part of the block

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 <benoit.knecht@fsfe.org>
This commit is contained in:
Benoît Knecht 2018-06-13 14:58:16 +02:00
parent f87d00d78d
commit 0e4be5226a
1 changed files with 7 additions and 1 deletions

8
db.go
View File

@ -360,7 +360,13 @@ func (db *DB) compact() (changes bool, err error) {
head := &rangeHead{ head := &rangeHead{
head: db.head, head: db.head,
mint: mint, 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 { if _, err = db.compactor.Write(db.dir, head, mint, maxt, nil); err != nil {
return changes, errors.Wrap(err, "persist head block") return changes, errors.Wrap(err, "persist head block")