Skip to content

Commit

Permalink
Upsert initial SLA lifecycle unconditionally & drop execution order f…
Browse files Browse the repository at this point in the history
…rom runtime updates
  • Loading branch information
yhabteab committed Sep 4, 2024
1 parent 3f895f2 commit 05e39f0
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 235 deletions.
22 changes: 19 additions & 3 deletions cmd/icingadb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,15 @@ func run() int {
synctx, cancelSynctx := context.WithCancel(ha.Environment().NewContext(hactx))
g, synctx := errgroup.WithContext(synctx)
// WaitGroups for initial synchronization.
// Runtime updates must wait for initial synchronization to complete.
// Runtime updates and history pipelines must wait for the initial synchronization to
// complete by draining the `initConfigSyncDone` channel.
configInitSync := sync.WaitGroup{}
stateInitSync := &sync.WaitGroup{}

// A buffered channel used to notify both the runtime updates and history pipelines workers
// about the successful initial config sync completion including the SLA lifecycles.
initConfigSyncDone := make(chan struct{}, 1)

// Clear the runtime update streams before starting anything else (rather than after the sync),
// otherwise updates may be lost.
runtimeConfigUpdateStreams, runtimeStateUpdateStreams, err := rt.ClearStreams(synctx)
Expand Down Expand Up @@ -242,7 +247,17 @@ func run() int {
})

g.Go(func() error {
defer close(initConfigSyncDone)
defer func() { initConfigSyncDone <- struct{}{} }()

// Wait for the actual initial config sync to finish before syncing the SLA lifecycles.
configInitSync.Wait()

logger.Info("Syncing Host and Service initial SLA lifecycle")
if err := icingadb.SyncCheckablesSlaLifecycle(synctx, db); err != nil {
return err
}

atomic.StoreInt64(&telemetry.OngoingSyncStartMilli, 0)

syncEnd := time.Now()
Expand Down Expand Up @@ -278,7 +293,8 @@ func run() int {
})

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

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

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

if err := synctx.Err(); err != nil {
Expand Down
Loading

0 comments on commit 05e39f0

Please sign in to comment.