Skip to content

Commit b6efac0

Browse files
authored
[Feature] Agency Improvements (#1341)
1 parent deb06bf commit b6efac0

File tree

4 files changed

+97
-0
lines changed

4 files changed

+97
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [master](https://github.com/arangodb/kube-arangodb/tree/master) (N/A)
44
- (Improvement) Block traffic on the services if there is more than 1 active leader in ActiveFailover mode
55
- (Improvement) Improve master endpoint validation.
6+
- (Feature) Agency Improvements
67

78
## [1.2.30](https://github.com/arangodb/kube-arangodb/tree/1.2.30) (2023-06-16)
89
- (Feature) AgencyCache Interface

pkg/deployment/agency/cache/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func Init(cmd *cobra.Command) error {
4040

4141
f.DurationVar(&global.RefreshDelay, "agency.refresh-delay", 500*time.Millisecond, "The Agency refresh delay (0 = no delay)")
4242
f.DurationVar(&global.RefreshInterval, "agency.refresh-interval", 0, "The Agency refresh interval (0 = do not refresh)")
43+
f.IntVar(&global.Retries, "agency.retries", 1, "The Agency retries (0 = no retries)")
4344

4445
return nil
4546
}
@@ -53,4 +54,5 @@ func GlobalConfig() Config {
5354
type Config struct {
5455
RefreshDelay time.Duration
5556
RefreshInterval time.Duration
57+
Retries int
5658
}

pkg/deployment/agency/loader.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ func getLoader[T interface{}]() agencyCache.StateLoader[T] {
3636
loader = DelayLoader[T](loader, agencyCache.GlobalConfig().RefreshDelay)
3737
loader = RefreshLoader[T](loader, agencyCache.GlobalConfig().RefreshInterval)
3838

39+
loader = RetryLoader[T](loader, agencyCache.GlobalConfig().Retries)
40+
3941
return loader
4042
}
4143

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package agency
22+
23+
import (
24+
"context"
25+
"sync"
26+
"time"
27+
28+
agencyCache "github.com/arangodb/kube-arangodb/pkg/deployment/agency/cache"
29+
)
30+
31+
func RetryLoader[T interface{}](loader agencyCache.StateLoader[T], retries int) agencyCache.StateLoader[T] {
32+
if retries <= 0 {
33+
return loader
34+
}
35+
36+
return &retryLoader[T]{
37+
parent: loader,
38+
retries: retries,
39+
}
40+
}
41+
42+
type retryLoader[T interface{}] struct {
43+
lock sync.Mutex
44+
45+
retries int
46+
47+
parent agencyCache.StateLoader[T]
48+
}
49+
50+
func (i *retryLoader[T]) UpdateTime() time.Time {
51+
i.lock.Lock()
52+
defer i.lock.Unlock()
53+
54+
return i.parent.UpdateTime()
55+
}
56+
57+
func (i *retryLoader[T]) Valid() bool {
58+
i.lock.Lock()
59+
defer i.lock.Unlock()
60+
61+
return i.parent.Valid()
62+
}
63+
64+
func (i *retryLoader[T]) State() (*T, uint64, bool) {
65+
i.lock.Lock()
66+
defer i.lock.Unlock()
67+
68+
return i.parent.State()
69+
}
70+
71+
func (i *retryLoader[T]) Invalidate() {
72+
i.lock.Lock()
73+
defer i.lock.Unlock()
74+
75+
i.parent.Invalidate()
76+
}
77+
78+
func (i *retryLoader[T]) Refresh(ctx context.Context, discovery agencyCache.LeaderDiscovery) (err error) {
79+
i.lock.Lock()
80+
defer i.lock.Unlock()
81+
82+
for z := 0; z < i.retries-1; z++ {
83+
if err := i.parent.Refresh(ctx, discovery); err != nil {
84+
logger.Err(err).Debug("Unable to refresh agency while retrying")
85+
continue
86+
}
87+
88+
return nil
89+
}
90+
91+
return i.parent.Refresh(ctx, discovery)
92+
}

0 commit comments

Comments
 (0)