Commit 3b3b254a authored by Vincent Pelletier's avatar Vincent Pelletier

Rename Packets.AcceptIdentification "primary_uuid" field.

Prepares for type change so it is easily reversible.
parent f35b298b
...@@ -29,7 +29,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -29,7 +29,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
app.trying_master_node = None app.trying_master_node = None
def _acceptIdentification(self, node, uuid, num_partitions, def _acceptIdentification(self, node, uuid, num_partitions,
num_replicas, your_uuid, primary_uuid, known_master_list): num_replicas, your_uuid, primary, known_master_list):
app = self.app app = self.app
# Register new master nodes. # Register new master nodes.
...@@ -47,13 +47,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -47,13 +47,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
assert found, (node, dump(uuid), known_master_list) assert found, (node, dump(uuid), known_master_list)
conn = node.getConnection() conn = node.getConnection()
if primary_uuid is not None: if primary is not None:
primary_node = app.nm.getByUUID(primary_uuid) primary_node = app.nm.getByUUID(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 UUID: %s. Ignoring.', logging.warning('Unknown primary master: %s. Ignoring.',
dump(primary_uuid)) dump(primary))
return return
else: else:
if app.trying_master_node is not primary_node: if app.trying_master_node is not primary_node:
......
...@@ -48,10 +48,10 @@ class StorageBootstrapHandler(AnswerBaseHandler): ...@@ -48,10 +48,10 @@ class StorageBootstrapHandler(AnswerBaseHandler):
raise NodeNotReady(message) raise NodeNotReady(message)
def _acceptIdentification(self, node, def _acceptIdentification(self, node,
uuid, num_partitions, num_replicas, your_uuid, primary_uuid, uuid, num_partitions, num_replicas, your_uuid, primary,
master_list): master_list):
assert primary_uuid == self.app.primary_master_node.getUUID(), ( assert primary == self.app.primary_master_node.getUUID(), (
dump(primary_uuid), dump(self.app.primary_master_node.getUUID())) dump(primary), dump(self.app.primary_master_node.getUUID()))
node.setUUID(uuid) node.setUUID(uuid)
class StorageAnswersHandler(AnswerBaseHandler): class StorageAnswersHandler(AnswerBaseHandler):
......
...@@ -90,7 +90,7 @@ class BootstrapManager(EventHandler): ...@@ -90,7 +90,7 @@ class BootstrapManager(EventHandler):
conn.close() conn.close()
def _acceptIdentification(self, node, uuid, num_partitions, def _acceptIdentification(self, node, uuid, num_partitions,
num_replicas, your_uuid, primary_uuid, known_master_list): num_replicas, your_uuid, primary, known_master_list):
nm = self.app.nm nm = self.app.nm
# Register new master nodes. # Register new master nodes.
...@@ -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_uuid) self.primary = nm.getByUUID(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_uuid'), PUUID('primary'),
PList('known_master_list', PList('known_master_list',
PStruct('master', PStruct('master',
PAddress('address'), PAddress('address'),
......
...@@ -79,7 +79,7 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -79,7 +79,7 @@ class ClientElectionHandler(BaseElectionHandler):
self.app.negotiating_master_node_set.discard(addr) self.app.negotiating_master_node_set.discard(addr)
def _acceptIdentification(self, node, peer_uuid, num_partitions, def _acceptIdentification(self, node, peer_uuid, num_partitions,
num_replicas, your_uuid, primary_uuid, known_master_list): num_replicas, your_uuid, primary, known_master_list):
app = self.app app = self.app
if your_uuid != app.uuid: if your_uuid != app.uuid:
...@@ -94,7 +94,7 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -94,7 +94,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_uuid or uuid == your_uuid, ( assert peer_uuid != 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)
...@@ -106,18 +106,18 @@ class ClientElectionHandler(BaseElectionHandler): ...@@ -106,18 +106,18 @@ class ClientElectionHandler(BaseElectionHandler):
if n.getUUID() is None or n.getUUID() != uuid: if n.getUUID() is None or n.getUUID() != uuid:
n.setUUID(uuid) n.setUUID(uuid)
if primary_uuid 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_uuid: and app.primary_master_node.getUUID() != 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_uuid) primary_node = app.nm.getByUUID(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('received an unknown primary node UUID') logging.warning('received an unknown primary node')
else: else:
# Whatever the situation is, I trust this master. # Whatever the situation is, I trust this master.
app.primary = False app.primary = False
......
...@@ -87,9 +87,9 @@ class PrimaryHandler(EventHandler): ...@@ -87,9 +87,9 @@ class PrimaryHandler(EventHandler):
n.setUUID(uuid) n.setUUID(uuid)
def _acceptIdentification(self, node, uuid, num_partitions, def _acceptIdentification(self, node, uuid, num_partitions,
num_replicas, your_uuid, primary_uuid, known_master_list): num_replicas, your_uuid, primary, known_master_list):
app = self.app app = self.app
if primary_uuid != app.primary_master_node.getUUID(): if primary != app.primary_master_node.getUUID():
raise PrimaryFailure('unexpected primary uuid') raise PrimaryFailure('unexpected primary uuid')
if your_uuid != app.uuid: if your_uuid != app.uuid:
......
...@@ -136,6 +136,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -136,6 +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
self.election.acceptIdentification( self.election.acceptIdentification(
master1_conn, master1_conn,
NodeTypes.MASTER, NodeTypes.MASTER,
...@@ -143,7 +144,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -143,7 +144,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
1, 1,
0, 0,
self.app.uuid, self.app.uuid,
master1_uuid, primary1,
[(master1.getAddress(), master1_uuid)], [(master1.getAddress(), master1_uuid)],
) )
self.assertNotEqual(self.app.primary_master_node, None) self.assertNotEqual(self.app.primary_master_node, None)
...@@ -155,6 +156,8 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -155,6 +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
primary3 = master3_uuid
master1_address = master1.getAddress() master1_address = master1.getAddress()
master2_address = master2.getAddress() master2_address = master2.getAddress()
master3_address = master3.getAddress() master3_address = master3.getAddress()
...@@ -165,7 +168,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -165,7 +168,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
1, 1,
0, 0,
self.app.uuid, self.app.uuid,
master1_uuid, primary1,
[(master1_address, master1_uuid)], [(master1_address, master1_uuid)],
) )
self.assertRaises(ElectionFailure, self.election.acceptIdentification, self.assertRaises(ElectionFailure, self.election.acceptIdentification,
...@@ -175,7 +178,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase): ...@@ -175,7 +178,7 @@ class MasterClientElectionTests(MasterClientElectionTestBase):
1, 1,
0, 0,
self.app.uuid, self.app.uuid,
master3_uuid, primary3,
[ [
(master1_address, master1_uuid), (master1_address, master1_uuid),
(master2_address, master2_uuid), (master2_address, master2_uuid),
...@@ -320,7 +323,7 @@ class MasterServerElectionTests(MasterClientElectionTestBase): ...@@ -320,7 +323,7 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
address, address,
self.app.name, self.app.name,
) )
node_type, uuid, partitions, replicas, _peer_uuid, primary_uuid, \ node_type, uuid, partitions, replicas, _peer_uuid, primary, \
master_list = self.checkAcceptIdentification(conn, decode=True) master_list = self.checkAcceptIdentification(conn, decode=True)
self.assertEqual(node_type, NodeTypes.MASTER) self.assertEqual(node_type, NodeTypes.MASTER)
self.assertEqual(uuid, self.app.uuid) self.assertEqual(uuid, self.app.uuid)
...@@ -329,7 +332,7 @@ class MasterServerElectionTests(MasterClientElectionTestBase): ...@@ -329,7 +332,7 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
self.assertTrue((address, peer_uuid) in master_list) self.assertTrue((address, peer_uuid) in master_list)
self.assertTrue(self.app.server 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) self.assertEqual(peer_uuid, _peer_uuid)
return primary_uuid return primary
def testRequestIdentificationDoesNotKnowPrimary(self): def testRequestIdentificationDoesNotKnowPrimary(self):
self.app.primary = False self.app.primary = False
...@@ -338,19 +341,19 @@ class MasterServerElectionTests(MasterClientElectionTestBase): ...@@ -338,19 +341,19 @@ class MasterServerElectionTests(MasterClientElectionTestBase):
def testRequestIdentificationKnowsPrimary(self): def testRequestIdentificationKnowsPrimary(self):
self.app.primary = False self.app.primary = False
primary_uuid = self.getNewUUID() primary = self.getNewUUID()
self.app.primary_master_node = Mock({ self.app.primary_master_node = Mock({
'getUUID': primary_uuid, 'getUUID': primary,
}) })
self.assertEqual(self._requestIdentification(), primary_uuid) self.assertEqual(self._requestIdentification(), primary)
def testRequestIdentificationIsPrimary(self): def testRequestIdentificationIsPrimary(self):
self.app.primary = True self.app.primary = True
primary_uuid = self.app.uuid primary = self.app.uuid
self.app.primary_master_node = Mock({ self.app.primary_master_node = Mock({
'getUUID': primary_uuid, 'getUUID': primary,
}) })
self.assertEqual(self._requestIdentification(), primary_uuid) self.assertEqual(self._requestIdentification(), primary)
def testAnnouncePrimary1(self): def testAnnouncePrimary1(self):
""" check the wrong cases """ """ check the wrong cases """
......
...@@ -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_uuid = self.getNewUUID() master = self.getNewUUID()
self.app.master_node = Mock({ self.app.master_node = Mock({
'getUUID': master_uuid, 'getUUID': master,
}) })
self.identification.requestIdentification(conn, NodeTypes.CLIENT, uuid, self.identification.requestIdentification(conn, NodeTypes.CLIENT, uuid,
None, self.app.name) None, self.app.name)
...@@ -93,11 +93,11 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase): ...@@ -93,11 +93,11 @@ class StorageIdentificationHandlerTests(NeoUnitTestBase):
self.assertEqual(node.getUUID(), uuid) self.assertEqual(node.getUUID(), uuid)
self.assertTrue(node.getConnection() is conn) self.assertTrue(node.getConnection() is conn)
args = self.checkAcceptIdentification(conn, decode=True) args = self.checkAcceptIdentification(conn, decode=True)
node_type, address, _np, _nr, _uuid, _master_uuid, _master_list = args node_type, address, _np, _nr, _uuid, _master, _master_list = args
self.assertEqual(node_type, NodeTypes.STORAGE) self.assertEqual(node_type, NodeTypes.STORAGE)
self.assertEqual(address, None) self.assertEqual(address, None)
self.assertEqual(_uuid, uuid) self.assertEqual(_uuid, uuid)
self.assertEqual(_master_uuid, master_uuid) self.assertEqual(_master, master)
# TODO: check _master_list ? # TODO: check _master_list ?
if __name__ == "__main__": if __name__ == "__main__":
......
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