MultiClient implements kv.Client by forwarding all API calls to primary client. Writes performed via CAS method are also (optionally) forwarded to secondary clients.
| 57 | // MultiClient implements kv.Client by forwarding all API calls to primary client. |
| 58 | // Writes performed via CAS method are also (optionally) forwarded to secondary clients. |
| 59 | type MultiClient struct { |
| 60 | // Available KV clients |
| 61 | clients []kvclient |
| 62 | |
| 63 | mirrorTimeout time.Duration |
| 64 | mirroringEnabled *atomic.Bool |
| 65 | |
| 66 | // logger with "multikv" component |
| 67 | logger log.Logger |
| 68 | |
| 69 | // The primary client used for interaction. |
| 70 | primaryID *atomic.Int32 |
| 71 | |
| 72 | cancel context.CancelFunc |
| 73 | |
| 74 | inProgressMu sync.Mutex |
| 75 | // Cancel functions for ongoing operations. key is a value from inProgressCnt. |
| 76 | // What we really need is a []context.CancelFunc, but functions cannot be compared against each other using ==, |
| 77 | // so we use this map instead. |
| 78 | inProgress map[int]clientInProgress |
| 79 | inProgressCnt int |
| 80 | |
| 81 | primaryStoreGauge *prometheus.GaugeVec |
| 82 | mirrorEnabledGauge prometheus.Gauge |
| 83 | mirrorWritesCounter prometheus.Counter |
| 84 | mirrorFailuresCounter prometheus.Counter |
| 85 | } |
| 86 | |
| 87 | // NewMultiClient creates new MultiClient with given KV Clients. |
| 88 | // First client in the slice is the primary client. |
nothing calls this directly
no outgoing calls
no test coverage detected