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
Jérome Perrin
neoppod
Commits
9af67a09
Commit
9af67a09
authored
Mar 22, 2012
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only primary master allocates UUIDs.
parent
a5be7f16
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
22 additions
and
52 deletions
+22
-52
neo/master/app.py
neo/master/app.py
+12
-5
neo/master/handlers/election.py
neo/master/handlers/election.py
+0
-16
neo/master/handlers/secondary.py
neo/master/handlers/secondary.py
+0
-1
neo/tests/master/testElectionHandler.py
neo/tests/master/testElectionHandler.py
+1
-25
neo/tests/threaded/__init__.py
neo/tests/threaded/__init__.py
+9
-5
No files found.
neo/master/app.py
View file @
9af67a09
...
...
@@ -83,12 +83,9 @@ class Application(object):
self
.
cluster_state
=
None
self
.
_startup_allowed
=
False
# Generate an UUID for self
uuid
=
config
.
getUUID
()
if
uuid
is
None
or
uuid
==
''
:
uuid
=
self
.
getNewUUID
(
None
,
self
.
server
,
NodeTypes
.
MASTER
)
self
.
uuid
=
uuid
logging
.
info
(
'UUID : %s'
,
dump
(
uuid
))
if
uuid
:
self
.
uuid
=
uuid
# election related data
self
.
unconnected_master_node_set
=
set
()
...
...
@@ -331,6 +328,16 @@ class Application(object):
if
node
.
isRunning
():
node
.
setTemporarilyDown
()
if
self
.
uuid
is
None
:
self
.
uuid
=
self
.
getNewUUID
(
None
,
self
.
server
,
NodeTypes
.
MASTER
)
logging
.
info
(
'My UUID: '
+
dump
(
self
.
uuid
))
else
:
in_conflict
=
self
.
nm
.
getByUUID
(
self
.
uuid
)
if
in_conflict
is
not
None
:
logging
.
warning
(
'UUID conflict at election exit with %r'
,
in_conflict
)
in_conflict
.
setUUID
(
None
)
# recover the cluster status at startup
self
.
runManager
(
RecoveryManager
)
while
True
:
...
...
neo/master/handlers/election.py
View file @
9af67a09
...
...
@@ -82,13 +82,6 @@ class ClientElectionHandler(BaseElectionHandler):
num_replicas
,
your_uuid
,
primary
,
known_master_list
):
app
=
self
.
app
if
your_uuid
!=
app
.
uuid
:
# uuid conflict happened, accept the new one
app
.
uuid
=
your_uuid
logging
.
info
(
'UUID conflict, new UUID: %s'
,
dump
(
your_uuid
))
node
.
setUUID
(
peer_uuid
)
# Register new master nodes.
for
address
,
uuid
in
known_master_list
:
if
app
.
server
==
address
:
...
...
@@ -99,11 +92,6 @@ class ClientElectionHandler(BaseElectionHandler):
n
=
app
.
nm
.
getByAddress
(
address
)
if
n
is
None
:
n
=
app
.
nm
.
createMaster
(
address
=
address
)
if
uuid
is
not
None
:
# If I don't know the UUID yet, believe what the peer
# told me at the moment.
if
n
.
getUUID
()
is
None
or
n
.
getUUID
()
!=
uuid
:
n
.
setUUID
(
uuid
)
if
primary
is
not
None
:
# The primary master is defined.
...
...
@@ -139,11 +127,7 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler):
if
node
is
None
:
node
=
app
.
nm
.
createMaster
(
address
=
address
)
# supply another uuid in case of conflict
uuid
=
app
.
getNewUUID
(
uuid
,
address
,
node_type
)
node
.
setUUID
(
uuid
)
conn
.
setUUID
(
uuid
)
elect
(
app
,
address
)
return
uuid
neo/master/handlers/secondary.py
View file @
9af67a09
...
...
@@ -93,7 +93,6 @@ class PrimaryHandler(EventHandler):
raise
PrimaryFailure
(
'unexpected primary uuid'
)
if
your_uuid
!=
app
.
uuid
:
# uuid conflict happened, accept the new one
app
.
uuid
=
your_uuid
logging
.
info
(
'My UUID: '
+
dump
(
your_uuid
))
...
...
neo/tests/master/testElectionHandler.py
View file @
9af67a09
...
...
@@ -186,16 +186,6 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
],
)
def
test_acceptIdentification2
(
self
):
""" UUID conflict """
node
,
conn
=
self
.
identifyToMasterNode
()
new_uuid
=
self
.
_makeUUID
(
'M'
)
args
=
(
node
.
getUUID
(),
0
,
10
,
new_uuid
,
None
,
self
.
_getMasterList
())
self
.
assertRaises
(
ElectionFailure
,
self
.
election
.
acceptIdentification
,
conn
,
NodeTypes
.
MASTER
,
*
args
)
self
.
assertEqual
(
self
.
app
.
uuid
,
new_uuid
)
def
test_acceptIdentification3
(
self
):
""" Identification accepted """
node
,
conn
=
self
.
identifyToMasterNode
()
...
...
@@ -269,20 +259,6 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
self
.
assertEqual
(
node
.
getUUID
(),
new_uuid
)
self
.
assertNotEqual
(
node
.
getUUID
(),
uuid
)
def
test_requestIdentification5
(
self
):
""" UUID conflict """
node
,
conn
=
self
.
identifyToMasterNode
()
args
=
(
self
.
app
.
uuid
,
node
.
getAddress
(),
self
.
app
.
name
)
self
.
election
.
requestIdentification
(
conn
,
NodeTypes
.
MASTER
,
*
args
)
self
.
checkUUIDSet
(
conn
,
check_intermediate
=
False
)
args
=
self
.
checkAcceptIdentification
(
conn
,
decode
=
True
)
(
node_type
,
uuid
,
partitions
,
replicas
,
new_uuid
,
primary_uuid
,
master_list
)
=
args
self
.
assertNotEqual
(
self
.
app
.
uuid
,
new_uuid
)
self
.
assertEqual
(
self
.
app
.
uuid
,
uuid
)
def
_getNodeList
(
self
):
return
[
x
.
asTuple
()
for
x
in
self
.
app
.
nm
.
getList
()]
...
...
@@ -329,7 +305,7 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
self
.
assertEqual
(
uuid
,
self
.
app
.
uuid
)
self
.
assertEqual
(
partitions
,
self
.
app
.
pt
.
getPartitions
())
self
.
assertEqual
(
replicas
,
self
.
app
.
pt
.
getReplicas
())
self
.
assertTrue
(
(
address
,
peer_uuid
)
in
master_list
)
self
.
assertTrue
(
address
in
[
x
[
0
]
for
x
in
master_list
]
)
self
.
assertTrue
(
self
.
app
.
server
in
[
x
[
0
]
for
x
in
master_list
])
self
.
assertEqual
(
peer_uuid
,
_peer_uuid
)
return
primary
...
...
neo/tests/threaded/__init__.py
View file @
9af67a09
...
...
@@ -800,12 +800,16 @@ def predictable_random(seed=None):
if
node_type
==
NodeTypes
.
CLIENT
:
return
super
(
MasterApplication
,
self
).
getNewUUID
(
uuid
,
address
,
node_type
)
while
uuid
is
None
or
uuid
==
self
.
uuid
:
node
=
self
.
nm
.
getByUUID
(
uuid
)
if
node
is
None
or
node
.
getAddress
()
in
(
None
,
addr
):
uuid
=
UUID_NAMESPACES
[
node_type
]
+
''
.
join
(
if
None
!=
uuid
!=
self
.
uuid
and
\
self
.
nm
.
getByAddress
(
address
)
is
\
self
.
nm
.
getByUUID
(
uuid
):
return
uuid
while
True
:
uuid
=
UUID_NAMESPACES
[
node_type
]
+
''
.
join
(
chr
(
r
.
randrange
(
256
))
for
_
in
xrange
(
15
))
return
uuid
if
uuid
!=
self
.
uuid
and
\
self
.
nm
.
getByUUID
(
uuid
)
is
None
:
return
uuid
MasterApplication
.
getNewUUID
=
getNewUUID
administration
.
random
=
backup_app
.
random
=
replicator
.
random
\
...
...
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