MCPcopy
hub / github.com/prometheus/prometheus / TestDelayedCompactionDoesNotBlockUnrelatedOps

Function TestDelayedCompactionDoesNotBlockUnrelatedOps

tsdb/compact_test.go:2115–2173  ·  view source on GitHub ↗

TestDelayedCompactionDoesNotBlockUnrelatedOps makes sure that when delayed compaction is enabled, operations that don't directly derive from the Head compaction are not delayed, here we consider disk blocks compaction.

(t *testing.T)

Source from the content-addressed store, hash-verified

2113// TestDelayedCompactionDoesNotBlockUnrelatedOps makes sure that when delayed compaction is enabled,
2114// operations that don't directly derive from the Head compaction are not delayed, here we consider disk blocks compaction.
2115func TestDelayedCompactionDoesNotBlockUnrelatedOps(t *testing.T) {
2116 t.Parallel()
2117 cases := []struct {
2118 name string
2119 whenCompactable bool
2120 }{
2121 {
2122 "Head is compactable",
2123 true,
2124 },
2125 {
2126 "Head is not compactable",
2127 false,
2128 },
2129 }
2130
2131 for _, c := range cases {
2132 t.Run(c.name, func(t *testing.T) {
2133 t.Parallel()
2134
2135 tmpdir := t.TempDir()
2136 // Some blocks that need compaction are present.
2137 createBlock(t, tmpdir, genSeries(1, 1, 0, 100))
2138 createBlock(t, tmpdir, genSeries(1, 1, 100, 200))
2139 createBlock(t, tmpdir, genSeries(1, 1, 200, 300))
2140
2141 options := DefaultOptions()
2142 // This will make the test timeout if compaction really waits for it.
2143 options.CompactionDelay = time.Hour
2144 db, err := open(tmpdir, promslog.NewNopLogger(), nil, options, []int64{10, 200}, nil)
2145 require.NoError(t, err)
2146 defer func() {
2147 require.NoError(t, db.Close())
2148 }()
2149
2150 db.DisableCompactions()
2151 require.Len(t, db.Blocks(), 3)
2152
2153 if c.whenCompactable {
2154 label := labels.FromStrings("foo", "bar")
2155 app := db.Appender(context.Background())
2156 _, err := app.Append(0, label, 301, 0)
2157 require.NoError(t, err)
2158 _, err = app.Append(0, label, 317, 0)
2159 require.NoError(t, err)
2160 require.NoError(t, app.Commit())
2161 // The Head is compactable and will still be at the end.
2162 require.True(t, db.head.compactable())
2163 defer func() {
2164 require.True(t, db.head.compactable())
2165 }()
2166 }
2167
2168 // The blocks were compacted.
2169 db.Compact(context.Background())
2170 require.Len(t, db.Blocks(), 2)
2171 })
2172 }

Callers

nothing calls this directly

Calls 15

FromStringsFunction · 0.92
createBlockFunction · 0.85
genSeriesFunction · 0.85
openFunction · 0.85
DisableCompactionsMethod · 0.80
compactableMethod · 0.80
DefaultOptionsFunction · 0.70
RunMethod · 0.65
CloseMethod · 0.65
LenMethod · 0.65
AppenderMethod · 0.65
AppendMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…