Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Iliya Manolov
neoppod
Commits
96827f57
Commit
96827f57
authored
Jan 03, 2012
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge called-once methods into their caller.
parent
caeac356
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
70 deletions
+53
-70
neo/master/app.py
neo/master/app.py
+53
-70
No files found.
neo/master/app.py
View file @
96827f57
...
@@ -150,6 +150,7 @@ class Application(object):
...
@@ -150,6 +150,7 @@ class Application(object):
to self as well as master nodes."""
to self as well as master nodes."""
neo
.
lib
.
logging
.
info
(
'begin the election of a primary master'
)
neo
.
lib
.
logging
.
info
(
'begin the election of a primary master'
)
client_handler
=
election
.
ClientElectionHandler
(
self
)
self
.
unconnected_master_node_set
.
clear
()
self
.
unconnected_master_node_set
.
clear
()
self
.
negotiating_master_node_set
.
clear
()
self
.
negotiating_master_node_set
.
clear
()
self
.
listening_conn
.
setHandler
(
election
.
ServerElectionHandler
(
self
))
self
.
listening_conn
.
setHandler
(
election
.
ServerElectionHandler
(
self
))
...
@@ -165,10 +166,60 @@ class Application(object):
...
@@ -165,10 +166,60 @@ class Application(object):
self
.
primary
=
None
self
.
primary
=
None
self
.
primary_master_node
=
None
self
.
primary_master_node
=
None
try
:
try
:
self
.
_doElection
(
bootstrap
)
# Wait at most 20 seconds at bootstrap. Otherwise, wait at most
# 10 seconds to avoid stopping the whole cluster for a long time.
# Note that even if not all master are up in the first 20 seconds
# this is not an issue because the first up will timeout and take
# the primary role.
if
bootstrap
:
expiration
=
20
else
:
expiration
=
10
t
=
0
while
True
:
current_time
=
time
()
if
current_time
>=
t
:
t
=
current_time
+
1
for
node
in
self
.
nm
.
getMasterList
():
if
not
node
.
isRunning
()
and
node
.
getLastStateChange
()
+
\
expiration
<
current_time
:
neo
.
lib
.
logging
.
info
(
'%s is down'
%
(
node
,
))
node
.
setDown
()
self
.
unconnected_master_node_set
.
discard
(
node
.
getAddress
())
# Try to connect to master nodes.
for
addr
in
self
.
unconnected_master_node_set
.
difference
(
x
.
getAddress
()
for
x
in
self
.
em
.
getClientList
()):
ClientConnection
(
self
.
em
,
client_handler
,
addr
=
addr
,
connector
=
self
.
connector_handler
())
self
.
em
.
poll
(
1
)
if
not
(
self
.
unconnected_master_node_set
or
self
.
negotiating_master_node_set
):
break
except
ElectionFailure
,
m
:
except
ElectionFailure
,
m
:
# something goes wrong, clean then restart
# something goes wrong, clean then restart
self
.
_electionFailed
(
m
)
neo
.
lib
.
logging
.
error
(
'election failed: %s'
,
(
m
,
))
# Ask all connected nodes to reelect a single primary master.
for
conn
in
self
.
em
.
getClientList
():
conn
.
notify
(
Packets
.
ReelectPrimary
())
conn
.
abort
()
# Wait until the connections are closed.
self
.
primary
=
None
self
.
primary_master_node
=
None
t
=
time
()
+
10
while
self
.
em
.
getClientList
()
and
time
()
<
t
:
try
:
self
.
em
.
poll
(
1
)
except
ElectionFailure
:
pass
# Close all connections.
for
conn
in
self
.
em
.
getClientList
()
+
self
.
em
.
getServerList
():
conn
.
close
()
bootstrap
=
False
bootstrap
=
False
else
:
else
:
# election succeed, stop the process
# election succeed, stop the process
...
@@ -176,48 +227,6 @@ class Application(object):
...
@@ -176,48 +227,6 @@ class Application(object):
break
break
def
_doElection
(
self
,
bootstrap
):
"""
Start the election process:
- Try to connect to any known master node
- Wait at most for the timeout defined by bootstrap parameter
When done, the current process is defined either as primary or
secondary master node
"""
# Wait at most 20 seconds at bootstrap. Otherwise, wait at most
# 10 seconds to avoid stopping the whole cluster for a long time.
# Note that even if not all master are up in the first 20 seconds
# this is not an issue because the first up will timeout and take
# the primary role.
if
bootstrap
:
expiration
=
20
else
:
expiration
=
10
client_handler
=
election
.
ClientElectionHandler
(
self
)
t
=
0
while
True
:
current_time
=
time
()
if
current_time
>=
t
:
t
=
current_time
+
1
for
node
in
self
.
nm
.
getMasterList
():
if
not
node
.
isRunning
()
and
node
.
getLastStateChange
()
+
\
expiration
<
current_time
:
neo
.
lib
.
logging
.
info
(
'%s is down'
%
(
node
,
))
node
.
setDown
()
self
.
unconnected_master_node_set
.
discard
(
node
.
getAddress
())
# Try to connect to master nodes.
for
addr
in
self
.
unconnected_master_node_set
.
difference
(
x
.
getAddress
()
for
x
in
self
.
em
.
getClientList
()):
ClientConnection
(
self
.
em
,
client_handler
,
addr
=
addr
,
connector
=
self
.
connector_handler
())
self
.
em
.
poll
(
1
)
if
not
(
self
.
unconnected_master_node_set
or
self
.
negotiating_master_node_set
):
break
def
_announcePrimary
(
self
):
def
_announcePrimary
(
self
):
"""
"""
Broadcast the announce that I'm the primary
Broadcast the announce that I'm the primary
...
@@ -236,32 +245,6 @@ class Application(object):
...
@@ -236,32 +245,6 @@ class Application(object):
break
break
def
_electionFailed
(
self
,
m
):
"""
Ask other masters to reelect a primary after an election failure.
"""
neo
.
lib
.
logging
.
error
(
'election failed: %s'
,
(
m
,
))
# Ask all connected nodes to reelect a single primary master.
for
conn
in
self
.
em
.
getClientList
():
conn
.
notify
(
Packets
.
ReelectPrimary
())
conn
.
abort
()
# Wait until the connections are closed.
self
.
primary
=
None
self
.
primary_master_node
=
None
t
=
time
()
+
10
while
self
.
em
.
getClientList
()
and
time
()
<
t
:
try
:
self
.
em
.
poll
(
1
)
except
ElectionFailure
:
pass
# Close all connections.
for
conn
in
self
.
em
.
getClientList
()
+
self
.
em
.
getServerList
():
conn
.
close
()
def
broadcastNodesInformation
(
self
,
node_list
):
def
broadcastNodesInformation
(
self
,
node_list
):
"""
"""
Broadcast changes for a set a nodes
Broadcast changes for a set a nodes
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment