Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
a5be7f16
Commit
a5be7f16
authored
Mar 23, 2012
by
Vincent Pelletier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Replace master uuid with master address in election.
parent
3b3b254a
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
36 additions
and
34 deletions
+36
-34
neo/client/handlers/master.py
neo/client/handlers/master.py
+2
-2
neo/client/handlers/storage.py
neo/client/handlers/storage.py
+2
-2
neo/lib/bootstrap.py
neo/lib/bootstrap.py
+1
-1
neo/lib/protocol.py
neo/lib/protocol.py
+1
-1
neo/master/handlers/__init__.py
neo/master/handlers/__init__.py
+4
-4
neo/master/handlers/election.py
neo/master/handlers/election.py
+8
-9
neo/master/handlers/secondary.py
neo/master/handlers/secondary.py
+1
-1
neo/storage/handlers/identification.py
neo/storage/handlers/identification.py
+1
-1
neo/tests/client/testMasterHandler.py
neo/tests/client/testMasterHandler.py
+4
-2
neo/tests/client/testStorageHandler.py
neo/tests/client/testStorageHandler.py
+3
-2
neo/tests/master/testElectionHandler.py
neo/tests/master/testElectionHandler.py
+7
-7
neo/tests/storage/testIdentificationHandler.py
neo/tests/storage/testIdentificationHandler.py
+2
-2
No files found.
neo/client/handlers/master.py
View file @
a5be7f16
...
...
@@ -48,12 +48,12 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
conn
=
node
.
getConnection
()
if
primary
is
not
None
:
primary_node
=
app
.
nm
.
getBy
UUID
(
primary
)
primary_node
=
app
.
nm
.
getBy
Address
(
primary
)
if
primary_node
is
None
:
# I don't know such a node. Probably this information
# is old. So ignore it.
logging
.
warning
(
'Unknown primary master: %s. Ignoring.'
,
dump
(
primary
)
)
primary
)
return
else
:
if
app
.
trying_master_node
is
not
primary_node
:
...
...
neo/client/handlers/storage.py
View file @
a5be7f16
...
...
@@ -50,8 +50,8 @@ class StorageBootstrapHandler(AnswerBaseHandler):
def
_acceptIdentification
(
self
,
node
,
uuid
,
num_partitions
,
num_replicas
,
your_uuid
,
primary
,
master_list
):
assert
primary
==
self
.
app
.
primary_master_node
.
get
UUID
(),
(
dump
(
primary
),
dump
(
self
.
app
.
primary_master_node
.
getUUID
())
)
assert
primary
==
self
.
app
.
primary_master_node
.
get
Address
(),
(
primary
,
self
.
app
.
primary_master_node
)
node
.
setUUID
(
uuid
)
class
StorageAnswersHandler
(
AnswerBaseHandler
):
...
...
neo/lib/bootstrap.py
View file @
a5be7f16
...
...
@@ -100,7 +100,7 @@ class BootstrapManager(EventHandler):
master_node
=
nm
.
createMaster
(
address
=
address
)
master_node
.
setUUID
(
uuid
)
self
.
primary
=
nm
.
getBy
UUID
(
primary
)
self
.
primary
=
nm
.
getBy
Address
(
primary
)
if
self
.
primary
is
None
or
self
.
current
is
not
self
.
primary
:
# three cases here:
# - something goes wrong (unknown UUID)
...
...
neo/lib/protocol.py
View file @
a5be7f16
...
...
@@ -722,7 +722,7 @@ class RequestIdentification(Packet):
PNumber
(
'num_partitions'
),
PNumber
(
'num_replicas'
),
PUUID
(
'your_uuid'
),
P
UUID
(
'primary'
),
P
Address
(
'primary'
),
PList
(
'known_master_list'
,
PStruct
(
'master'
,
PAddress
(
'address'
),
...
...
neo/master/handlers/__init__.py
View file @
a5be7f16
...
...
@@ -37,11 +37,11 @@ class MasterHandler(EventHandler):
node
=
app
.
nm
.
getByAddress
(
address
)
peer_uuid
=
self
.
_setupNode
(
conn
,
node_type
,
uuid
,
address
,
node
)
if
app
.
primary
:
primary_
uuid
=
app
.
uuid
primary_
address
=
app
.
server
elif
app
.
primary_master_node
is
not
None
:
primary_
uuid
=
app
.
primary_master_node
.
getUUID
()
primary_
address
=
app
.
primary_master_node
.
getAddress
()
else
:
primary_
uuid
=
None
primary_
address
=
None
known_master_list
=
[(
app
.
server
,
app
.
uuid
)]
for
n
in
app
.
nm
.
getMasterList
():
...
...
@@ -54,7 +54,7 @@ class MasterHandler(EventHandler):
app
.
pt
.
getPartitions
(),
app
.
pt
.
getReplicas
(),
peer_uuid
,
primary_
uuid
,
primary_
address
,
known_master_list
),
)
...
...
neo/master/handlers/election.py
View file @
a5be7f16
...
...
@@ -23,8 +23,8 @@ from neo.lib.handler import EventHandler
from
neo.lib.util
import
dump
from
.
import
MasterHandler
def
elect
(
app
,
peer_
uuid
,
peer_
address
):
if
app
.
uuid
<
peer_uuid
:
def
elect
(
app
,
peer_address
):
if
app
.
server
<
peer_address
:
app
.
primary
=
False
app
.
negotiating_master_node_set
.
discard
(
peer_address
)
...
...
@@ -83,10 +83,9 @@ class ClientElectionHandler(BaseElectionHandler):
app
=
self
.
app
if
your_uuid
!=
app
.
uuid
:
# uuid conflict happened, accept the new one
and restart election
# uuid conflict happened, accept the new one
app
.
uuid
=
your_uuid
logging
.
info
(
'UUID conflict, new UUID: %s'
,
dump
(
your_uuid
))
raise
ElectionFailure
,
'new uuid supplied'
node
.
setUUID
(
peer_uuid
)
...
...
@@ -94,7 +93,7 @@ class ClientElectionHandler(BaseElectionHandler):
for
address
,
uuid
in
known_master_list
:
if
app
.
server
==
address
:
# This is self.
assert
peer_uuid
!=
primary
or
uuid
==
your_uuid
,
(
assert
node
.
getAddress
()
!=
primary
or
uuid
==
your_uuid
,
(
dump
(
uuid
),
dump
(
your_uuid
))
continue
n
=
app
.
nm
.
getByAddress
(
address
)
...
...
@@ -109,11 +108,11 @@ class ClientElectionHandler(BaseElectionHandler):
if
primary
is
not
None
:
# The primary master is defined.
if
app
.
primary_master_node
is
not
None
\
and
app
.
primary_master_node
.
get
UUID
()
!=
primary
:
and
app
.
primary_master_node
.
get
Address
()
!=
primary
:
# There are multiple primary master nodes. This is
# dangerous.
raise
ElectionFailure
,
'multiple primary master nodes'
primary_node
=
app
.
nm
.
getBy
UUID
(
primary
)
primary_node
=
app
.
nm
.
getBy
Address
(
primary
)
if
primary_node
is
None
:
# I don't know such a node. Probably this information
# is old. So ignore it.
...
...
@@ -127,7 +126,7 @@ class ClientElectionHandler(BaseElectionHandler):
app
.
negotiating_master_node_set
.
clear
()
return
elect
(
app
,
peer_uuid
,
node
.
getAddress
())
elect
(
app
,
node
.
getAddress
())
class
ServerElectionHandler
(
BaseElectionHandler
,
MasterHandler
):
...
...
@@ -145,6 +144,6 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler):
node
.
setUUID
(
uuid
)
conn
.
setUUID
(
uuid
)
elect
(
app
,
uuid
,
address
)
elect
(
app
,
address
)
return
uuid
neo/master/handlers/secondary.py
View file @
a5be7f16
...
...
@@ -89,7 +89,7 @@ class PrimaryHandler(EventHandler):
def
_acceptIdentification
(
self
,
node
,
uuid
,
num_partitions
,
num_replicas
,
your_uuid
,
primary
,
known_master_list
):
app
=
self
.
app
if
primary
!=
app
.
primary_master_node
.
get
UUID
():
if
primary
!=
app
.
primary_master_node
.
get
Address
():
raise
PrimaryFailure
(
'unexpected primary uuid'
)
if
your_uuid
!=
app
.
uuid
:
...
...
neo/storage/handlers/identification.py
View file @
a5be7f16
...
...
@@ -72,5 +72,5 @@ class IdentificationHandler(EventHandler):
# accept the identification and trigger an event
conn
.
answer
(
Packets
.
AcceptIdentification
(
NodeTypes
.
STORAGE
,
uuid
and
app
.
uuid
,
app
.
pt
.
getPartitions
(),
app
.
pt
.
getReplicas
(),
uuid
,
app
.
master_node
.
get
UUID
(),
()))
app
.
master_node
.
get
Address
(),
()))
handler
.
connectionCompleted
(
conn
)
neo/tests/client/testMasterHandler.py
View file @
a5be7f16
...
...
@@ -70,18 +70,20 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
""" No UUID supplied """
node
,
conn
=
self
.
getKnownMaster
()
uuid
=
self
.
getNewUUID
()
addr
=
conn
.
getAddress
()
self
.
checkProtocolErrorRaised
(
self
.
handler
.
acceptIdentification
,
conn
,
NodeTypes
.
MASTER
,
uuid
,
100
,
0
,
None
,
uuid
,
[(
conn
.
getAddress
()
,
uuid
)],
addr
,
[(
addr
,
uuid
)],
)
def
test_acceptIdentification3
(
self
):
""" identification accepted """
node
,
conn
=
self
.
getKnownMaster
()
uuid
=
self
.
getNewUUID
()
addr
=
conn
.
getAddress
()
your_uuid
=
self
.
getNewUUID
()
self
.
handler
.
acceptIdentification
(
conn
,
NodeTypes
.
MASTER
,
uuid
,
100
,
2
,
your_uuid
,
uuid
,
[(
conn
.
getAddress
()
,
uuid
)])
100
,
2
,
your_uuid
,
addr
,
[(
addr
,
uuid
)])
self
.
assertEqual
(
self
.
app
.
uuid
,
your_uuid
)
self
.
assertEqual
(
node
.
getUUID
(),
uuid
)
self
.
assertTrue
(
isinstance
(
self
.
app
.
pt
,
PartitionTable
))
...
...
neo/tests/client/testStorageHandler.py
View file @
a5be7f16
...
...
@@ -39,6 +39,7 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
self
.
app
.
primary_master_node
=
node
=
Mock
({
'getConnection'
:
self
.
getFakeConnection
(),
'getUUID'
:
self
.
getNewUUID
(),
'getAddress'
:
(
self
.
local_ip
,
2999
)
})
self
.
_next_port
=
3000
...
...
@@ -62,14 +63,14 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
node
,
conn
=
self
.
getKnownStorage
()
self
.
handler
.
acceptIdentification
(
conn
,
NodeTypes
.
CLIENT
,
node
.
getUUID
(),
10
,
0
,
None
,
self
.
app
.
primary_master_node
.
get
UUID
(),
[])
10
,
0
,
None
,
self
.
app
.
primary_master_node
.
get
Address
(),
[])
self
.
checkClosed
(
conn
)
def
test_acceptIdentification2
(
self
):
node
,
conn
=
self
.
getKnownStorage
()
self
.
handler
.
acceptIdentification
(
conn
,
NodeTypes
.
STORAGE
,
node
.
getUUID
(),
10
,
0
,
None
,
self
.
app
.
primary_master_node
.
get
UUID
(),
[])
10
,
0
,
None
,
self
.
app
.
primary_master_node
.
get
Address
(),
[])
self
.
checkNotClosed
(
conn
)
class
StorageAnswerHandlerTests
(
NeoUnitTestBase
):
...
...
neo/tests/master/testElectionHandler.py
View file @
a5be7f16
...
...
@@ -136,7 +136,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
def
test_acceptIdentificationKnowsPrimary
(
self
):
master1
,
master1_conn
=
self
.
identifyToMasterNode
()
master1_uuid
=
master1
.
getUUID
()
primary1
=
master1
_uuid
primary1
=
master1
.
getAddress
()
self
.
election
.
acceptIdentification
(
master1_conn
,
NodeTypes
.
MASTER
,
...
...
@@ -156,8 +156,8 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
master1_uuid
=
master1
.
getUUID
()
master2_uuid
=
master2
.
getUUID
()
master3_uuid
=
master3
.
getUUID
()
primary1
=
master1
_uuid
primary3
=
master3
_uuid
primary1
=
master1
.
getAddress
()
primary3
=
master3
.
getAddress
()
master1_address
=
master1
.
getAddress
()
master2_address
=
master2
.
getAddress
()
master3_address
=
master3
.
getAddress
()
...
...
@@ -341,17 +341,17 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
def
testRequestIdentificationKnowsPrimary
(
self
):
self
.
app
.
primary
=
False
primary
=
self
.
getNewUUID
(
)
primary
=
(
self
.
local_ip
,
3000
)
self
.
app
.
primary_master_node
=
Mock
({
'get
UUID
'
:
primary
,
'get
Address
'
:
primary
,
})
self
.
assertEqual
(
self
.
_requestIdentification
(),
primary
)
def
testRequestIdentificationIsPrimary
(
self
):
self
.
app
.
primary
=
True
primary
=
self
.
app
.
uuid
primary
=
self
.
app
.
server
self
.
app
.
primary_master_node
=
Mock
({
'get
UUID
'
:
primary
,
'get
Address
'
:
primary
,
})
self
.
assertEqual
(
self
.
_requestIdentification
(),
primary
)
...
...
neo/tests/storage/testIdentificationHandler.py
View file @
a5be7f16
...
...
@@ -82,9 +82,9 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase):
uuid
=
self
.
getNewUUID
()
conn
=
self
.
getFakeConnection
(
uuid
=
uuid
)
node
=
self
.
app
.
nm
.
createClient
(
uuid
=
uuid
)
master
=
self
.
getNewUUID
(
)
master
=
(
self
.
local_ip
,
3000
)
self
.
app
.
master_node
=
Mock
({
'get
UUID
'
:
master
,
'get
Address
'
:
master
,
})
self
.
identification
.
requestIdentification
(
conn
,
NodeTypes
.
CLIENT
,
uuid
,
None
,
self
.
app
.
name
)
...
...
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