MCPcopy
hub / github.com/grafana/tempo / starting

Method starting

modules/livestore/live_store.go:272–355  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

270}
271
272func (s *LiveStore) starting(ctx context.Context) error {
273 // First of all we have to check if the shutdown marker is set. This needs to be done
274 // as first thing because, if found, it may change the behaviour of the live-store startup.
275
276 if _, err := os.Stat(s.cfg.ShutdownMarkerDir); os.IsNotExist(err) {
277 err := os.MkdirAll(s.cfg.ShutdownMarkerDir, 0o700)
278 if err != nil {
279 return fmt.Errorf("failed to create shutdown marker directory: %w", err)
280 }
281 }
282
283 shutdownMarkerPath := shutdownmarker.GetPath(s.cfg.ShutdownMarkerDir)
284 if exists, err := shutdownmarker.Exists(shutdownMarkerPath); err != nil {
285 return fmt.Errorf("failed to check live-store shutdown marker: %w", err)
286 } else if exists {
287 level.Info(s.logger).Log("msg", "detected existing shutdown marker, setting prepare for shutdown", "path", shutdownMarkerPath)
288 s.setPrepareShutdown()
289 }
290
291 var err error
292 s.wal, err = wal.New(&s.cfg.WAL)
293 if err != nil {
294 return fmt.Errorf("failed to create WAL: %w", err)
295 }
296
297 err = s.reloadBlocks()
298 if err != nil {
299 return fmt.Errorf("failed to reload blocks from wal: %w", err)
300 }
301
302 level.Info(s.logger).Log("msg", "deleting old blocks")
303 for _, inst := range s.getInstances() {
304 err = inst.deleteOldBlocks()
305 if err != nil {
306 level.Warn(s.logger).Log("msg", "failed to delete old blocks", "err", err, "tenant", inst.tenantID)
307 }
308 }
309 level.Info(s.logger).Log("msg", "done deleting old blocks")
310
311 // Set eagerly so the flag is already in place when the lifecycler's stopping()
312 // checks it. Setting it in our own stopping() races with context-cancellation
313 // that triggers the lifecycler's shutdown first.
314 if s.cfg.RemoveOwnerOnShutdown {
315 s.ingestPartitionLifecycler.SetRemoveOwnerOnShutdown(true)
316 }
317
318 err = services.StartAndAwaitRunning(ctx, s.ingestPartitionLifecycler)
319 if err != nil {
320 return fmt.Errorf("failed to start partition lifecycler: %w", err)
321 }
322
323 err = services.StartAndAwaitRunning(ctx, s.livestoreLifecycler)
324 if err != nil {
325 return fmt.Errorf("failed to start livestore lifecycler: %w", err)
326 }
327
328 if err := s.startIngestPath(ctx); err != nil {
329 return err

Callers

nothing calls this directly

Calls 15

setPrepareShutdownMethod · 0.95
reloadBlocksMethod · 0.95
getInstancesMethod · 0.95
startIngestPathMethod · 0.95
runInBackgroundMethod · 0.95
globalCompleteLoopMethod · 0.95
GetPathFunction · 0.92
ExistsFunction · 0.92
NewFunction · 0.92
deleteOldBlocksMethod · 0.80

Tested by

no test coverage detected