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

Method writeToSecondary

pkg/ring/kv/multi.go:343–369  ·  view source on GitHub ↗
(ctx context.Context, primary kvclient, key string, newValue any)

Source from the content-addressed store, hash-verified

341}
342
343func (m *MultiClient) writeToSecondary(ctx context.Context, primary kvclient, key string, newValue any) {
344 if m.mirrorTimeout > 0 {
345 var cfn context.CancelFunc
346 ctx, cfn = context.WithTimeout(ctx, m.mirrorTimeout)
347 defer cfn()
348 }
349
350 // let's propagate new value to all remaining clients
351 for _, kvc := range m.clients {
352 if kvc == primary {
353 continue
354 }
355
356 m.mirrorWritesCounter.Inc()
357 err := kvc.client.CAS(ctx, key, func(in any) (out any, retry bool, err error) {
358 // try once
359 return newValue, false, nil
360 })
361
362 if err != nil {
363 m.mirrorFailuresCounter.Inc()
364 level.Warn(m.logger).Log("msg", "failed to update value in secondary store", "key", key, "err", err, "primary", primary.name, "secondary", kvc.name)
365 } else {
366 level.Debug(m.logger).Log("msg", "stored updated value to secondary store", "key", key, "primary", primary.name, "secondary", kvc.name)
367 }
368 }
369}

Callers 1

CASMethod · 0.95

Calls 3

CASMethod · 0.65
IncMethod · 0.45
LogMethod · 0.45

Tested by

no test coverage detected