MCPcopy Create free account
hub / github.com/cortexproject/cortex / loop

Method loop

pkg/compactor/blocks_cleaner.go:231–303  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

229}
230
231func (c *BlocksCleaner) loop(ctx context.Context) error {
232 t := time.NewTicker(c.cfg.CleanupInterval)
233 defer t.Stop()
234
235 usersChan := make(chan *cleanerJob)
236 deleteChan := make(chan *cleanerJob)
237 defer close(usersChan)
238 defer close(deleteChan)
239
240 go func() {
241 c.runActiveUserCleanup(ctx, usersChan)
242 }()
243 go func() {
244 c.runDeleteUserCleanup(ctx, deleteChan)
245 }()
246 var metricsChan chan *cleanerJob
247 if c.cfg.ShardingStrategy == util.ShardingStrategyShuffle &&
248 c.cfg.CompactionStrategy == util.CompactionStrategyPartitioning {
249 metricsChan = make(chan *cleanerJob)
250 defer close(metricsChan)
251 go func() {
252 c.runEmitPartitionMetricsWorker(ctx, metricsChan)
253 }()
254 }
255
256 for {
257 select {
258 case <-t.C:
259 activeUsers, deletedUsers, err := c.scanUsers(ctx)
260 if err != nil {
261 level.Error(c.logger).Log("msg", "failed to scan users blocks cleanup and maintenance", "err", err.Error())
262 c.runsFailed.WithLabelValues(deletedStatus).Inc()
263 c.runsFailed.WithLabelValues(activeStatus).Inc()
264 continue
265 }
266 cleanJobTimestamp := time.Now().Unix()
267
268 select {
269 case usersChan <- &cleanerJob{
270 users: activeUsers,
271 timestamp: cleanJobTimestamp,
272 }:
273 default:
274 level.Warn(c.logger).Log("msg", "unable to push cleaning job to usersChan")
275 c.enqueueJobFailed.WithLabelValues(activeStatus).Inc()
276 }
277
278 select {
279 case deleteChan <- &cleanerJob{
280 users: deletedUsers,
281 timestamp: cleanJobTimestamp,
282 }:
283 default:
284 level.Warn(c.logger).Log("msg", "unable to push deletion job to deleteChan")
285 c.enqueueJobFailed.WithLabelValues(deletedStatus).Inc()
286 }
287
288 if metricsChan != nil {

Callers

nothing calls this directly

Calls 9

runActiveUserCleanupMethod · 0.95
runDeleteUserCleanupMethod · 0.95
scanUsersMethod · 0.95
DoneMethod · 0.80
StopMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45
IncMethod · 0.45

Tested by

no test coverage detected