@@ -27,22 +27,21 @@ import (
2727
2828 "github.com/rs/zerolog"
2929
30- "github.com/arangodb/go-driver"
31- "github.com/arangodb/go-driver/agency"
32-
3330 api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
3431 "github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
3532 "github.com/arangodb/kube-arangodb/pkg/logging"
33+ "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
3634 "github.com/arangodb/kube-arangodb/pkg/util/errors"
3735 "github.com/arangodb/kube-arangodb/pkg/util/globals"
3836 "github.com/arangodb/kube-arangodb/pkg/util/metrics"
3937)
4038
39+ type Connections map [string ]conn.Connection
40+
4141type health struct {
4242 namespace , name string
4343
4444 leaderID string
45- leader driver.Connection
4645
4746 agencySize int
4847
@@ -52,14 +51,6 @@ type health struct {
5251 election map [string ]int
5352}
5453
55- func (h health ) Leader () (driver.Connection , bool ) {
56- if l := h .leader ; l != nil {
57- return l , true
58- }
59-
60- return nil , false
61- }
62-
6354func (h health ) CollectMetrics (m metrics.PushMetric ) {
6455 if err := h .Serving (); err == nil {
6556 m .Push (metric_descriptions .ArangodbOperatorAgencyCacheServingGauge (1 , h .namespace , h .name ))
@@ -145,14 +136,11 @@ type Health interface {
145136 // LeaderID returns a leader ID or empty string if a leader is not known.
146137 LeaderID () string
147138
148- // Leader returns connection to the Agency leader
149- Leader () (driver.Connection , bool )
150-
151139 CollectMetrics (m metrics.PushMetric )
152140}
153141
154142type Cache interface {
155- Reload (ctx context.Context , size int , clients map [ string ]agency. Agency ) (uint64 , error )
143+ Reload (ctx context.Context , size int , clients Connections ) (uint64 , error )
156144 Data () (State , bool )
157145 DataDB () (StateDB , bool )
158146 CommitIndex () uint64
@@ -206,7 +194,7 @@ func (c cacheSingle) Health() (Health, bool) {
206194 return nil , false
207195}
208196
209- func (c cacheSingle ) Reload (_ context.Context , _ int , _ map [ string ]agency. Agency ) (uint64 , error ) {
197+ func (c cacheSingle ) Reload (_ context.Context , _ int , _ Connections ) (uint64 , error ) {
210198 return 0 , nil
211199}
212200
@@ -278,7 +266,7 @@ func (c *cache) Health() (Health, bool) {
278266 return nil , false
279267}
280268
281- func (c * cache ) Reload (ctx context.Context , size int , clients map [ string ]agency. Agency ) (uint64 , error ) {
269+ func (c * cache ) Reload (ctx context.Context , size int , clients Connections ) (uint64 , error ) {
282270 c .lock .Lock ()
283271 defer c .lock .Unlock ()
284272
@@ -313,7 +301,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
313301 return index , nil
314302}
315303
316- func (c * cache ) reload (ctx context.Context , size int , clients map [ string ]agency. Agency ) (uint64 , error ) {
304+ func (c * cache ) reload (ctx context.Context , size int , clients Connections ) (uint64 , error ) {
317305 leaderCli , leaderConfig , health , err := c .getLeader (ctx , size , clients )
318306 if err != nil {
319307 // Invalidate a leader ID and agency state.
@@ -363,7 +351,7 @@ func (c *cache) ShardsInSyncMap() (ShardsSyncStatus, bool) {
363351
364352// getLeader returns config and client to a leader agency, and health to check if agencies are on the same page.
365353// If there is no quorum for the leader then error is returned.
366- func (c * cache ) getLeader (ctx context.Context , size int , clients map [ string ]agency. Agency ) (agency. Agency , * Config , health , error ) {
354+ func (c * cache ) getLeader (ctx context.Context , size int , clients Connections ) (conn. Connection , * Config , health , error ) {
367355 configs := make ([]* Config , len (clients ))
368356 errs := make ([]error , len (clients ))
369357 names := make ([]string , 0 , len (clients ))
@@ -427,7 +415,6 @@ func (c *cache) getLeader(ctx context.Context, size int, clients map[string]agen
427415
428416 for id := range names {
429417 if h .leaderID == h .names [id ] {
430- h .leader = clients [names [id ]].Connection ()
431418 if cfg := configs [id ]; cfg != nil {
432419 return clients [names [id ]], cfg , h , nil
433420 }
0 commit comments