Skip to content

Commit 9f4d397

Browse files
authored
[Bugfix] Do not stop Sync if Synchronization is in progress (#1203)
1 parent ff759b5 commit 9f4d397

20 files changed

+162
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
- (Feature) Configurable ArangoD Port
3838
- (Feature) Allow to exclude metrics
3939
- (Feature) Do not restart member if all pods in group are not ready
40+
- (Bugfix) Do not stop Sync if Synchronization is in progress
4041

4142
## [1.2.20](https://github.com/arangodb/kube-arangodb/tree/1.2.20) (2022-10-25)
4243
- (Feature) Add action progress

pkg/apis/deployment/v1/conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ const (
121121

122122
// ConditionTypeMaintenance indicates that maintenance is enabled on cluster
123123
ConditionTypeMaintenance ConditionType = "Maintenance"
124+
125+
// ConditionTypeSyncEnabled Define if sync is enabled
126+
ConditionTypeSyncEnabled ConditionType = "SyncEnabled"
124127
)
125128

126129
// Condition represents one current condition of a deployment or deployment member.

pkg/apis/deployment/v2alpha1/conditions.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ const (
121121

122122
// ConditionTypeMaintenance indicates that maintenance is enabled on cluster
123123
ConditionTypeMaintenance ConditionType = "Maintenance"
124+
125+
// ConditionTypeSyncEnabled Define if sync is enabled
126+
ConditionTypeSyncEnabled ConditionType = "SyncEnabled"
124127
)
125128

126129
// Condition represents one current condition of a deployment or deployment member.

pkg/deployment/access_package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func (d *Deployment) createAccessPackages(ctx context.Context) error {
5050
log := d.sectionLogger("access-package")
5151
spec := d.GetSpec()
5252

53-
if !spec.Sync.IsEnabled() {
53+
if !d.IsSyncEnabled() {
5454
// We're only relevant when sync is enabled
5555
return nil
5656
}

pkg/deployment/agency/cache.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ type Health interface {
153153
type Cache interface {
154154
Reload(ctx context.Context, size int, clients map[string]agency.Agency) (uint64, error)
155155
Data() (State, bool)
156+
DataDB() (StateDB, bool)
156157
CommitIndex() uint64
157158
// Health returns true when healthy object is available.
158159
Health() (Health, bool)
@@ -184,6 +185,10 @@ func NewSingleCache() Cache {
184185
type cacheSingle struct {
185186
}
186187

188+
func (c cacheSingle) DataDB() (StateDB, bool) {
189+
return StateDB{}, false
190+
}
191+
187192
func (c cacheSingle) CommitIndex() uint64 {
188193
return 0
189194
}
@@ -212,7 +217,8 @@ type cache struct {
212217

213218
commitIndex uint64
214219

215-
data State
220+
data State
221+
dataDB StateDB
216222

217223
health Health
218224
}
@@ -232,7 +238,22 @@ func (c *cache) Data() (State, bool) {
232238
c.lock.RLock()
233239
defer c.lock.RUnlock()
234240

235-
return c.data, c.valid
241+
if !c.valid {
242+
return State{}, false
243+
}
244+
245+
return c.data, true
246+
}
247+
248+
func (c *cache) DataDB() (StateDB, bool) {
249+
c.lock.RLock()
250+
defer c.lock.RUnlock()
251+
252+
if !c.valid {
253+
return StateDB{}, false
254+
}
255+
256+
return c.dataDB, c.valid
236257
}
237258

238259
// Health returns always false for single cache.
@@ -275,7 +296,8 @@ func (c *cache) Reload(ctx context.Context, size int, clients map[string]agency.
275296
c.valid = false
276297
return leaderConfig.CommitIndex, err
277298
} else {
278-
c.data = data
299+
c.data = data.Arango
300+
c.dataDB = data.ArangoDB
279301
c.valid = true
280302
c.commitIndex = leaderConfig.CommitIndex
281303
return leaderConfig.CommitIndex, nil

pkg/deployment/agency/definitions.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ import (
2626
)
2727

2828
const (
29-
ArangoKey = "arango"
29+
ArangoKey = "arango"
30+
ArangoDBKey = "arangodb"
3031

3132
PlanKey = "Plan"
3233
CurrentKey = "Current"
@@ -48,6 +49,13 @@ const (
4849
TargetJobFinishedKey = "Finished"
4950

5051
TargetCleanedServersKey = "CleanedServers"
52+
53+
ArangoSyncKey = "arangosync"
54+
ArangoSyncStateKey = "synchronizationState"
55+
ArangoSyncStateIncomingKey = "incoming"
56+
ArangoSyncStateIncomingStateKey = "state"
57+
ArangoSyncStateOutgoingKey = "outgoing"
58+
ArangoSyncStateOutgoingTargetsKey = "targets"
5159
)
5260

5361
func GetAgencyKey(parts ...string) string {

pkg/deployment/agency/state.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ import (
3131
"github.com/arangodb/kube-arangodb/pkg/util/errors"
3232
)
3333

34-
func (c *cache) loadState(ctx context.Context, client agency.Agency) (State, error) {
34+
func (c *cache) loadState(ctx context.Context, client agency.Agency) (StateRoot, error) {
3535
conn := client.Connection()
3636

3737
req, err := client.Connection().NewRequest(http.MethodPost, "/_api/agency/read")
3838
if err != nil {
39-
return State{}, err
39+
return StateRoot{}, err
4040
}
4141

4242
var data []byte
@@ -53,33 +53,35 @@ func (c *cache) loadState(ctx context.Context, client agency.Agency) (State, err
5353
GetAgencyKey(ArangoKey, TargetKey, TargetJobFailedKey),
5454
GetAgencyKey(ArangoKey, TargetKey, TargetJobFinishedKey),
5555
GetAgencyKey(ArangoKey, TargetKey, TargetCleanedServersKey),
56+
GetAgencyKey(ArangoDBKey, ArangoSyncKey, ArangoSyncStateKey, ArangoSyncStateIncomingKey, ArangoSyncStateIncomingStateKey),
57+
GetAgencyKey(ArangoDBKey, ArangoSyncKey, ArangoSyncStateKey, ArangoSyncStateOutgoingKey, ArangoSyncStateOutgoingTargetsKey),
5658
}
5759

5860
req, err = req.SetBody(GetAgencyReadRequest(GetAgencyReadKey(readKeys...)))
5961
if err != nil {
60-
return State{}, err
62+
return StateRoot{}, err
6163
}
6264

6365
resp, err := conn.Do(driver.WithRawResponse(ctx, &data), req)
6466
if err != nil {
65-
return State{}, err
67+
return StateRoot{}, err
6668
}
6769

6870
if err := resp.CheckStatus(http.StatusOK); err != nil {
69-
return State{}, err
71+
return StateRoot{}, err
7072
}
7173

7274
var r StateRoots
7375

7476
if err := json.Unmarshal(data, &r); err != nil {
75-
return State{}, err
77+
return StateRoot{}, err
7678
}
7779

7880
if len(r) != 1 {
79-
return State{}, errors.Newf("Invalid response size")
81+
return StateRoot{}, errors.Newf("Invalid response size")
8082
}
8183

82-
state := r[0].Arango
84+
state := r[0]
8385

8486
return state, nil
8587
}

pkg/deployment/deployment.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,21 @@ type Deployment struct {
137137
metrics Metrics
138138
}
139139

140+
func (d *Deployment) IsSyncEnabled() bool {
141+
d.currentObjectLock.RLock()
142+
defer d.currentObjectLock.RUnlock()
143+
144+
if d.currentObject.Spec.Sync.IsEnabled() {
145+
return true
146+
}
147+
148+
if d.currentObject.Status.Conditions.IsTrue(api.ConditionTypeSyncEnabled) {
149+
return true
150+
}
151+
152+
return false
153+
}
154+
140155
func (d *Deployment) GetMembersState() memberState.StateInspector {
141156
return d.memberState
142157
}
@@ -149,6 +164,10 @@ func (d *Deployment) GetAgencyHealth() (agency.Health, bool) {
149164
return d.agencyCache.Health()
150165
}
151166

167+
func (d *Deployment) GetAgencyArangoDBCache() (agency.StateDB, bool) {
168+
return d.agencyCache.DataDB()
169+
}
170+
152171
func (d *Deployment) RefreshAgencyCache(ctx context.Context) (uint64, error) {
153172
if d.GetSpec().Mode.Get() == api.DeploymentModeSingle {
154173
return 0, nil

pkg/deployment/reconcile/action_context.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ type actionContext struct {
140140
metrics *Metrics
141141
}
142142

143+
func (ac *actionContext) IsSyncEnabled() bool {
144+
return ac.context.IsSyncEnabled()
145+
}
146+
143147
func (ac *actionContext) WithMemberStatusUpdateErr(ctx context.Context, id string, group api.ServerGroup, action reconciler.DeploymentMemberStatusUpdateErrFunc) error {
144148
return ac.context.WithMemberStatusUpdateErr(ctx, id, group, action)
145149
}
@@ -251,6 +255,10 @@ func (ac *actionContext) GetAgencyCache() (agencyCache.State, bool) {
251255
return ac.context.GetAgencyCache()
252256
}
253257

258+
func (ac *actionContext) GetAgencyArangoDBCache() (agencyCache.StateDB, bool) {
259+
return ac.context.GetAgencyArangoDBCache()
260+
}
261+
254262
func (ac *actionContext) SetAgencyMaintenanceMode(ctx context.Context, enabled bool) error {
255263
return ac.context.SetAgencyMaintenanceMode(ctx, enabled)
256264
}

pkg/deployment/reconcile/plan_builder_high.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ func (r *Reconciler) createHighPlan(ctx context.Context, apiObject k8sutil.APIOb
4848
ApplyIfEmpty(r.updateMemberPodTemplateSpec).
4949
ApplyIfEmpty(r.updateMemberPhasePlan).
5050
ApplyIfEmpty(r.createCleanOutPlan).
51+
ApplyIfEmpty(r.createSyncPlan).
5152
ApplyIfEmpty(r.updateMemberUpdateConditionsPlan).
5253
ApplyIfEmpty(r.updateMemberRotationConditionsPlan).
5354
ApplyIfEmpty(r.createMemberRecreationConditionsPlan).

0 commit comments

Comments
 (0)