mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
fix(event_history) fix a bug in event queue
This commit is contained in:
parent
70c8c09360
commit
ef988020b7
@ -57,7 +57,7 @@ func GetHandler(w http.ResponseWriter, req *http.Request, s Server) error {
|
|||||||
// Start the watcher on the store.
|
// Start the watcher on the store.
|
||||||
eventChan, err := s.Store().Watch(key, recursive, sinceIndex)
|
eventChan, err := s.Store().Watch(key, recursive, sinceIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return etcdErr.NewError(500, key, s.Store().Index())
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
cn, _ := w.(http.CloseNotifier)
|
cn, _ := w.(http.CloseNotifier)
|
||||||
|
@ -46,7 +46,7 @@ func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event,
|
|||||||
defer eh.rwl.RUnlock()
|
defer eh.rwl.RUnlock()
|
||||||
|
|
||||||
// the index should locate after the event history's StartIndex
|
// the index should locate after the event history's StartIndex
|
||||||
if index-eh.StartIndex < 0 {
|
if index < eh.StartIndex {
|
||||||
return nil,
|
return nil,
|
||||||
etcdErr.NewError(etcdErr.EcodeEventIndexCleared,
|
etcdErr.NewError(etcdErr.EcodeEventIndexCleared,
|
||||||
fmt.Sprintf("the requested history has been cleared [%v/%v]",
|
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
|
i = (i + 1) % eh.Queue.Capacity
|
||||||
|
|
||||||
if i > eh.Queue.back() {
|
if i == eh.Queue.Back {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -95,6 +95,7 @@ func (eh *EventHistory) clone() *EventHistory {
|
|||||||
Events: make([]*Event, eh.Queue.Capacity),
|
Events: make([]*Event, eh.Queue.Capacity),
|
||||||
Size: eh.Queue.Size,
|
Size: eh.Queue.Size,
|
||||||
Front: eh.Queue.Front,
|
Front: eh.Queue.Front,
|
||||||
|
Back: eh.Queue.Back,
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, e := range eh.Queue.Events {
|
for i, e := range eh.Queue.Events {
|
||||||
|
@ -4,22 +4,17 @@ type eventQueue struct {
|
|||||||
Events []*Event
|
Events []*Event
|
||||||
Size int
|
Size int
|
||||||
Front int
|
Front int
|
||||||
|
Back int
|
||||||
Capacity int
|
Capacity int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (eq *eventQueue) back() int {
|
|
||||||
return (eq.Front + eq.Size - 1 + eq.Capacity) % eq.Capacity
|
|
||||||
}
|
|
||||||
|
|
||||||
func (eq *eventQueue) insert(e *Event) {
|
func (eq *eventQueue) insert(e *Event) {
|
||||||
index := (eq.back() + 1) % eq.Capacity
|
eq.Events[eq.Back] = e
|
||||||
|
eq.Back = (eq.Back + 1) % eq.Capacity
|
||||||
eq.Events[index] = e
|
|
||||||
|
|
||||||
if eq.Size == eq.Capacity { //dequeue
|
if eq.Size == eq.Capacity { //dequeue
|
||||||
eq.Front = (index + 1) % eq.Capacity
|
eq.Front = (eq.Front + 1) % eq.Capacity
|
||||||
} else {
|
} else {
|
||||||
eq.Size++
|
eq.Size++
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user