@@ -27,22 +27,21 @@ import (
27
27
28
28
"github.com/rs/zerolog"
29
29
30
- "github.com/arangodb/go-driver"
31
- "github.com/arangodb/go-driver/agency"
32
-
33
30
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
34
31
"github.com/arangodb/kube-arangodb/pkg/generated/metric_descriptions"
35
32
"github.com/arangodb/kube-arangodb/pkg/logging"
33
+ "github.com/arangodb/kube-arangodb/pkg/util/arangod/conn"
36
34
"github.com/arangodb/kube-arangodb/pkg/util/errors"
37
35
"github.com/arangodb/kube-arangodb/pkg/util/globals"
38
36
"github.com/arangodb/kube-arangodb/pkg/util/metrics"
39
37
)
40
38
39
+ type Connections map [string ]conn.Connection
40
+
41
41
type health struct {
42
42
namespace , name string
43
43
44
44
leaderID string
45
- leader driver.Connection
46
45
47
46
agencySize int
48
47
@@ -52,14 +51,6 @@ type health struct {
52
51
election map [string ]int
53
52
}
54
53
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
-
63
54
func (h health ) CollectMetrics (m metrics.PushMetric ) {
64
55
if err := h .Serving (); err == nil {
65
56
m .Push (metric_descriptions .ArangodbOperatorAgencyCacheServingGauge (1 , h .namespace , h .name ))
@@ -145,14 +136,11 @@ type Health interface {
145
136
// LeaderID returns a leader ID or empty string if a leader is not known.
146
137
LeaderID () string
147
138
148
- // Leader returns connection to the Agency leader
149
- Leader () (driver.Connection , bool )
150
-
151
139
CollectMetrics (m metrics.PushMetric )
152
140
}
153
141
154
142
type 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 )
156
144
Data () (State , bool )
157
145
DataDB () (StateDB , bool )
158
146
CommitIndex () uint64
@@ -206,7 +194,7 @@ func (c cacheSingle) Health() (Health, bool) {
206
194
return nil , false
207
195
}
208
196
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 ) {
210
198
return 0 , nil
211
199
}
212
200
@@ -278,7 +266,7 @@ func (c *cache) Health() (Health, bool) {
278
266
return nil , false
279
267
}
280
268
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 ) {
282
270
c .lock .Lock ()
283
271
defer c .lock .Unlock ()
284
272
@@ -313,7 +301,7 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
313
301
return index , nil
314
302
}
315
303
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 ) {
317
305
leaderCli , leaderConfig , health , err := c .getLeader (ctx , size , clients )
318
306
if err != nil {
319
307
// Invalidate a leader ID and agency state.
@@ -363,7 +351,7 @@ func (c *cache) ShardsInSyncMap() (ShardsSyncStatus, bool) {
363
351
364
352
// getLeader returns config and client to a leader agency, and health to check if agencies are on the same page.
365
353
// 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 ) {
367
355
configs := make ([]* Config , len (clients ))
368
356
errs := make ([]error , len (clients ))
369
357
names := make ([]string , 0 , len (clients ))
@@ -427,7 +415,6 @@ func (c *cache) getLeader(ctx context.Context, size int, clients map[string]agen
427
415
428
416
for id := range names {
429
417
if h .leaderID == h .names [id ] {
430
- h .leader = clients [names [id ]].Connection ()
431
418
if cfg := configs [id ]; cfg != nil {
432
419
return clients [names [id ]], cfg , h , nil
433
420
}
0 commit comments