(ctx context.Context)
| 784 | } |
| 785 | |
| 786 | func (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 | |
| 824 | func (c *Compactor) compactUsers(ctx context.Context) { |
| 825 | succeeded := false |
nothing calls this directly
no test coverage detected