Skip to content

Commit 5257503

Browse files
authored
Ingester: compact ooo head during head compaction (#6108)
Signed-off-by: Ben Ye <[email protected]>
1 parent b167dd4 commit 5257503

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

pkg/ingester/ingester.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ func (u *userTSDB) casState(from, to tsdbState) bool {
360360
}
361361

362362
// compactHead compacts the Head block at specified block durations avoiding a single huge block.
363-
func (u *userTSDB) compactHead(blockDuration int64) error {
363+
func (u *userTSDB) compactHead(ctx context.Context, blockDuration int64) error {
364364
if !u.casState(active, forceCompacting) {
365365
return errors.New("TSDB head cannot be compacted because it is not in active state (possibly being closed or blocks shipping in progress)")
366366
}
@@ -388,7 +388,10 @@ func (u *userTSDB) compactHead(blockDuration int64) error {
388388
minTime, maxTime = h.MinTime(), h.MaxTime()
389389
}
390390

391-
return u.db.CompactHead(tsdb.NewRangeHead(h, minTime, maxTime))
391+
if err := u.db.CompactHead(tsdb.NewRangeHead(h, minTime, maxTime)); err != nil {
392+
return err
393+
}
394+
return u.db.CompactOOOHead(ctx)
392395
}
393396

394397
// PreCreation implements SeriesLifecycleCallback interface.
@@ -2536,12 +2539,12 @@ func (i *Ingester) compactBlocks(ctx context.Context, force bool, allowed *util.
25362539
switch {
25372540
case force:
25382541
reason = "forced"
2539-
err = userDB.compactHead(i.cfg.BlocksStorageConfig.TSDB.BlockRanges[0].Milliseconds())
2542+
err = userDB.compactHead(ctx, i.cfg.BlocksStorageConfig.TSDB.BlockRanges[0].Milliseconds())
25402543

25412544
case i.TSDBState.compactionIdleTimeout > 0 && userDB.isIdle(time.Now(), i.TSDBState.compactionIdleTimeout):
25422545
reason = "idle"
25432546
level.Info(logutil.WithContext(ctx, i.logger)).Log("msg", "TSDB is idle, forcing compaction", "user", userID)
2544-
err = userDB.compactHead(i.cfg.BlocksStorageConfig.TSDB.BlockRanges[0].Milliseconds())
2547+
err = userDB.compactHead(ctx, i.cfg.BlocksStorageConfig.TSDB.BlockRanges[0].Milliseconds())
25452548

25462549
default:
25472550
reason = "regular"

0 commit comments

Comments
 (0)