Skip to content

Fix some cases where flush reason is recorded as 'Immediate' #2022

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 2 commits into from
Jan 23, 2020
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
17 changes: 10 additions & 7 deletions pkg/ingester/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ func (i *Ingester) sweepSeries(userID string, fp model.Fingerprint, series *memo
}

func (i *Ingester) shouldFlushSeries(series *memorySeries, fp model.Fingerprint, immediate bool) flushReason {
if len(series.chunkDescs) == 0 {
return noFlush
}
if immediate {
return reasonImmediate
}
Expand All @@ -203,12 +206,9 @@ func (i *Ingester) shouldFlushSeries(series *memorySeries, fp model.Fingerprint,
return series.chunkDescs[0].flushReason
}
return reasonMultipleChunksInSeries
} else if len(series.chunkDescs) > 0 {
// Otherwise look in more detail at the first chunk
return i.shouldFlushChunk(series.chunkDescs[0], fp, series.isStale())
}

return noFlush
// Otherwise look in more detail at the first chunk
return i.shouldFlushChunk(series.chunkDescs[0], fp, series.isStale())
}

func (i *Ingester) shouldFlushChunk(c *desc, fp model.Fingerprint, lastValueIsStale bool) flushReason {
Expand Down Expand Up @@ -290,11 +290,14 @@ func (i *Ingester) flushUserSeries(flushQueueIndex int, userID string, fp model.
return nil
}

// Assume we're going to flush everything, and maybe don't flush the head chunk if it doesn't need it.
// shouldFlushSeries() has told us we have at least one chunk
chunks := series.chunkDescs
if immediate || (len(chunks) > 0 && i.shouldFlushChunk(series.head(), fp, series.isStale()) != noFlush) {
if immediate {
series.closeHead(reasonImmediate)
} else if chunkReason := i.shouldFlushChunk(series.head(), fp, series.isStale()); chunkReason != noFlush {
series.closeHead(chunkReason)
} else {
// The head chunk doesn't need flushing; step back by one.
chunks = chunks[:len(chunks)-1]
}

Expand Down