// Start starts background servers and joins the cluster. You still need to call
// Shutdown method if Start function returns an early error.
Start starts background servers and joins the cluster. You still need to call
Shutdown method if Start function returns an early error.
// Start starts background servers and joins the cluster . You still need to call // Shutdown method if Start function returns an early error .
func (db *Olric) Start() error {
	errGr, ctx := errgroup.WithContext(context.Background())
	errGr.Go(func() error {
		return db.server.ListenAndServe()
	})
	select {
	case <-db.server.StartedCtx.Done():
		checkpoint.Pass()
	case <-ctx.Done():
		if err := db.Shutdown(context.Background()); err != nil {
			db.log.V(2).Printf("[ERROR] Failed to Shutdown: %v", err)
		}
		return errGr.Wait()
	}
	if err := db.balancer.Start(); err != nil {
		return err
	}
	if err := db.rt.Start(); err != nil {
		return err
	}
	if err := db.dtopic.Start(); err != nil {
		return err
	}
	if err := db.dmap.Start(); err != nil {
		return err
	}
	if db.config.ReplicationMode == config.AsyncReplicationMode && db.config.WriteQuorum > 1 {
		db.log.V(2).
			Printf("[WARN] Olric is running in async replication mode. WriteQuorum (%d) is ineffective",
				db.config.WriteQuorum)
	}
	if db.started != nil {
		db.wg.Add(1)
		go db.callStartedCallback()
	}
	db.log.V(2).Printf("[INFO] Node name in the cluster: %s",
		db.name)
	if db.config.Interface != "" {
		db.log.V(2).Printf("[INFO] Olric uses interface: %s",
			db.config.Interface)
	}
	db.log.V(2).Printf("[INFO] Olric bindAddr: %s, bindPort: %d",
		db.config.BindAddr, db.config.BindPort)
	db.log.V(2).Printf("[INFO] Replication count is %d", db.config.ReplicaCount)
	return errGr.Wait()
}
func ( db * Olric ) Start ( ) error { errGr , ctx := errgroup . WithContext ( context . Background ( ) ) errGr . Go ( func ( ) error { return db . server . ListenAndServe ( ) } ) select { case <- db . server . StartedCtx . Done ( ) : checkpoint . Pass ( ) case <- ctx . Done ( ) : if err := db . Shutdown ( context . Background ( ) ) ; err != nil { db . log . V ( 2 ) . Printf ( " " , err ) } return errGr . Wait ( ) } if err := db . balancer . Start ( ) ; err != nil { return err } if err := db . rt . Start ( ) ; err != nil { return err } if err := db . dtopic . Start ( ) ; err != nil { return err } if err := db . dmap . Start ( ) ; err != nil { return err } if db . config . ReplicationMode == config . AsyncReplicationMode && db . config . WriteQuorum > 1 { db . log . V ( 2 ) . Printf ( " " , db . config . WriteQuorum ) } if db . started != nil { db . wg . Add ( 1 ) go db . callStartedCallback ( ) } db . log . V ( 2 ) . Printf ( " " , db . name ) if db . config . Interface != " " { db . log . V ( 2 ) . Printf ( " " , db . config . Interface ) } db . log . V ( 2 ) . Printf ( " " , db . config . BindAddr , db . config . BindPort ) db . log . V ( 2 ) . Printf ( " " , db . config . ReplicaCount ) return errGr . Wait ( ) }
Start starts background servers and joins the cluster.
Start starts background servers and joins the cluster .
// Start the TCP server // TCP server is started // Balancer works periodically to balance partition data across the cluster. // Start routing table service and member discovery subsystem. // Start distributed topic service // Start distributed map service // Warn the user about his/her choice of configuration