mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix index inconsistence in v1 api
This commit is contained in:
parent
f66bd1689d
commit
a5bca025b1
@ -260,7 +260,7 @@ func (s *Server) Dispatch(c raft.Command, w http.ResponseWriter, req *http.Reque
|
||||
|
||||
var b []byte
|
||||
if strings.HasPrefix(req.URL.Path, "/v1") {
|
||||
b, _ = json.Marshal(result.(*store.Event).Response())
|
||||
b, _ = json.Marshal(result.(*store.Event).Response(0))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
e, _ := result.(*store.Event)
|
||||
|
@ -19,7 +19,8 @@ func GetKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
||||
}
|
||||
|
||||
// Convert event to a response and write to client.
|
||||
b, _ := json.Marshal(event.Response())
|
||||
b, _ := json.Marshal(event.Response(s.Store().Index()))
|
||||
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(b)
|
||||
|
||||
|
@ -31,7 +31,8 @@ func WatchKeyHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
||||
}
|
||||
event := <-c
|
||||
|
||||
b, _ := json.Marshal(event.Response())
|
||||
// Convert event to a response and write to client.
|
||||
b, _ := json.Marshal(event.Response(s.Store().Index()))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(b)
|
||||
|
||||
|
@ -45,7 +45,7 @@ func (e *Event) Index() uint64 {
|
||||
}
|
||||
|
||||
// Converts an event object into a response object.
|
||||
func (event *Event) Response() interface{} {
|
||||
func (event *Event) Response(currentIndex uint64) interface{} {
|
||||
if !event.Node.Dir {
|
||||
response := &Response{
|
||||
Action: event.Action,
|
||||
@ -57,6 +57,10 @@ func (event *Event) Response() interface{} {
|
||||
Expiration: event.Node.Expiration,
|
||||
}
|
||||
|
||||
if currentIndex != 0 {
|
||||
response.Index = currentIndex
|
||||
}
|
||||
|
||||
if response.Action == Set {
|
||||
if response.PrevValue == "" {
|
||||
response.NewKey = true
|
||||
@ -79,6 +83,10 @@ func (event *Event) Response() interface{} {
|
||||
Dir: node.Dir,
|
||||
Index: node.ModifiedIndex,
|
||||
}
|
||||
|
||||
if currentIndex != 0 {
|
||||
responses[i].Index = currentIndex
|
||||
}
|
||||
}
|
||||
return responses
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user