Commit a5be7f16 authored by Vincent Pelletier's avatar Vincent Pelletier

Replace master uuid with master address in election.

parent 3b3b254a
...@@ -48,12 +48,12 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -48,12 +48,12 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
conn = node.getConnection() conn = node.getConnection()
if primary is not None: if primary is not None:
primary_node = app.nm.getByUUID(primary) primary_node = app.nm.getByAddress(primary)
if primary_node is None: if primary_node is None:
# I don't know such a node. Probably this information # I don't know such a node. Probably this information
# is old. So ignore it. # is old. So ignore it.
logging.warning('Unknown primary master: %s. Ignoring.', logging.warning('Unknown primary master: %s. Ignoring.',
dump(primary)) primary)
return return
else: else:
if app.trying_master_node is not primary_node: if app.trying_master_node is not primary_node:
......
...@@ -50,8 +50,8 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -50,8 +50,8 @@ class StorageBootstrapHandler(AnswerBaseHandler):
def _acceptIdentification(self, node, def _acceptIdentification(self, node,
uuid, num_partitions, num_replicas, your_uuid, primary, uuid, num_partitions, num_replicas, your_uuid, primary,
master_list): master_list):
assert primary == self.app.primary_master_node.getUUID(), ( assert primary == self.app.primary_master_node.getAddress(), (
dump(primary), dump(self.app.primary_master_node.getUUID())) primary, self.app.primary_master_node)
node.setUUID(uuid) node.setUUID(uuid)
class StorageAnswersHandler(AnswerBaseHandler): class StorageAnswersHandler(AnswerBaseHandler):
......
...@@ -100,7 +100,7 @@ class BootstrapManager(EventHandler): ...@@ -100,7 +100,7 @@ class BootstrapManager(EventHandler):
master_node = nm.createMaster(address=address) master_node = nm.createMaster(address=address)
master_node.setUUID(uuid) master_node.setUUID(uuid)
self.primary = nm.getByUUID(primary) self.primary = nm.getByAddress(primary)
if self.primary is None or self.current is not self.primary: if self.primary is None or self.current is not self.primary:
# three cases here: # three cases here:
# - something goes wrong (unknown UUID) # - something goes wrong (unknown UUID)
......
...@@ -722,7 +722,7 @@ class RequestIdentification(Packet): ...@@ -722,7 +722,7 @@ class RequestIdentification(Packet):
PNumber('num_partitions'), PNumber('num_partitions'),
PNumber('num_replicas'), PNumber('num_replicas'),
PUUID('your_uuid'), PUUID('your_uuid'),
PUUID('primary'), PAddress('primary'),
PList('known_master_list', PList('known_master_list',
PStruct('master', PStruct('master',
PAddress('address'), PAddress('address'),
......
...@@ -37,11 +37,11 @@ class MasterHandler(EventHandler): ...@@ -37,11 +37,11 @@ class MasterHandler(EventHandler):
node = app.nm.getByAddress(address) node = app.nm.getByAddress(address)
peer_uuid = self._setupNode(conn, node_type, uuid, address, node) peer_uuid = self._setupNode(conn, node_type, uuid, address, node)
if app.primary: if app.primary:
primary_uuid = app.uuid primary_address = app.server
elif app.primary_master_node is not None: elif app.primary_master_node is not None:
primary_uuid = app.primary_master_node.getUUID() primary_address = app.primary_master_node.getAddress()
else: else:
primary_uuid = None primary_address = None
known_master_list = [(app.server, app.uuid)] known_master_list = [(app.server, app.uuid)]
for n in app.nm.getMasterList(): for n in app.nm.getMasterList():
...@@ -54,7 +54,7 @@ class MasterHandler(EventHandler): ...@@ -54,7 +54,7 @@ class MasterHandler(EventHandler):
app.pt.getPartitions(), app.pt.getPartitions(),
app.pt.getReplicas(), app.pt.getReplicas(),
peer_uuid, peer_uuid,
primary_uuid, primary_address,
known_master_list), known_master_list),
) )
......
...@@ -23,8 +23,8 @@ from neo.lib.handler import EventHandler ...@@ -23,8 +23,8 @@ from neo.lib.handler import EventHandler
from neo.lib.util import dump from neo.lib.util import dump
from . import MasterHandler from . import MasterHandler
def elect(app, peer_uuid, peer_address): def elect(app, peer_address):
if app.uuid < peer_uuid: if app.server < peer_address:
app.primary = False app.primary = False
app.negotiating_master_node_set.discard(peer_address) app.negotiating_master_node_set.discard(peer_address)
...@@ -83,10 +83,9 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -83,10 +83,9 @@ class ClientElectionHandler(BaseElectionHandler):
app = self.app app = self.app
if your_uuid != app.uuid: 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 app.uuid = your_uuid
logging.info('UUID conflict, new UUID: %s', dump(your_uuid)) logging.info('UUID conflict, new UUID: %s', dump(your_uuid))
raise ElectionFailure, 'new uuid supplied'
node.setUUID(peer_uuid) node.setUUID(peer_uuid)
...@@ -94,7 +93,7 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -94,7 +93,7 @@ class ClientElectionHandler(BaseElectionHandler):
for address, uuid in known_master_list: for address, uuid in known_master_list:
if app.server == address: if app.server == address:
# This is self. # This is self.
assert peer_uuid != primary or uuid == your_uuid, ( assert node.getAddress() != primary or uuid == your_uuid, (
dump(uuid), dump(your_uuid)) dump(uuid), dump(your_uuid))
continue continue
n = app.nm.getByAddress(address) n = app.nm.getByAddress(address)
...@@ -109,11 +108,11 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -109,11 +108,11 @@ class ClientElectionHandler(BaseElectionHandler):
if primary is not None: if primary is not None:
# The primary master is defined. # The primary master is defined.
if app.primary_master_node is not None \ if app.primary_master_node is not None \
and app.primary_master_node.getUUID() != primary: and app.primary_master_node.getAddress() != primary:
# There are multiple primary master nodes. This is # There are multiple primary master nodes. This is
# dangerous. # dangerous.
raise ElectionFailure, 'multiple primary master nodes' raise ElectionFailure, 'multiple primary master nodes'
primary_node = app.nm.getByUUID(primary) primary_node = app.nm.getByAddress(primary)
if primary_node is None: if primary_node is None:
# I don't know such a node. Probably this information # I don't know such a node. Probably this information
# is old. So ignore it. # is old. So ignore it.
...@@ -127,7 +126,7 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -127,7 +126,7 @@ class ClientElectionHandler(BaseElectionHandler):
app.negotiating_master_node_set.clear() app.negotiating_master_node_set.clear()
return return
elect(app, peer_uuid, node.getAddress()) elect(app, node.getAddress())
class ServerElectionHandler(BaseElectionHandler, MasterHandler): class ServerElectionHandler(BaseElectionHandler, MasterHandler):
...@@ -145,6 +144,6 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler): ...@@ -145,6 +144,6 @@ class ServerElectionHandler(BaseElectionHandler, MasterHandler):
node.setUUID(uuid) node.setUUID(uuid)
conn.setUUID(uuid) conn.setUUID(uuid)
elect(app, uuid, address) elect(app, address)
return uuid return uuid
...@@ -89,7 +89,7 @@ class PrimaryHandler(EventHandler): ...@@ -89,7 +89,7 @@ class PrimaryHandler(EventHandler):
def _acceptIdentification(self, node, uuid, num_partitions, def _acceptIdentification(self, node, uuid, num_partitions,
num_replicas, your_uuid, primary, known_master_list): num_replicas, your_uuid, primary, known_master_list):
app = self.app app = self.app
if primary != app.primary_master_node.getUUID(): if primary != app.primary_master_node.getAddress():
raise PrimaryFailure('unexpected primary uuid') raise PrimaryFailure('unexpected primary uuid')
if your_uuid != app.uuid: if your_uuid != app.uuid:
......
...@@ -72,5 +72,5 @@ class IdentificationHandler(EventHandler): ...@@ -72,5 +72,5 @@ class IdentificationHandler(EventHandler):
# accept the identification and trigger an event # accept the identification and trigger an event
conn.answer(Packets.AcceptIdentification(NodeTypes.STORAGE, uuid and conn.answer(Packets.AcceptIdentification(NodeTypes.STORAGE, uuid and
app.uuid, app.pt.getPartitions(), app.pt.getReplicas(), uuid, app.uuid, app.pt.getPartitions(), app.pt.getReplicas(), uuid,
app.master_node.getUUID(), ())) app.master_node.getAddress(), ()))
handler.connectionCompleted(conn) handler.connectionCompleted(conn)
...@@ -70,18 +70,20 @@ class MasterBootstrapHandlerTests(MasterHandlerTests): ...@@ -70,18 +70,20 @@ class MasterBootstrapHandlerTests(MasterHandlerTests):
""" No UUID supplied """ """ No UUID supplied """
node, conn = self.getKnownMaster() node, conn = self.getKnownMaster()
uuid = self.getNewUUID() uuid = self.getNewUUID()
addr = conn.getAddress()
self.checkProtocolErrorRaised(self.handler.acceptIdentification, self.checkProtocolErrorRaised(self.handler.acceptIdentification,
conn, NodeTypes.MASTER, uuid, 100, 0, None, conn, NodeTypes.MASTER, uuid, 100, 0, None,
uuid, [(conn.getAddress(), uuid)], addr, [(addr, uuid)],
) )
def test_acceptIdentification3(self): def test_acceptIdentification3(self):
""" identification accepted """ """ identification accepted """
node, conn = self.getKnownMaster() node, conn = self.getKnownMaster()
uuid = self.getNewUUID() uuid = self.getNewUUID()
addr = conn.getAddress()
your_uuid = self.getNewUUID() your_uuid = self.getNewUUID()
self.handler.acceptIdentification(conn, NodeTypes.MASTER, uuid, 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(self.app.uuid, your_uuid)
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertTrue(isinstance(self.app.pt, PartitionTable)) self.assertTrue(isinstance(self.app.pt, PartitionTable))
......
...@@ -39,6 +39,7 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase): ...@@ -39,6 +39,7 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
self.app.primary_master_node = node = Mock({ self.app.primary_master_node = node = Mock({
'getConnection': self.getFakeConnection(), 'getConnection': self.getFakeConnection(),
'getUUID': self.getNewUUID(), 'getUUID': self.getNewUUID(),
'getAddress': (self.local_ip, 2999)
}) })
self._next_port = 3000 self._next_port = 3000
...@@ -62,14 +63,14 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase): ...@@ -62,14 +63,14 @@ class StorageBootstrapHandlerTests(NeoUnitTestBase):
node, conn = self.getKnownStorage() node, conn = self.getKnownStorage()
self.handler.acceptIdentification(conn, NodeTypes.CLIENT, self.handler.acceptIdentification(conn, NodeTypes.CLIENT,
node.getUUID(), node.getUUID(),
10, 0, None, self.app.primary_master_node.getUUID(), []) 10, 0, None, self.app.primary_master_node.getAddress(), [])
self.checkClosed(conn) self.checkClosed(conn)
def test_acceptIdentification2(self): def test_acceptIdentification2(self):
node, conn = self.getKnownStorage() node, conn = self.getKnownStorage()
self.handler.acceptIdentification(conn, NodeTypes.STORAGE, self.handler.acceptIdentification(conn, NodeTypes.STORAGE,
node.getUUID(), node.getUUID(),
10, 0, None, self.app.primary_master_node.getUUID(), []) 10, 0, None, self.app.primary_master_node.getAddress(), [])
self.checkNotClosed(conn) self.checkNotClosed(conn)
class StorageAnswerHandlerTests(NeoUnitTestBase): class StorageAnswerHandlerTests(NeoUnitTestBase):
......
...@@ -136,7 +136,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -136,7 +136,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
def test_acceptIdentificationKnowsPrimary(self): def test_acceptIdentificationKnowsPrimary(self):
master1, master1_conn = self.identifyToMasterNode() master1, master1_conn = self.identifyToMasterNode()
master1_uuid = master1.getUUID() master1_uuid = master1.getUUID()
primary1 = master1_uuid primary1 = master1.getAddress()
self.election.acceptIdentification( self.election.acceptIdentification(
master1_conn, master1_conn,
NodeTypes.MASTER, NodeTypes.MASTER,
...@@ -156,8 +156,8 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -156,8 +156,8 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
master1_uuid = master1.getUUID() master1_uuid = master1.getUUID()
master2_uuid = master2.getUUID() master2_uuid = master2.getUUID()
master3_uuid = master3.getUUID() master3_uuid = master3.getUUID()
primary1 = master1_uuid primary1 = master1.getAddress()
primary3 = master3_uuid primary3 = master3.getAddress()
master1_address = master1.getAddress() master1_address = master1.getAddress()
master2_address = master2.getAddress() master2_address = master2.getAddress()
master3_address = master3.getAddress() master3_address = master3.getAddress()
...@@ -341,17 +341,17 @@ class MasterServerElectionTests(MasterClientElectionTestBase): ...@@ -341,17 +341,17 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
def testRequestIdentificationKnowsPrimary(self): def testRequestIdentificationKnowsPrimary(self):
self.app.primary = False self.app.primary = False
primary = self.getNewUUID() primary = (self.local_ip, 3000)
self.app.primary_master_node = Mock({ self.app.primary_master_node = Mock({
'getUUID': primary, 'getAddress': primary,
}) })
self.assertEqual(self._requestIdentification(), primary) self.assertEqual(self._requestIdentification(), primary)
def testRequestIdentificationIsPrimary(self): def testRequestIdentificationIsPrimary(self):
self.app.primary = True self.app.primary = True
primary = self.app.uuid primary = self.app.server
self.app.primary_master_node = Mock({ self.app.primary_master_node = Mock({
'getUUID': primary, 'getAddress': primary,
}) })
self.assertEqual(self._requestIdentification(), primary) self.assertEqual(self._requestIdentification(), primary)
......
...@@ -82,9 +82,9 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase): ...@@ -82,9 +82,9 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase):
uuid = self.getNewUUID() uuid = self.getNewUUID()
conn = self.getFakeConnection(uuid=uuid) conn = self.getFakeConnection(uuid=uuid)
node = self.app.nm.createClient(uuid=uuid) node = self.app.nm.createClient(uuid=uuid)
master = self.getNewUUID() master = (self.local_ip, 3000)
self.app.master_node = Mock({ self.app.master_node = Mock({
'getUUID': master, 'getAddress': master,
}) })
self.identification.requestIdentification(conn, NodeTypes.CLIENT, uuid, self.identification.requestIdentification(conn, NodeTypes.CLIENT, uuid,
None, self.app.name) None, self.app.name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment