Skip to content
Snippets Groups Projects
Commit 354f1a3c authored by ale's avatar ale
Browse files

fix syntax errors

parent 5ce6d0c9
No related branches found
No related tags found
No related merge requests found
...@@ -17,6 +17,8 @@ var ( ...@@ -17,6 +17,8 @@ var (
MasterElectionPath = "/icecast/cluster/master" MasterElectionPath = "/icecast/cluster/master"
MountPrefix = "/icecast/mounts/" MountPrefix = "/icecast/mounts/"
NodePrefix = "/icecast/nodes/" NodePrefix = "/icecast/nodes/"
IcecastPort = 8000
) )
// A mountpoint for a stream. // A mountpoint for a stream.
......
...@@ -28,7 +28,6 @@ type MasterElection struct { ...@@ -28,7 +28,6 @@ type MasterElection struct {
stopped bool stopped bool
Addr string Addr string
MasterAddr string
Path string Path string
TTL uint64 TTL uint64
...@@ -55,6 +54,14 @@ func (m *MasterElection) IsMaster() bool { ...@@ -55,6 +54,14 @@ func (m *MasterElection) IsMaster() bool {
return m.State == STATE_MASTER return m.State == STATE_MASTER
} }
func (m *MasterElection) GetMasterAddr() string {
responses, err := m.client.Get(m.Path)
if err != nil || len(responses) != 1 {
return ""
}
return responses[0].Value
}
func (m *MasterElection) setState(state int) { func (m *MasterElection) setState(state int) {
if m.State == state { if m.State == state {
return return
...@@ -100,27 +107,19 @@ func (m *MasterElection) Run() { ...@@ -100,27 +107,19 @@ func (m *MasterElection) Run() {
if m.State == STATE_MASTER { if m.State == STATE_MASTER {
prevValue = m.Addr prevValue = m.Addr
} }
resp, ok, err := m.client.TestAndSet(m.Path, prevValue, m.Addr, m.TTL) if _, ok, _ := m.client.TestAndSet(m.Path, prevValue, m.Addr, m.TTL); ok {
// if err != nil {
// log.Printf("%s: error from etcd: %s", m.Path, err)
// time.Sleep(20 * time.Millisecond)
// continue
// }
if ok {
// Howdy, we're the master now. Wait a while // Howdy, we're the master now. Wait a while
// and renew our TTL. // and renew our TTL.
m.setState(STATE_MASTER) m.setState(STATE_MASTER)
m.MasterAddr = m.Addr
time.Sleep(halfttl) time.Sleep(halfttl)
} else { } else {
// We're not the master. Watch for a DELETE // We're not the master. We could wait for a
// (in theory, but we're not actually // DELETE but I'm not sure if that's what you
// verifying the action type, just waiting for // get on expiry, so we just wait for the
// the first event...) // first event which will be another SET from
// the current master. Oh well.
m.setState(STATE_SLAVE) m.setState(STATE_SLAVE)
m.MasterAddr = resp.PrevValue _, err := m.client.Watch(m.Path, 0, nil, nil)
_, err := m.client.Watch(m.Path, resp.Index, nil, nil)
if err != nil { if err != nil {
log.Printf("%s: watch error: %s", m.Path, err) log.Printf("%s: watch error: %s", m.Path, err)
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment