etcd: fake standby

release-2.0
Xiang Li 2014-07-11 13:53:15 -07:00 committed by Yicheng Qin
parent 44836d9099
commit 8ccb8b1f9f
1 changed files with 28 additions and 1 deletions

View File

@ -30,9 +30,17 @@ const (
raftPrefix = "/raft"
)
const (
participant = iota
standby
stop
)
type Server struct {
config *config.Config
mode int
id int64
pubAddr string
raftPubAddr string
@ -90,7 +98,6 @@ func New(c *config.Config, id int64) *Server {
}
m := http.NewServeMux()
//m.Handle("/HEAD", handlerErr(s.serveHead))
m.Handle(v2Prefix+"/", handlerErr(s.serveValue))
m.Handle(v2machinePrefix, handlerErr(s.serveMachines))
m.Handle(v2peersPrefix, handlerErr(s.serveMachines))
@ -153,6 +160,21 @@ func (s *Server) Join() {
}
func (s *Server) run() {
for {
switch s.mode {
case participant:
s.runParticipant()
case standby:
s.runStandby()
case stop:
return
default:
panic("unsupport mode")
}
}
}
func (s *Server) runParticipant() {
node := s.node
recv := s.t.recv
ticker := time.NewTicker(s.tickDuration)
@ -176,6 +198,7 @@ func (s *Server) run() {
node.Sync()
case <-s.stop:
log.Printf("Node: %d stopped\n", s.id)
s.mode = stop
return
}
s.apply(node.Next())
@ -183,6 +206,10 @@ func (s *Server) run() {
}
}
func (s *Server) runStandby() {
panic("unimplemented")
}
func (s *Server) apply(ents []raft.Entry) {
offset := s.node.Applied() - int64(len(ents)) + 1
for i, ent := range ents {