MCPcopy
hub / github.com/olric-data/olric / Shutdown

Method Shutdown

olric.go:411–466  ·  view source on GitHub ↗

Shutdown stops background servers and leaves the cluster.

(ctx context.Context)

Source from the content-addressed store, hash-verified

409
410// Shutdown stops background servers and leaves the cluster.
411func (db *Olric) Shutdown(ctx context.Context) error {
412 select {
413 case <-db.ctx.Done():
414 // Shutdown only once.
415 return nil
416 default:
417 }
418
419 db.cancel()
420
421 var latestError error
422
423 if err := db.pubsub.Shutdown(ctx); err != nil {
424 db.log.V(2).Printf("[ERROR] Failed to shutdown PubSub service: %v", err)
425 latestError = err
426 }
427
428 if err := db.dmap.Shutdown(ctx); err != nil {
429 db.log.V(2).Printf("[ERROR] Failed to shutdown DMap service: %v", err)
430 latestError = err
431 }
432
433 if err := db.balancer.Shutdown(ctx); err != nil {
434 db.log.V(2).Printf("[ERROR] Failed to shutdown balancer service: %v", err)
435 latestError = err
436 }
437
438 if err := db.rt.Shutdown(ctx); err != nil {
439 db.log.V(2).Printf("[ERROR] Failed to shutdown routing table service: %v", err)
440 latestError = err
441 }
442
443 // Shutdown Redcon server
444 if err := db.server.Shutdown(ctx); err != nil {
445 db.log.V(2).Printf("[ERROR] Failed to shutdown RESP server: %v", err)
446 latestError = err
447 }
448
449 done := make(chan struct{})
450 go func() {
451 defer func() {
452 close(done)
453 }()
454 db.wg.Wait()
455 }()
456
457 select {
458 case <-ctx.Done():
459 case <-done:
460 }
461
462 // db.name will be shown as empty string, if the program is killed before
463 // bootstrapping.
464 db.log.V(2).Printf("[INFO] %s is gone", db.name)
465 return latestError
466}
467
468func convertDMapError(err error) error {

Callers

nothing calls this directly

Calls 3

PrintfMethod · 0.80
VMethod · 0.80
ShutdownMethod · 0.65

Tested by

no test coverage detected