Skip to content

Commit aa65fe5

Browse files
committed
Upsert initial SLA lifecycle unconditionally & drop execution order from runtime updates
1 parent dffb183 commit aa65fe5

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
@@ -167,10 +167,15 @@ func run() int {
167167
synctx, cancelSynctx := context.WithCancel(ha.Environment().NewContext(hactx))
168168
g, synctx := errgroup.WithContext(synctx)
169169
// WaitGroups for initial synchronization.
170-
// Runtime updates must wait for initial synchronization to complete.
170+
// Runtime updates and history pipelines must wait for the initial synchronization to
171+
// complete by draining the `initConfigSyncDone` channel.
171172
configInitSync := sync.WaitGroup{}
172173
stateInitSync := &sync.WaitGroup{}
173174

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

245250
g.Go(func() error {
251+
// Unblock the runtime updates and history pipelines workers.
252+
defer close(initConfigSyncDone)
253+
254+
// Wait for the actual initial config sync to finish before syncing the SLA lifecycles.
246255
configInitSync.Wait()
256+
257+
logger.Info("Syncing Host and Service initial SLA lifecycle")
258+
if err := icingadb.SyncCheckablesSlaLifecycle(synctx, db); err != nil {
259+
return err
260+
}
261+
247262
atomic.StoreInt64(&telemetry.OngoingSyncStartMilli, 0)
248263

249264
syncEnd := time.Now()
@@ -279,7 +294,8 @@ func run() int {
279294
})
280295

281296
g.Go(func() error {
282-
configInitSync.Wait()
297+
// Wait for the initial config sync including the SLA lifecycles to finish!
298+
<-initConfigSyncDone
283299

284300
if err := synctx.Err(); err != nil {
285301
return err
@@ -304,7 +320,7 @@ func run() int {
304320

305321
g.Go(func() error {
306322
// Wait for config and state sync to avoid putting additional pressure on the database.
307-
configInitSync.Wait()
323+
<-initConfigSyncDone
308324
stateInitSync.Wait()
309325

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

0 commit comments

Comments
 (0)