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)
| 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. |
| 2115 | func 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 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…