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
Ivan Tyagov
neoppod
Commits
f35b298b
Commit
f35b298b
authored
Mar 26, 2012
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make getNewUUID internally avoid duplicate UUIDs.
parent
58058cca
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
24 additions
and
21 deletions
+24
-21
neo/master/app.py
neo/master/app.py
+10
-12
neo/master/handlers/election.py
neo/master/handlers/election.py
+1
-2
neo/master/handlers/identification.py
neo/master/handlers/identification.py
+1
-2
neo/tests/threaded/__init__.py
neo/tests/threaded/__init__.py
+12
-5
No files found.
neo/master/app.py
View file @
f35b298b
...
...
@@ -46,6 +46,7 @@ class Application(object):
last_transaction
=
ZERO_TID
backup_tid
=
None
backup_app
=
None
uuid
=
None
def
__init__
(
self
,
config
):
# Internal attributes.
...
...
@@ -85,7 +86,7 @@ class Application(object):
# Generate an UUID for self
uuid
=
config
.
getUUID
()
if
uuid
is
None
or
uuid
==
''
:
uuid
=
self
.
getNewUUID
(
NodeTypes
.
MASTER
)
uuid
=
self
.
getNewUUID
(
No
ne
,
self
.
server
,
No
deTypes
.
MASTER
)
self
.
uuid
=
uuid
logging
.
info
(
'UUID : %s'
,
dump
(
uuid
))
...
...
@@ -424,17 +425,14 @@ class Application(object):
handler
.
connectionCompleted
(
conn
)
self
.
cluster_state
=
state
def
getNewUUID
(
self
,
node_type
):
try
:
return
UUID_NAMESPACES
[
node_type
]
+
os
.
urandom
(
15
)
except
KeyError
:
raise
RuntimeError
,
'No UUID namespace found for this node type'
def
isValidUUID
(
self
,
uuid
,
addr
):
if
uuid
==
self
.
uuid
or
uuid
is
None
:
return
False
node
=
self
.
nm
.
getByUUID
(
uuid
)
return
node
is
None
or
node
.
getAddress
()
in
(
None
,
addr
)
def
getNewUUID
(
self
,
uuid
,
address
,
node_type
):
if
None
!=
uuid
!=
self
.
uuid
and
\
self
.
nm
.
getByAddress
(
address
)
is
self
.
nm
.
getByUUID
(
uuid
):
return
uuid
while
True
:
uuid
=
UUID_NAMESPACES
[
node_type
]
+
os
.
urandom
(
15
)
if
uuid
!=
self
.
uuid
and
self
.
nm
.
getByUUID
(
uuid
)
is
None
:
return
uuid
def
getClusterState
(
self
):
return
self
.
cluster_state
...
...
neo/master/handlers/election.py
View file @
f35b298b
...
...
@@ -141,8 +141,7 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler):
if
node
is
None
:
node
=
app
.
nm
.
createMaster
(
address
=
address
)
# supply another uuid in case of conflict
while
not
app
.
isValidUUID
(
uuid
,
address
):
uuid
=
app
.
getNewUUID
(
node_type
)
uuid
=
app
.
getNewUUID
(
uuid
,
address
,
node_type
)
node
.
setUUID
(
uuid
)
conn
.
setUUID
(
uuid
)
...
...
neo/master/handlers/identification.py
View file @
f35b298b
...
...
@@ -67,8 +67,7 @@ class IdentificationHandler(MasterHandler):
else
:
raise
NotImplementedError
(
node_type
)
while
not
app
.
isValidUUID
(
uuid
,
address
):
uuid
=
app
.
getNewUUID
(
node_type
)
uuid
=
app
.
getNewUUID
(
uuid
,
address
,
node_type
)
logging
.
info
(
'Accept a'
+
human_readable_node_type
+
dump
(
uuid
))
if
node
is
None
:
node
=
node_ctor
(
uuid
=
uuid
,
address
=
address
)
...
...
neo/tests/threaded/__init__.py
View file @
f35b298b
...
...
@@ -796,11 +796,18 @@ def predictable_random(seed=None):
logging
.
info
(
"using seed %r"
,
s
)
r
=
random
.
Random
(
s
)
try
:
MasterApplication
.
getNewUUID
=
lambda
self
,
node_type
:
(
super
(
MasterApplication
,
self
).
getNewUUID
(
node_type
)
if
node_type
==
NodeTypes
.
CLIENT
else
UUID_NAMESPACES
[
node_type
]
+
''
.
join
(
chr
(
r
.
randrange
(
256
))
for
_
in
xrange
(
15
)))
def
getNewUUID
(
self
,
uuid
,
address
,
node_type
):
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
(
chr
(
r
.
randrange
(
256
))
for
_
in
xrange
(
15
))
return
uuid
MasterApplication
.
getNewUUID
=
getNewUUID
administration
.
random
=
backup_app
.
random
=
replicator
.
random
\
=
r
return
wrapped
(
*
args
,
**
kw
)
...
...
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