MCPcopy
hub / github.com/grafana/dskit / stopping

Method stopping

ring/basic_lifecycler.go:271–309  ·  view source on GitHub ↗
(runningError error)

Source from the content-addressed store, hash-verified

269}
270
271func (l *BasicLifecycler) stopping(runningError error) error {
272 if runningError != nil {
273 return nil
274 }
275
276 // Let the delegate change the instance state (ie. to LEAVING) and handling any
277 // state transferring / flushing while we continue to heartbeat.
278 done := make(chan struct{})
279 go func() {
280 defer close(done)
281 l.delegate.OnRingInstanceStopping(l)
282 }()
283
284 // Heartbeat while the stopping delegate function is running.
285 heartbeatTickerStop, heartbeatTickerChan := newDisableableTicker(l.cfg.HeartbeatPeriod)
286 defer heartbeatTickerStop()
287
288heartbeatLoop:
289 for {
290 select {
291 case <-heartbeatTickerChan:
292 l.heartbeat(context.Background())
293 case <-done:
294 break heartbeatLoop
295 }
296 }
297
298 if l.ShouldKeepInstanceInTheRingOnShutdown() {
299 level.Info(l.logger).Log("msg", "keeping instance the ring", "ring", l.ringName)
300 } else {
301 // Remove the instance from the ring.
302 if err := l.unregisterInstance(context.Background()); err != nil {
303 return errors.Wrapf(err, "failed to unregister instance from the ring (ring: %s)", l.ringName)
304 }
305 level.Info(l.logger).Log("msg", "instance removed from the ring", "ring", l.ringName)
306 }
307
308 return nil
309}
310
311// registerInstance registers the instance in the ring. The initial state and set of tokens
312// depends on the OnRingInstanceRegister() delegate function.

Callers

nothing calls this directly

Calls 6

heartbeatMethod · 0.95
unregisterInstanceMethod · 0.95
newDisableableTickerFunction · 0.85
LogMethod · 0.45

Tested by

no test coverage detected