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.
|
||||
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)
|
||||
|
@ -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 {
|
||||
|
@ -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++
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user