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