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

Method setNewPrimaryClient

pkg/ring/kv/multi.go:153–183  ·  view source on GitHub ↗

returns true, if primary client has changed

(store string)

Source from the content-addressed store, hash-verified

151
152// returns true, if primary client has changed
153func (m *MultiClient) setNewPrimaryClient(store string) (bool, error) {
154 newPrimaryIx := -1
155 for ix, c := range m.clients {
156 if c.name == store {
157 newPrimaryIx = ix
158 break
159 }
160 }
161
162 if newPrimaryIx < 0 {
163 return false, fmt.Errorf("KV store not found")
164 }
165
166 prev := int(m.primaryID.Swap(int32(newPrimaryIx)))
167 if prev == newPrimaryIx {
168 return false, nil
169 }
170
171 defer m.updatePrimaryStoreGauge() // do as the last thing, after releasing the lock
172
173 // switching to new primary... cancel clients using previous one
174 m.inProgressMu.Lock()
175 defer m.inProgressMu.Unlock()
176
177 for _, inp := range m.inProgress {
178 if inp.client == prev {
179 inp.cancel()
180 }
181 }
182 return true, nil
183}
184
185func (m *MultiClient) registerMetrics(registerer prometheus.Registerer) {
186 m.primaryStoreGauge = promauto.With(registerer).NewGaugeVec(prometheus.GaugeOpts{

Callers 1

watchConfigChannelMethod · 0.95

Calls 2

SwapMethod · 0.45

Tested by

no test coverage detected