Skip to content

Commit 05e39f0

Browse files
committed
Upsert initial SLA lifecycle unconditionally & drop execution order from runtime updates
1 parent 3f895f2 commit 05e39f0

File tree

6 files changed

+219
-235
lines changed

6 files changed

+219
-235
lines changed

cmd/icingadb/main.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,10 +166,15 @@ func run() int {
166166
synctx, cancelSynctx := context.WithCancel(ha.Environment().NewContext(hactx))
167167
g, synctx := errgroup.WithContext(synctx)
168168
// WaitGroups for initial synchronization.
169-
// Runtime updates must wait for initial synchronization to complete.
169+
// Runtime updates and history pipelines must wait for the initial synchronization to
170+
// complete by draining the `initConfigSyncDone` channel.
170171
configInitSync := sync.WaitGroup{}
171172
stateInitSync := &sync.WaitGroup{}
172173

174+
// A buffered channel used to notify both the runtime updates and history pipelines workers
175+
// about the successful initial config sync completion including the SLA lifecycles.
176+
initConfigSyncDone := make(chan struct{}, 1)
177+
173178
// Clear the runtime update streams before starting anything else (rather than after the sync),
174179
// otherwise updates may be lost.
175180
runtimeConfigUpdateStreams, runtimeStateUpdateStreams, err := rt.ClearStreams(synctx)
@@ -242,7 +247,17 @@ func run() int {
242247
})
243248

244249
g.Go(func() error {
250+
defer close(initConfigSyncDone)
251+
defer func() { initConfigSyncDone <- struct{}{} }()
252+
253+
// Wait for the actual initial config sync to finish before syncing the SLA lifecycles.
245254
configInitSync.Wait()
255+
256+
logger.Info("Syncing Host and Service initial SLA lifecycle")
257+
if err := icingadb.SyncCheckablesSlaLifecycle(synctx, db); err != nil {
258+
return err
259+
}
260+
246261
atomic.StoreInt64(&telemetry.OngoingSyncStartMilli, 0)
247262

248263
syncEnd := time.Now()
@@ -278,7 +293,8 @@ func run() int {
278293
})
279294

280295
g.Go(func() error {
281-
configInitSync.Wait()
296+
// Wait for the initial config sync including the SLA lifecycles to finish!
297+
<-initConfigSyncDone
282298

283299
if err := synctx.Err(); err != nil {
284300
return err
@@ -303,7 +319,7 @@ func run() int {
303319

304320
g.Go(func() error {
305321
// Wait for config and state sync to avoid putting additional pressure on the database.
306-
configInitSync.Wait()
322+
<-initConfigSyncDone
307323
stateInitSync.Wait()
308324

309325
if err := synctx.Err(); err != nil {

0 commit comments

Comments
 (0)