Skip to content

Ingester: compact ooo head during head compaction #6108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions pkg/ingester/ingester.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (u *userTSDB) casState(from, to tsdbState) bool {
}

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

return u.db.CompactHead(tsdb.NewRangeHead(h, minTime, maxTime))
if err := u.db.CompactHead(tsdb.NewRangeHead(h, minTime, maxTime)); err != nil {
return err
}
return u.db.CompactOOOHead(ctx)
}

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

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

default:
reason = "regular"
Expand Down
Loading