From bdb0264b3588c4ecbad068112275a9b4b2f41602 Mon Sep 17 00:00:00 2001 From: Ganesh Vernekar Date: Thu, 23 Jan 2020 12:52:33 +0530 Subject: [PATCH] Squashed commit of the PR #2022: commit df8b95f2109b6fd27212a01b69a42e2518834849 Author: Bryan Boreham Date: Wed Jan 22 13:52:44 2020 +0000 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 commit 17c0c21e4f964140eb1b651392d05b72a327dda2 Author: Bryan Boreham Date: Wed Jan 22 13:45:22 2020 +0000 Make sure we return noFlush on an empty series Signed-off-by: Bryan Boreham Signed-off-by: Ganesh Vernekar --- pkg/ingester/flush.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/pkg/ingester/flush.go b/pkg/ingester/flush.go index 49b229229e..3b73e1ffa7 100644 --- a/pkg/ingester/flush.go +++ b/pkg/ingester/flush.go @@ -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 } @@ -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 { @@ -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] }