(ctx context.Context)
| 1210 | } |
| 1211 | |
| 1212 | func (c *Compactor) userIndexUpdateLoop(ctx context.Context) { |
| 1213 | // Hardcode ID to check which compactor owns updating user index. |
| 1214 | userID := users.UserIndexCompressedFilename |
| 1215 | // Align with clean up interval. |
| 1216 | ticker := time.NewTicker(util.DurationWithJitter(c.storageCfg.UsersScanner.UpdateInterval, 0.1)) |
| 1217 | defer ticker.Stop() |
| 1218 | |
| 1219 | for { |
| 1220 | select { |
| 1221 | case <-ctx.Done(): |
| 1222 | level.Error(c.logger).Log("msg", "context timeout, exit user index update loop", "err", ctx.Err()) |
| 1223 | return |
| 1224 | case <-ticker.C: |
| 1225 | owned, err := c.ownUser(userID, true) |
| 1226 | if err != nil { |
| 1227 | level.Error(c.logger).Log("msg", "failed to check if compactor owns updating user index", "err", err) |
| 1228 | // Wait for next interval. Worst case, the user index scanner will fallback to list strategy. |
| 1229 | continue |
| 1230 | } |
| 1231 | if !owned { |
| 1232 | continue |
| 1233 | } |
| 1234 | start := time.Now() |
| 1235 | if err := c.userIndexUpdater.UpdateUserIndex(ctx); err != nil { |
| 1236 | level.Error(c.logger).Log("msg", "failed to update user index", "err", err) |
| 1237 | // Wait for next interval. Worst case, the user index scanner will fallback to list strategy. |
| 1238 | continue |
| 1239 | } |
| 1240 | level.Info(c.logger).Log("msg", "successfully updated user index", "duration_ms", time.Since(start).Milliseconds()) |
| 1241 | } |
| 1242 | } |
| 1243 | } |
| 1244 | |
| 1245 | const compactorMetaPrefix = "compactor-meta-" |
| 1246 |
no test coverage detected