Skip to content
Snippets Groups Projects
Commit 9dc3b40d authored by ale's avatar ale
Browse files

upstream fixes to coordination package

* Track ModifiedIndex, preventing missed updates
* Properly handle errors in presence protocol
parent e6bf4793
Branches
No related tags found
No related merge requests found
...@@ -164,6 +164,7 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e ...@@ -164,6 +164,7 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e
EtcdIndex: s.index, EtcdIndex: s.index,
} }
var nodes []*etcd.Node var nodes []*etcd.Node
var modifiedIndex uint64
key = strings.TrimSuffix(key, "/") key = strings.TrimSuffix(key, "/")
keyDirPfx := key + "/" keyDirPfx := key + "/"
for path, datum := range s.data { for path, datum := range s.data {
...@@ -174,6 +175,9 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e ...@@ -174,6 +175,9 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e
Value: datum.value, Value: datum.value,
ModifiedIndex: datum.index, ModifiedIndex: datum.index,
}) })
if datum.index > modifiedIndex {
modifiedIndex = datum.index
}
} }
} }
switch { switch {
...@@ -183,9 +187,10 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e ...@@ -183,9 +187,10 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e
resp.Node = nodes[0] resp.Node = nodes[0]
default: default:
resp.Node = &etcd.Node{ resp.Node = &etcd.Node{
Key: key, Key: key,
Dir: true, Dir: true,
Nodes: nodes, Nodes: nodes,
ModifiedIndex: modifiedIndex,
} }
} }
return resp, nil return resp, nil
...@@ -225,6 +230,7 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch ...@@ -225,6 +230,7 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch
// First scan the data to check for changes >= index. // First scan the data to check for changes >= index.
s.lock.Lock() s.lock.Lock()
var nodes []*etcd.Node var nodes []*etcd.Node
var modifiedIndex uint64
for k, d := range s.data { for k, d := range s.data {
if strings.HasPrefix(k, key) && d.index >= index { if strings.HasPrefix(k, key) && d.index >= index {
nodes = append(nodes, &etcd.Node{ nodes = append(nodes, &etcd.Node{
...@@ -232,6 +238,9 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch ...@@ -232,6 +238,9 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch
Value: d.value, Value: d.value,
ModifiedIndex: d.index, ModifiedIndex: d.index,
}) })
if d.index > modifiedIndex {
modifiedIndex = d.index
}
} }
} }
if len(nodes) > 0 { if len(nodes) > 0 {
...@@ -239,9 +248,10 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch ...@@ -239,9 +248,10 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch
resp := &etcd.Response{ resp := &etcd.Response{
Action: "update", Action: "update",
Node: &etcd.Node{ Node: &etcd.Node{
Key: key, Key: key,
Dir: true, Dir: true,
Nodes: nodes, Nodes: nodes,
ModifiedIndex: modifiedIndex,
}, },
EtcdIndex: s.index, EtcdIndex: s.index,
} }
......
...@@ -124,6 +124,7 @@ func (p *Presence) run() { ...@@ -124,6 +124,7 @@ func (p *Presence) run() {
if t.Sub(lastUpdate) > ttl { if t.Sub(lastUpdate) > ttl {
doinit = true doinit = true
} }
continue
} }
} }
lastUpdate = t lastUpdate = t
......
...@@ -138,7 +138,7 @@ func (w *Watcher) watcher(c chan<- *etcd.Response) { ...@@ -138,7 +138,7 @@ func (w *Watcher) watcher(c chan<- *etcd.Response) {
continue continue
} }
index = resp.EtcdIndex index = resp.Node.ModifiedIndex
c <- resp c <- resp
} }
......
autoradio (0.6.1) unstable; urgency=medium
* Rebuilt with Go 1.5.1.
* Fixes to the presence library.
-- ale <ale@incal.net> Thu, 20 Aug 2015 08:38:48 +0100
autoradio (0.6) unstable; urgency=medium autoradio (0.6) unstable; urgency=medium
* Etcd 2.0 compatibility. * Etcd 2.0 compatibility.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment