Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
autoradio
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
autoradio
Commits
354f1a3c
Commit
354f1a3c
authored
11 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
fix syntax errors
parent
5ce6d0c9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api.go
+2
-0
2 additions, 0 deletions
api.go
masterelection/masterelection.go
+15
-16
15 additions, 16 deletions
masterelection/masterelection.go
with
17 additions
and
16 deletions
api.go
+
2
−
0
View file @
354f1a3c
...
@@ -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.
...
...
This diff is collapsed.
Click to expand it.
masterelection/masterelection.go
+
15
−
16
View file @
354f1a3c
...
@@ -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
)
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment