func NewRaftServerWithEnv(conf *core.ServerConfig, env *core.Env) *RaftServer {
	newServer := &RaftServer{}
	fullFilename := filepath.Join(env.DBDir, fmt.Sprintf("server_%d", conf.Info.ServerID))
	newServer.dbStore = kvstore.NewRocksDB(fullFilename)
	newServer.ServerConf = conf
	newServer.stableInfo = &core.PersistentState{Term: 0, LastVotedServerID: 0, Logs: core.NewLogRepo()}
	newServer.volatileInfo = &core.VolatileState{}
	newServer.leaderState = &core.VolatileLeaderState{}
	newServer.wgHandleCommand = &sync.WaitGroup{}
	newServer.RandomRangeInMs = env.RandomRangeInMs
	newServer.leaderElectionTimer = newEventTimer(newServer.LeaderElectionEventHandler, env.LeaderElectionDurationInMs)
	newServer.leaderHeartBeatTimer = newEventTimer(newServer.HeartbeatEventHandler, env.HeartBeatDurationInMs)
	newServer.leaderState.NextIndex = map[int]int{}
	newServer.leaderState.MatchIndex = map[int]int{}
	newServer.leaderState.LastRPCTime = map[int]time.Time{}
	for _, addr := range newServer.ServerConf.ClusterAddrList {
		if newServer.ServerConf.Info.ServerID == addr.ServerID {
			continue
		}
		newServer.leaderState.NextIndex[addr.ServerID] = 1
		newServer.leaderState.MatchIndex[addr.ServerID] = 0
		newServer.leaderState.LastRPCTime[addr.ServerID] = time.Now()
	}
	newServer.clientPool = raftrpc.NewClientPool()
	newServer.sigs = make(chan os.Signal, 1)
	// SIGINT：interrupt/Ctrl-C
	// SIGTERM: kill, can be block
	// SIGUSR1, SIGUSR2: user defined
	signal.Notify(newServer.sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2)
	newServer.stopSignal = make(chan int, 1)
	return newServer
}
// NewRaftServerWithEnv returns a new raft server with env
NewRaftServerWithEnv returns a new raft server with env
// NewRaftServerWithEnv returns a new raft server with env
func NewRaftServerWithEnv(conf *core.ServerConfig, env *core.Env) *RaftServer {
	newServer := &RaftServer{}
	fullFilename := filepath.Join(env.DBDir, fmt.Sprintf("server_%d", conf.Info.ServerID))
	newServer.dbStore = kvstore.NewRocksDB(fullFilename)
	newServer.ServerConf = conf
	newServer.stableInfo = &core.PersistentState{Term: 0, LastVotedServerID: 0, Logs: core.NewLogRepo()}
	newServer.volatileInfo = &core.VolatileState{}
	newServer.leaderState = &core.VolatileLeaderState{}
	newServer.wgHandleCommand = &sync.WaitGroup{}
	newServer.RandomRangeInMs = env.RandomRangeInMs
	newServer.leaderElectionTimer = newEventTimer(newServer.LeaderElectionEventHandler, env.LeaderElectionDurationInMs)
	newServer.leaderHeartBeatTimer = newEventTimer(newServer.HeartbeatEventHandler, env.HeartBeatDurationInMs)
	newServer.leaderState.NextIndex = map[int]int{}
	newServer.leaderState.MatchIndex = map[int]int{}
	newServer.leaderState.LastRPCTime = map[int]time.Time{}
	for _, addr := range newServer.ServerConf.ClusterAddrList {
		if newServer.ServerConf.Info.ServerID == addr.ServerID {
			continue
		}
		newServer.leaderState.NextIndex[addr.ServerID] = 1
		newServer.leaderState.MatchIndex[addr.ServerID] = 0
		newServer.leaderState.LastRPCTime[addr.ServerID] = time.Now()
	}
	newServer.clientPool = raftrpc.NewClientPool()
	newServer.sigs = make(chan os.Signal, 1)
	signal.Notify(newServer.sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGUSR1, syscall.SIGUSR2)
	newServer.stopSignal = make(chan int, 1)
	return newServer
}
func NewRaftServerWithEnv ( conf * core . ServerConfig , env * core . Env ) * RaftServer { newServer := & RaftServer { } fullFilename := filepath . Join ( env . DBDir , fmt . Sprintf ( " " , conf . Info . ServerID ) ) newServer . dbStore = kvstore . NewRocksDB ( fullFilename ) newServer . ServerConf = conf newServer . stableInfo = & core . PersistentState { Term : 0 , LastVotedServerID : 0 , Logs : core . NewLogRepo ( ) } newServer . volatileInfo = & core . VolatileState { } newServer . leaderState = & core . VolatileLeaderState { } newServer . wgHandleCommand = & sync . WaitGroup { } newServer . RandomRangeInMs = env . RandomRangeInMs newServer . leaderElectionTimer = newEventTimer ( newServer . LeaderElectionEventHandler , env . LeaderElectionDurationInMs ) newServer . leaderHeartBeatTimer = newEventTimer ( newServer . HeartbeatEventHandler , env . HeartBeatDurationInMs ) newServer . leaderState . NextIndex = map [ int ] int { } newServer . leaderState . MatchIndex = map [ int ] int { } newServer . leaderState . LastRPCTime = map [ int ] time . Time { } for _ , addr := range newServer . ServerConf . ClusterAddrList { if newServer . ServerConf . Info . ServerID == addr . ServerID { continue } newServer . leaderState . NextIndex [ addr . ServerID ] = 1 newServer . leaderState . MatchIndex [ addr . ServerID ] = 0 newServer . leaderState . LastRPCTime [ addr . ServerID ] = time . Now ( ) } newServer . clientPool = raftrpc . NewClientPool ( ) newServer . sigs = make ( chan os . Signal , 1 ) signal . Notify ( newServer . sigs , syscall . SIGINT , syscall . SIGTERM , syscall . SIGUSR1 , syscall . SIGUSR2 ) newServer . stopSignal = make ( chan int , 1 ) return newServer }
NewRaftServerWithEnv returns a new raft server with env
NewRaftServerWithEnv returns a new raft server with env
// SIGINT：interrupt/Ctrl-C // SIGTERM: kill, can be block // SIGUSR1, SIGUSR2: user defined