MCPcopy
hub / github.com/grafana/dskit / watchConfigChannel

Method watchConfigChannel

kv/multi.go:115–146  ·  view source on GitHub ↗
(ctx context.Context, configChannel <-chan MultiRuntimeConfig)

Source from the content-addressed store, hash-verified

113}
114
115func (m *MultiClient) watchConfigChannel(ctx context.Context, configChannel <-chan MultiRuntimeConfig) {
116 for {
117 select {
118 case cfg, ok := <-configChannel:
119 if !ok {
120 return
121 }
122
123 if cfg.Mirroring != nil {
124 enabled := *cfg.Mirroring
125 old := m.mirroringEnabled.Swap(enabled)
126 if old != enabled {
127 level.Info(m.logger).Log("msg", "toggled mirroring", "enabled", enabled)
128 }
129 m.updateMirrorEnabledGauge()
130 }
131
132 if cfg.PrimaryStore != "" {
133 switched, err := m.setNewPrimaryClient(cfg.PrimaryStore)
134 if switched {
135 level.Info(m.logger).Log("msg", "switched primary KV store", "primary", cfg.PrimaryStore)
136 }
137 if err != nil {
138 level.Error(m.logger).Log("msg", "failed to switch primary KV store", "primary", cfg.PrimaryStore, "err", err)
139 }
140 }
141
142 case <-ctx.Done():
143 return
144 }
145 }
146}
147
148func (m *MultiClient) getPrimaryClient() (int, kvclient) {
149 v := m.primaryID.Load()

Callers 1

NewMultiClientFunction · 0.95

Calls 6

setNewPrimaryClientMethod · 0.95
DoneMethod · 0.65
SwapMethod · 0.45
LogMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected