// Shutdown stops background servers and leaves the cluster.
Shutdown stops background servers and leaves the cluster.
// Shutdown stops background servers and leaves the cluster .
func (db *Olric) Shutdown(ctx context.Context) error {
	db.cancel()
	var latestError error
	if err := db.dtopic.Shutdown(ctx); err != nil {
		db.log.V(2).Printf("[ERROR] Failed to shutdown DTopic service: %v", err)
		latestError = err
	}
	if err := db.dmap.Shutdown(ctx); err != nil {
		db.log.V(2).Printf("[ERROR] Failed to shutdown DMap service: %v", err)
		latestError = err
	}
	if err := db.streams.Shutdown(ctx); err != nil {
		db.log.V(2).Printf("[ERROR] Failed to shutdown stream service: %v", err)
		latestError = err
	}
	if err := db.balancer.Shutdown(ctx); err != nil {
		db.log.V(2).Printf("[ERROR] Failed to shutdown balancer service: %v", err)
		latestError = err
	}
	if err := db.rt.Shutdown(ctx); err != nil {
		db.log.V(2).Printf("[ERROR] Failed to shutdown routing table service: %v", err)
		latestError = err
	}
	if err := db.server.Shutdown(ctx); err != nil {
		db.log.V(2).Printf("[ERROR] Failed to shutdown TCP server: %v", err)
		latestError = err
	}
	db.wg.Wait()
	db.log.V(2).Printf("[INFO] %s is gone", db.name)
	return latestError
}
func ( db * Olric ) Shutdown ( ctx context . Context ) error { db . cancel ( ) var latestError error if err := db . dtopic . Shutdown ( ctx ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) latestError = err } if err := db . dmap . Shutdown ( ctx ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) latestError = err } if err := db . streams . Shutdown ( ctx ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) latestError = err } if err := db . balancer . Shutdown ( ctx ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) latestError = err } if err := db . rt . Shutdown ( ctx ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) latestError = err } if err := db . server . Shutdown ( ctx ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) latestError = err } db . wg . Wait ( ) db . log . V ( 2 ) . Printf ( " " , db . name ) return latestError }
Shutdown stops background servers and leaves the cluster.
Shutdown stops background servers and leaves the cluster .
// TODO: It's a good idea to add graceful period here // db.name will be shown as empty string, if the program is killed before // bootstrapping.