diff --git a/server/v2/get_handler.go b/server/v2/get_handler.go index 9a67ea2ae..abdb94f7e 100644 --- a/server/v2/get_handler.go +++ b/server/v2/get_handler.go @@ -57,7 +57,7 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error { // Start the watcher on the store. eventChan, err := s.Store().Watch(key, recursive, sinceIndex) if err != nil { - return etcdErr.NewError(500, key, s.Store().Index()) + return err } cn, _ := w.(http.CloseNotifier) diff --git a/store/event_history.go b/store/event_history.go index 19d781def..cb3ab49c2 100644 --- a/store/event_history.go +++ b/store/event_history.go @@ -46,7 +46,7 @@ func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event, defer eh.rwl.RUnlock() // the index should locate after the event history's StartIndex - if index-eh.StartIndex < 0 { + if index < eh.StartIndex { return nil, etcdErr.NewError(etcdErr.EcodeEventIndexCleared, fmt.Sprintf("the requested history has been cleared [%v/%v]", @@ -81,7 +81,7 @@ func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event, i = (i + 1) % eh.Queue.Capacity - if i > eh.Queue.back() { + if i == eh.Queue.Back { return nil, nil } } @@ -95,6 +95,7 @@ func (eh *EventHistory) clone() *EventHistory { Events: make([]*Event, eh.Queue.Capacity), Size: eh.Queue.Size, Front: eh.Queue.Front, + Back: eh.Queue.Back, } for i, e := range eh.Queue.Events { diff --git a/store/event_queue.go b/store/event_queue.go index 0852956b1..e32bf4cc3 100644 --- a/store/event_queue.go +++ b/store/event_queue.go @@ -4,22 +4,17 @@ type eventQueue struct { Events []*Event Size int Front int + Back int Capacity int } -func (eq *eventQueue) back() int { - return (eq.Front + eq.Size - 1 + eq.Capacity) % eq.Capacity -} - func (eq *eventQueue) insert(e *Event) { - index := (eq.back() + 1) % eq.Capacity - - eq.Events[index] = e + eq.Events[eq.Back] = e + eq.Back = (eq.Back + 1) % eq.Capacity if eq.Size == eq.Capacity { //dequeue - eq.Front = (index + 1) % eq.Capacity + eq.Front = (eq.Front + 1) % eq.Capacity } else { eq.Size++ } - }