Skip to content

Commit b98cc63

Browse files
codesomeSuperQ
authored andcommitted
Restore stale series count from chunk snapshots
Signed-off-by: Ganesh Vernekar <[email protected]>
1 parent c3789ff commit b98cc63

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

tsdb/head_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6988,6 +6988,10 @@ func TestHead_NumStaleSeries(t *testing.T) {
69886988
appendFloatHistogram(series5, 400, staleFH)
69896989
restartHeadAndVerifySeriesCounts(3, 5)
69906990

6991+
// This will test restarting with snapshot.
6992+
head.opts.EnableMemorySnapshotOnShutdown = true
6993+
restartHeadAndVerifySeriesCounts(3, 5)
6994+
69916995
// Test garbage collection behavior - stale series should be decremented when GC'd.
69926996
// Force a garbage collection by truncating old data.
69936997
require.NoError(t, head.Truncate(300))

tsdb/head_wal.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package tsdb
1616
import (
1717
"errors"
1818
"fmt"
19-
"github.com/prometheus/prometheus/model/value"
2019
"maps"
2120
"math"
2221
"os"
@@ -33,6 +32,7 @@ import (
3332
"github.com/prometheus/prometheus/model/histogram"
3433
"github.com/prometheus/prometheus/model/labels"
3534
"github.com/prometheus/prometheus/model/metadata"
35+
"github.com/prometheus/prometheus/model/value"
3636
"github.com/prometheus/prometheus/storage"
3737
"github.com/prometheus/prometheus/tsdb/chunkenc"
3838
"github.com/prometheus/prometheus/tsdb/chunks"
@@ -1607,6 +1607,12 @@ func (h *Head) loadChunkSnapshot() (int, int, map[chunks.HeadSeriesRef]*memSerie
16071607
series.lastHistogramValue = csr.lastHistogramValue
16081608
series.lastFloatHistogramValue = csr.lastFloatHistogramValue
16091609

1610+
if value.IsStaleNaN(series.lastValue) ||
1611+
(series.lastHistogramValue != nil && value.IsStaleNaN(series.lastHistogramValue.Sum)) ||
1612+
(series.lastFloatHistogramValue != nil && value.IsStaleNaN(series.lastFloatHistogramValue.Sum)) {
1613+
h.numStaleSeries.Inc()
1614+
}
1615+
16101616
app, err := series.headChunks.chunk.Appender()
16111617
if err != nil {
16121618
errChan <- err

0 commit comments

Comments
 (0)