Skip to content

Commit 2b8a8d6

Browse files
author
lamai93
committed
Added sync invalidation on server shutdown.
1 parent 2eada0b commit 2b8a8d6

File tree

6 files changed

+33
-4
lines changed

6 files changed

+33
-4
lines changed

pkg/deployment/context_impl.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,3 +385,8 @@ func (d *Deployment) GetExpectedPodArguments(apiObject metav1.Object, deplSpec a
385385
func (d *Deployment) GetShardSyncStatus() bool {
386386
return d.resources.GetShardSyncStatus()
387387
}
388+
389+
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
390+
func (d *Deployment) InvalidateSyncStatus() {
391+
d.resources.InvalidateSyncStatus()
392+
}

pkg/deployment/reconcile/context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,6 @@ type Context interface {
9595
agents api.MemberStatusList, id string, version driver.Version) []string
9696
// GetShardSyncStatus returns true if all shards are in sync
9797
GetShardSyncStatus() bool
98+
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
99+
InvalidateSyncStatus()
98100
}

pkg/deployment/reconcile/plan_builder_context.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type PlanBuilderContext interface {
4848
agents api.MemberStatusList, id string, version driver.Version) []string
4949
// GetShardSyncStatus returns true if all shards are in sync
5050
GetShardSyncStatus() bool
51+
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
52+
InvalidateSyncStatus()
5153
// GetStatus returns the current status of the deployment
5254
GetStatus() (api.DeploymentStatus, int32)
5355
}

pkg/deployment/resources/deployment_health.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (r *Resources) RunDeploymentHealthLoop(stopCh <-chan struct{}) {
5454
deploymentHealthFetchesCounters.WithLabelValues(deploymentName, metrics.Success).Inc()
5555
}
5656
select {
57+
case <-r.shardSync.triggerSyncInspection.Done():
5758
case <-time.After(time.Second * 5):
5859
// Continue
5960
case <-stopCh:
@@ -118,6 +119,15 @@ func (r *Resources) RunDeploymentShardSyncLoop(stopCh <-chan struct{}) {
118119
}
119120
}
120121

122+
// InvalidateSyncStatus resets the sync state to false and triggers an inspection
123+
func (r *Resources) InvalidateSyncStatus() {
124+
r.log.Debug().Msg("Invalidating sync status due to previous events")
125+
r.shardSync.mutex.Lock()
126+
defer r.shardSync.mutex.Unlock()
127+
r.shardSync.allInSync = false
128+
r.shardSync.triggerSyncInspection.Trigger()
129+
}
130+
121131
// fetchClusterShardSyncState performs a single fetch of the cluster inventory and
122132
// checks if all shards are in sync
123133
func (r *Resources) fetchClusterShardSyncState() error {
@@ -154,9 +164,15 @@ dbloop:
154164
}
155165

156166
r.shardSync.mutex.Lock()
157-
defer r.shardSync.mutex.Unlock()
167+
oldSyncState := r.shardSync.allInSync
158168
r.shardSync.allInSync = allInSync
159169
r.shardSync.timestamp = time.Now()
170+
r.shardSync.mutex.Unlock()
171+
172+
if !oldSyncState && allInSync {
173+
r.log.Debug().Msg("Everything is in sync by now")
174+
}
175+
160176
return nil
161177
}
162178

pkg/deployment/resources/pod_inspector.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ func (r *Resources) InspectPods(ctx context.Context) (util.Interval, error) {
109109
// Record termination time
110110
now := metav1.Now()
111111
memberStatus.RecentTerminations = append(memberStatus.RecentTerminations, now)
112+
r.InvalidateSyncStatus()
112113
}
113114
}
114115
} else if k8sutil.IsPodFailed(&p) {
@@ -122,6 +123,7 @@ func (r *Resources) InspectPods(ctx context.Context) (util.Interval, error) {
122123
// Record termination time
123124
now := metav1.Now()
124125
memberStatus.RecentTerminations = append(memberStatus.RecentTerminations, now)
126+
r.InvalidateSyncStatus()
125127
}
126128
}
127129
}

pkg/deployment/resources/resources.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"time"
2828

2929
driver "github.com/arangodb/go-driver"
30+
"github.com/arangodb/kube-arangodb/pkg/util/trigger"
3031
"github.com/rs/zerolog"
3132
)
3233

@@ -41,9 +42,10 @@ type Resources struct {
4142
mutex sync.Mutex // Mutex guarding fields in this struct
4243
}
4344
shardSync struct {
44-
allInSync bool
45-
timestamp time.Time
46-
mutex sync.Mutex
45+
allInSync bool
46+
timestamp time.Time
47+
mutex sync.Mutex
48+
triggerSyncInspection trigger.Trigger
4749
}
4850
}
4951

0 commit comments

Comments
 (0)