Commit 9dc3b40d authored by ale's avatar ale

upstream fixes to coordination package

* Track ModifiedIndex, preventing missed updates
* Properly handle errors in presence protocol
parent e6bf4793
......@@ -164,6 +164,7 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e
EtcdIndex: s.index,
}
var nodes []*etcd.Node
var modifiedIndex uint64
key = strings.TrimSuffix(key, "/")
keyDirPfx := key + "/"
for path, datum := range s.data {
......@@ -174,6 +175,9 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e
Value: datum.value,
ModifiedIndex: datum.index,
})
if datum.index > modifiedIndex {
modifiedIndex = datum.index
}
}
}
switch {
......@@ -183,9 +187,10 @@ func (s *FakeEtcdClient) Get(key string, recursive, boh bool) (*etcd.Response, e
resp.Node = nodes[0]
default:
resp.Node = &etcd.Node{
Key: key,
Dir: true,
Nodes: nodes,
Key: key,
Dir: true,
Nodes: nodes,
ModifiedIndex: modifiedIndex,
}
}
return resp, nil
......@@ -225,6 +230,7 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch
// First scan the data to check for changes >= index.
s.lock.Lock()
var nodes []*etcd.Node
var modifiedIndex uint64
for k, d := range s.data {
if strings.HasPrefix(k, key) && d.index >= index {
nodes = append(nodes, &etcd.Node{
......@@ -232,6 +238,9 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch
Value: d.value,
ModifiedIndex: d.index,
})
if d.index > modifiedIndex {
modifiedIndex = d.index
}
}
}
if len(nodes) > 0 {
......@@ -239,9 +248,10 @@ func (s *FakeEtcdClient) Watch(key string, index uint64, recursive bool, respch
resp := &etcd.Response{
Action: "update",
Node: &etcd.Node{
Key: key,
Dir: true,
Nodes: nodes,
Key: key,
Dir: true,
Nodes: nodes,
ModifiedIndex: modifiedIndex,
},
EtcdIndex: s.index,
}
......
......@@ -124,6 +124,7 @@ func (p *Presence) run() {
if t.Sub(lastUpdate) > ttl {
doinit = true
}
continue
}
}
lastUpdate = t
......
......@@ -138,7 +138,7 @@ func (w *Watcher) watcher(c chan<- *etcd.Response) {
continue
}
index = resp.EtcdIndex
index = resp.Node.ModifiedIndex
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
* Etcd 2.0 compatibility.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment