mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
add watchHistory clone
This commit is contained in:
parent
2c9d57a9fe
commit
33e010ebd8
@ -151,3 +151,25 @@ func (eh *EventHistory) scan(prefix string, index uint64) (*Event, error) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// clone will be protected by a stop-world lock
|
||||
// do not need to obtain internal lock
|
||||
func (eh *EventHistory) clone() *EventHistory {
|
||||
|
||||
clonedQueue := eventQueue{
|
||||
Capacity: eh.Queue.Capacity,
|
||||
Events: make([]*Event, eh.Queue.Capacity),
|
||||
Size: eh.Queue.Size,
|
||||
Front: eh.Queue.Front,
|
||||
}
|
||||
|
||||
for i, e := range eh.Queue.Events {
|
||||
clonedQueue.Events[i] = e
|
||||
}
|
||||
|
||||
return &EventHistory{
|
||||
StartIndex: eh.StartIndex,
|
||||
Queue: clonedQueue,
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -247,7 +247,7 @@ func TestExpire(t *testing.T) {
|
||||
|
||||
s.Create("/foo", "bar", expire, 1, 1)
|
||||
|
||||
_, err := s.InternalGet("/foo", 1, 1)
|
||||
_, err := s.internalGet("/foo", 1, 1)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("can not get the node")
|
||||
@ -255,7 +255,7 @@ func TestExpire(t *testing.T) {
|
||||
|
||||
time.Sleep(time.Second * 2)
|
||||
|
||||
_, err = s.InternalGet("/foo", 1, 1)
|
||||
_, err = s.internalGet("/foo", 1, 1)
|
||||
|
||||
if err == nil {
|
||||
t.Fatalf("can get the node after expiration time")
|
||||
@ -266,7 +266,7 @@ func TestExpire(t *testing.T) {
|
||||
s.Create("/foo", "bar", expire, 1, 1)
|
||||
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
_, err = s.InternalGet("/foo", 1, 1)
|
||||
_, err = s.internalGet("/foo", 1, 1)
|
||||
|
||||
if err != nil {
|
||||
t.Fatalf("cannot get the node before expiration", err.Error())
|
||||
|
@ -118,5 +118,9 @@ func (wh *watcherHub) notify(e *Event) {
|
||||
}
|
||||
|
||||
func (wh *watcherHub) clone() *watcherHub {
|
||||
return &watcherHub{}
|
||||
clonedHistory := wh.EventHistory.clone()
|
||||
|
||||
return &watcherHub{
|
||||
EventHistory: clonedHistory,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user