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 (
MasterElectionPath = "/icecast/cluster/master"
MountPrefix = "/icecast/mounts/"
NodePrefix = "/icecast/nodes/"
IcecastPort = 8000
)
// A mountpoint for a stream.
......
......@@ -28,7 +28,6 @@ type MasterElection struct {
stopped bool
Addr string
MasterAddr string
Path string
TTL uint64
......@@ -55,6 +54,14 @@ func (m *MasterElection) IsMaster() bool {
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) {
if m.State == state {
return
......@@ -100,27 +107,19 @@ func (m *MasterElection) Run() {
if m.State == STATE_MASTER {
prevValue = m.Addr
}
resp, ok, err := m.client.TestAndSet(m.Path, prevValue, m.Addr, m.TTL)
// if err != nil {
// log.Printf("%s: error from etcd: %s", m.Path, err)
// time.Sleep(20 * time.Millisecond)
// continue
// }
if ok {
if _, ok, _ := m.client.TestAndSet(m.Path, prevValue, m.Addr, m.TTL); ok {
// Howdy, we're the master now. Wait a while
// and renew our TTL.
m.setState(STATE_MASTER)
m.MasterAddr = m.Addr
time.Sleep(halfttl)
} else {
// We're not the master. Watch for a DELETE
// (in theory, but we're not actually
// verifying the action type, just waiting for
// the first event...)
// We're not the master. We could wait for a
// DELETE but I'm not sure if that's what you
// get on expiry, so we just wait for the
// first event which will be another SET from
// the current master. Oh well.
m.setState(STATE_SLAVE)
m.MasterAddr = resp.PrevValue
_, err := m.client.Watch(m.Path, resp.Index, nil, nil)
_, err := m.client.Watch(m.Path, 0, nil, nil)
if err != nil {
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.
Please register or to comment