feat attach etcd-index,raft-index,raft-term to header

This commit is contained in:
Xiang Li 2013-11-09 20:20:47 -08:00
parent d87e0e93d3
commit d8e5994c35
3 changed files with 10 additions and 2 deletions

View File

@ -225,6 +225,7 @@ func (s *Server) Close() {
}
}
// Dispatch command to the current leader
func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Request) error {
ps := s.peerServer
if ps.raftServer.State() == raft.Leader {
@ -252,6 +253,12 @@ func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Reque
e, _ := result.(*store.Event)
b, _ = json.Marshal(e)
// etcd index should be the same as the event index
// which is also the last modified index of the node
w.Header().Add("X-Etcd-Index", fmt.Sprint(e.Index))
w.Header().Add("X-Raft-Index", fmt.Sprint(s.CommitIndex()))
w.Header().Add("X-Raft-Term", fmt.Sprint(s.Term()))
if e.IsCreated() {
w.WriteHeader(http.StatusCreated)
} else {

View File

@ -68,7 +68,9 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
}
}
w.Header().Add("X-Etcd-Index", fmt.Sprint(event.Index))
w.Header().Add("X-Etcd-Index", fmt.Sprint(s.Store().Index()))
w.Header().Add("X-Raft-Index", fmt.Sprint(s.CommitIndex()))
w.Header().Add("X-Raft-Term", fmt.Sprint(s.Term()))
w.WriteHeader(http.StatusOK)
b, _ := json.Marshal(event)

View File

@ -17,7 +17,6 @@ type Node struct {
Path string
CreateIndex uint64
CreateTerm uint64
ModifiedIndex uint64
Parent *Node `json:"-"` // should not encode this field! avoid circular dependency.