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

Method userIndexUpdateLoop

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

Source from the content-addressed store, hash-verified

1210}
1211
1212func (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
1245const compactorMetaPrefix = "compactor-meta-"
1246

Callers 1

runningMethod · 0.95

Calls 8

ownUserMethod · 0.95
DurationWithJitterFunction · 0.92
DoneMethod · 0.80
UpdateUserIndexMethod · 0.80
StopMethod · 0.65
ErrMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected