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

Method WatchKey

pkg/ring/kv/dynamodb/client.go:233–278  ·  view source on GitHub ↗
(ctx context.Context, key string, f func(any) bool)

Source from the content-addressed store, hash-verified

231}
232
233func (c *Client) WatchKey(ctx context.Context, key string, f func(any) bool) {
234 watchBackoffConfig := c.backoffConfig
235 watchBackoffConfig.MaxRetries = 0
236 bo := backoff.New(ctx, watchBackoffConfig)
237 syncTimer := time.NewTimer(c.pullerSyncTime)
238 defer syncTimer.Stop()
239
240 for bo.Ongoing() {
241 out, _, err := c.kv.Query(ctx, dynamodbKey{
242 primaryKey: key,
243 }, false)
244 if err != nil {
245 level.Error(c.logger).Log("msg", "error WatchKey", "key", key, "err", err)
246
247 if bo.NumRetries() >= 10 {
248 level.Error(c.logger).Log("msg", "failed to WatchKey after retries", "key", key, "err", err)
249 if staleData := c.getStaleData(key); staleData != nil {
250 if !f(staleData) {
251 return
252 }
253 }
254 }
255 bo.Wait()
256 continue
257 }
258
259 decoded, err := c.decodeMultikey(out)
260 if err != nil {
261 level.Error(c.logger).Log("msg", "error decoding key", "key", key, "err", err)
262 continue
263 }
264 c.updateStaleData(key, decoded, time.Now().UTC())
265
266 if !f(decoded) {
267 return
268 }
269
270 bo.Reset()
271 utiltimer.ResetTimer(syncTimer, c.pullerSyncTime)
272 select {
273 case <-ctx.Done():
274 return
275 case <-syncTimer.C:
276 }
277 }
278}
279
280func (c *Client) WatchPrefix(ctx context.Context, prefix string, f func(string, any) bool) {
281 watchBackoffConfig := c.backoffConfig

Callers

nothing calls this directly

Calls 13

getStaleDataMethod · 0.95
decodeMultikeyMethod · 0.95
updateStaleDataMethod · 0.95
NewFunction · 0.92
OngoingMethod · 0.80
NumRetriesMethod · 0.80
DoneMethod · 0.80
StopMethod · 0.65
QueryMethod · 0.65
LogMethod · 0.45
ErrorMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected