Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1162)

Unified Diff: mstate/machine.go

Issue 6501114: mstate/presence: bring it in line with mstate/watcher
Patch Set: mstate/presence: bring it in line with mstate/watcher Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « [revision details] ('k') | mstate/machine_test.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mstate/machine.go
=== modified file 'mstate/machine.go'
--- mstate/machine.go 2012-09-10 15:29:01 +0000
+++ mstate/machine.go 2012-09-11 13:23:57 +0000
@@ -80,35 +80,29 @@
}
// AgentAlive returns whether the respective remote agent is alive.
-func (m *Machine) AgentAlive() bool {
- return m.st.presencew.Alive(m.globalKey())
+func (m *Machine) AgentAlive() (bool, error) {
+ return m.st.pwatcher.Alive(m.globalKey())
}
// WaitAgentAlive blocks until the respective agent is alive.
-func (m *Machine) WaitAgentAlive(timeout time.Duration) error {
+func (m *Machine) WaitAgentAlive(timeout time.Duration) (err error) {
+ defer trivial.ErrorContextf(&err, "waiting for agent of machine %v", m)
ch := make(chan presence.Change)
- m.st.presencew.Add(m.globalKey(), ch)
- defer m.st.presencew.Remove(m.globalKey(), ch)
- // Initial check.
- select {
- case change := <-ch:
- if change.Alive {
- return nil
- }
- case <-time.After(timeout):
- return fmt.Errorf("waiting for agent of machine %v: still not alive after timeout", m)
- }
- // Hasn't been alive, so now wait for change.
- select {
- case change := <-ch:
- if change.Alive {
- return nil
- }
- panic(fmt.Sprintf("presence reported dead status twice in a row for machine %v", m))
- case <-time.After(timeout):
- return fmt.Errorf("waiting for agent of machine %v: still not alive after timeout", m)
- }
- panic("unreachable")
+ m.st.pwatcher.Watch(m.globalKey(), ch)
+ defer m.st.pwatcher.Unwatch(m.globalKey(), ch)
+ for i := 0; i < 2; i++ {
+ select {
+ case change := <-ch:
+ if change.Alive {
+ return nil
+ }
+ case <-time.After(timeout):
+ return fmt.Errorf("still not alive after timeout")
+ case <-m.st.pwatcher.Dying():
+ return m.st.pwatcher.Err()
+ }
+ }
+ panic(fmt.Sprintf("presence reported dead status twice in a row for machine %v", m))
}
// SetAgentAlive signals that the agent for machine m is alive.
« no previous file with comments | « [revision details] ('k') | mstate/machine_test.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b