|
|
@@ -39,26 +39,27 @@ func (eh *EventHistory) addEvent(e *Event) *Event {
|
|
|
return e
|
|
|
}
|
|
|
|
|
|
-// scan function is enumerating events from the index in history and
|
|
|
-// stops till the first point where the key has identified key
|
|
|
+// scan enumerates events from the index history and stops at the first point
|
|
|
+// where the key matches.
|
|
|
func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event, *etcdErr.Error) {
|
|
|
eh.rwl.RLock()
|
|
|
defer eh.rwl.RUnlock()
|
|
|
|
|
|
- // the index should locate after the event history's StartIndex
|
|
|
- if index-eh.StartIndex < 0 {
|
|
|
+ // index should be after the event history's StartIndex
|
|
|
+ if index < eh.StartIndex {
|
|
|
return nil,
|
|
|
etcdErr.NewError(etcdErr.EcodeEventIndexCleared,
|
|
|
fmt.Sprintf("the requested history has been cleared [%v/%v]",
|
|
|
eh.StartIndex, index), 0)
|
|
|
}
|
|
|
|
|
|
- // the index should locate before the size of the queue minus the duplicate count
|
|
|
+ // the index should come before the size of the queue minus the duplicate count
|
|
|
if index > eh.LastIndex { // future index
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
- i := eh.Queue.Front
|
|
|
+ offset := index - eh.StartIndex
|
|
|
+ i := (eh.Queue.Front + int(offset)) % eh.Queue.Capacity
|
|
|
|
|
|
for {
|
|
|
e := eh.Queue.Events[i]
|
|
|
@@ -75,13 +76,13 @@ func (eh *EventHistory) scan(key string, recursive bool, index uint64) (*Event,
|
|
|
ok = ok || strings.HasPrefix(e.Node.Key, key)
|
|
|
}
|
|
|
|
|
|
- if ok && index <= e.Index() { // make sure we bypass the smaller one
|
|
|
+ if ok {
|
|
|
return e, nil
|
|
|
}
|
|
|
|
|
|
i = (i + 1) % eh.Queue.Capacity
|
|
|
|
|
|
- if i > eh.Queue.back() {
|
|
|
+ if i == eh.Queue.Back {
|
|
|
return nil, nil
|
|
|
}
|
|
|
}
|
|
|
@@ -95,6 +96,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 {
|