MCPcopy
hub / github.com/prometheus/prometheus / TestHead_mmapHeadChunks

Function TestHead_mmapHeadChunks

tsdb/head_test.go:8756–9250  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

8754}
8755
8756func TestHead_mmapHeadChunks(t *testing.T) {
8757 // Interval such that one chunk's worth of samples (DefaultSamplesPerChunk) spans DefaultBlockDuration/4.
8758 interval := DefaultBlockDuration / (4 * DefaultSamplesPerChunk)
8759 // Enough samples to cross the nextAt boundary multiple times, producing 3 head chunks per series.
8760 const chunkCutIterations = 2*DefaultSamplesPerChunk + 10
8761
8762 t.Run("basic", func(t *testing.T) {
8763 h, _ := newTestHead(t, DefaultBlockDuration, compression.None, false)
8764 require.NoError(t, h.Init(0))
8765
8766 countReady := func() int {
8767 n := 0
8768 for i := range h.series.size {
8769 h.series.locks[i].RLock()
8770 for _, s := range h.series.series[i] {
8771 if s.headChunkCount.Load() >= 2 {
8772 n++
8773 }
8774 }
8775 h.series.locks[i].RUnlock()
8776 }
8777 return n
8778 }
8779
8780 getCount := func(lbls labels.Labels) uint32 {
8781 s := h.series.getByHash(lbls.Hash(), lbls)
8782 require.NotNil(t, s, "series %s not found", lbls)
8783 return s.headChunkCount.Load()
8784 }
8785
8786 lblsA := labels.FromStrings("__name__", "seriesA")
8787 lblsB := labels.FromStrings("__name__", "seriesB")
8788 lblsC := labels.FromStrings("__name__", "seriesC")
8789
8790 ts := int64(0)
8791
8792 // First chunk creation should set headChunkCount to 1.
8793 app := h.Appender(t.Context())
8794 _, err := app.Append(0, lblsA, ts, 1.0)
8795 require.NoError(t, err)
8796 require.NoError(t, app.Commit())
8797 ts += interval
8798
8799 require.Equal(t, uint32(1), getCount(lblsA), "first chunk should set headChunkCount to 1")
8800 require.Equal(t, 0, countReady(), "series with only a first chunk should not be ready")
8801
8802 // Appending enough samples to trigger chunk cuts should update headChunkCount.
8803 var refB, refC storage.SeriesRef
8804 app = h.Appender(t.Context())
8805 for range chunkCutIterations {
8806 var err error
8807 refB, err = app.Append(refB, lblsB, ts, float64(ts))
8808 require.NoError(t, err)
8809 refC, err = app.Append(refC, lblsC, ts, float64(ts))
8810 require.NoError(t, err)
8811 ts += interval
8812 }
8813 require.NoError(t, app.Commit())

Callers

nothing calls this directly

Calls 15

FromStringsFunction · 0.92
GenerateTestHistogramsFunction · 0.92
SeriesRefTypeAlias · 0.92
newTestHeadFunction · 0.85
InitMethod · 0.80
getByHashMethod · 0.80
mmapHeadChunksMethod · 0.80
LockMethod · 0.80
incMmapReadyMethod · 0.80
appendChunkAndMmapMethod · 0.80
truncateStaleSeriesMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…