MCPcopy Index your code
hub / github.com/cortexproject/cortex / running

Method running

pkg/compactor/compactor.go:786–822  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

784}
785
786func (c *Compactor) running(ctx context.Context) error {
787 // Ensure an initial cleanup occurred as first thing when running compactor.
788 if err := services.StartAndAwaitRunning(ctx, c.blocksCleaner); err != nil {
789 c.ringSubservices.StopAsync()
790 return errors.Wrap(err, "failed to start the blocks cleaner")
791 }
792
793 if c.userIndexUpdater != nil {
794 go c.userIndexUpdateLoop(ctx)
795 }
796
797 // Run an initial compaction before starting the interval.
798 // Insert jitter right before compaction starts to avoid multiple starting compactor to be in sync
799 select {
800 case <-ctx.Done():
801 return ctx.Err()
802 case <-time.After(time.Duration(rand.Int63n(int64(float64(c.compactorCfg.CompactionInterval) * 0.1)))):
803 }
804 c.compactUsers(ctx)
805
806 ticker := time.NewTicker(c.compactorCfg.CompactionInterval)
807 defer ticker.Stop()
808
809 for {
810 select {
811 case <-ticker.C:
812 // Insert jitter right before compaction starts, so that there will always
813 // have jitter even compaction time is longer than CompactionInterval
814 time.Sleep(time.Duration(rand.Int63n(int64(float64(c.compactorCfg.CompactionInterval) * 0.1))))
815 c.compactUsers(ctx)
816 case <-ctx.Done():
817 return nil
818 case err := <-c.ringSubservicesWatcher.Chan():
819 return errors.Wrap(err, "compactor subservice failed")
820 }
821 }
822}
823
824func (c *Compactor) compactUsers(ctx context.Context) {
825 succeeded := false

Callers

nothing calls this directly

Calls 10

userIndexUpdateLoopMethod · 0.95
compactUsersMethod · 0.95
StartAndAwaitRunningFunction · 0.92
DoneMethod · 0.80
AfterMethod · 0.80
ChanMethod · 0.80
StopAsyncMethod · 0.65
WrapMethod · 0.65
ErrMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected