Skip to content

Commit

Permalink
Add a EnableBiggerOOOBlockForOldSamples option for the TSDB (#763)
Browse files Browse the repository at this point in the history
Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com>
  • Loading branch information
codesome authored and colega committed Nov 29, 2024
1 parent 7e232f3 commit 36ed32c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
27 changes: 17 additions & 10 deletions tsdb/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ type Options struct {
// OOO Native Histogram ingestion is complete.
EnableOOONativeHistograms bool

// EnableBiggerOOOBlockForOldSamples enables building 24h blocks for the OOO samples
// that belong to the previous day. This is in-line with Mimir maintaining 24h blocks
// for the previous days.
EnableBiggerOOOBlockForOldSamples bool

// OutOfOrderTimeWindow specifies how much out of order is allowed, if any.
// This can change during run-time, so this value from here should only be used
// while initialising.
Expand Down Expand Up @@ -1513,19 +1518,21 @@ func (db *DB) compactOOO(dest string, oooHead *OOOCompactionHead) (_ []ulid.ULID
return nil
}

day := 24 * time.Hour.Milliseconds()
maxtFor24hBlock := day * (db.Head().MaxTime() / day)
oooStart := oooHeadMint
if db.opts.EnableBiggerOOOBlockForOldSamples {
day := 24 * time.Hour.Milliseconds()
maxtFor24hBlock := day * (db.Head().MaxTime() / day)

// 24h blocks for data that is for the previous days
for t := day * (oooHeadMint / day); t < maxtFor24hBlock; t += day {
if err := runCompaction(t, t+day); err != nil {
return nil, err
// 24h blocks for data that is for the previous days
for t := day * (oooHeadMint / day); t < maxtFor24hBlock; t += day {
if err := runCompaction(t, t+day); err != nil {
return nil, err
}
}
}

oooStart := oooHeadMint
if oooStart < maxtFor24hBlock {
oooStart = maxtFor24hBlock
if oooStart < maxtFor24hBlock {
oooStart = maxtFor24hBlock
}
}
for t := blockSize * (oooStart / blockSize); t <= oooHeadMaxt; t += blockSize {
if err := runCompaction(t, t+blockSize); err != nil {
Expand Down
1 change: 1 addition & 0 deletions tsdb/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8987,6 +8987,7 @@ func TestBiggerBlocksForOldOOOData(t *testing.T) {

opts := DefaultOptions()
opts.OutOfOrderTimeWindow = 10 * day
opts.EnableBiggerOOOBlockForOldSamples = true
db := openTestDB(t, opts, nil)
db.DisableCompactions()
t.Cleanup(func() {
Expand Down

0 comments on commit 36ed32c

Please sign in to comment.