Skip to content

Commit 62efd50

Browse files
authored
Fix some cases where flush reason is recorded as 'Immediate' (#2022)
* Make sure we return noFlush on an empty series Signed-off-by: Bryan Boreham <bryan@weave.works> * Pass the correct flush reason to closeHead() Pass the reason from `shouldFlushChunk()` to `closeHead()`; sending `reasonImmediate` was a bug. We don't need to check `len(chunks)` is non-zero, since that would return `noFlush` from `shouldFlushSeries()`. Signed-off-by: Bryan Boreham <bryan@weave.works>
1 parent ab3e836 commit 62efd50

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/ingester/flush.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ func (i *Ingester) sweepSeries(userID string, fp model.Fingerprint, series *memo
193193
}
194194

195195
func (i *Ingester) shouldFlushSeries(series *memorySeries, fp model.Fingerprint, immediate bool) flushReason {
196+
if len(series.chunkDescs) == 0 {
197+
return noFlush
198+
}
196199
if immediate {
197200
return reasonImmediate
198201
}
@@ -203,12 +206,9 @@ func (i *Ingester) shouldFlushSeries(series *memorySeries, fp model.Fingerprint,
203206
return series.chunkDescs[0].flushReason
204207
}
205208
return reasonMultipleChunksInSeries
206-
} else if len(series.chunkDescs) > 0 {
207-
// Otherwise look in more detail at the first chunk
208-
return i.shouldFlushChunk(series.chunkDescs[0], fp, series.isStale())
209209
}
210-
211-
return noFlush
210+
// Otherwise look in more detail at the first chunk
211+
return i.shouldFlushChunk(series.chunkDescs[0], fp, series.isStale())
212212
}
213213

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

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

0 commit comments

Comments
 (0)