@@ -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,20 @@ func run() int {
242247 })
243248
244249 g .Go (func () error {
250+ defer func () {
251+ // Unblock the runtime updates and history pipelines workers.
252+ initConfigSyncDone <- struct {}{}
253+ close (initConfigSyncDone )
254+ }()
255+
256+ // Wait for the actual initial config sync to finish before syncing the SLA lifecycles.
245257 configInitSync .Wait ()
258+
259+ logger .Info ("Syncing Host and Service initial SLA lifecycle" )
260+ if err := icingadb .SyncCheckablesSlaLifecycle (synctx , db ); err != nil {
261+ return err
262+ }
263+
246264 atomic .StoreInt64 (& telemetry .OngoingSyncStartMilli , 0 )
247265
248266 syncEnd := time .Now ()
@@ -278,7 +296,8 @@ func run() int {
278296 })
279297
280298 g .Go (func () error {
281- configInitSync .Wait ()
299+ // Wait for the initial config sync including the SLA lifecycles to finish!
300+ <- initConfigSyncDone
282301
283302 if err := synctx .Err (); err != nil {
284303 return err
@@ -303,7 +322,7 @@ func run() int {
303322
304323 g .Go (func () error {
305324 // Wait for config and state sync to avoid putting additional pressure on the database.
306- configInitSync . Wait ()
325+ <- initConfigSyncDone
307326 stateInitSync .Wait ()
308327
309328 if err := synctx .Err (); err != nil {
0 commit comments