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):
conn = node.getConnection()
if primary is not None:
primary_node = app.nm.getByUUID(primary)
primary_node = app.nm.getByAddress(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:
......
......@@ -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.getUUID(), (
dump(primary), dump(self.app.primary_master_node.getUUID()))
assert primary == self.app.primary_master_node.getAddress(), (
primary, self.app.primary_master_node)
node.setUUID(uuid)
class StorageAnswersHandler(AnswerBaseHandler):
......
......@@ -100,7 +100,7 @@ class BootstrapManager(EventHandler):
master_node = nm.createMaster(address=address)
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:
# three cases here:
# - something goes wrong (unknown UUID)
......
......@@ -722,7 +722,7 @@ class RequestIdentification(Packet):
PNumber('num_partitions'),
PNumber('num_replicas'),
PUUID('your_uuid'),
PUUID('primary'),
PAddress('primary'),
PList('known_master_list',
PStruct('master',
PAddress('address'),
......
......@@ -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),
)
......
......@@ -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.getUUID() != primary:
and app.primary_master_node.getAddress() != primary:
# There are multiple primary master nodes. This is
# dangerous.
raise ElectionFailure, 'multiple primary master nodes'
primary_node = app.nm.getByUUID(primary)
primary_node = app.nm.getByAddress(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
......@@ -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.getUUID():
if primary != app.primary_master_node.getAddress():
raise PrimaryFailure('unexpected primary uuid')
if your_uuid != app.uuid:
......
......@@ -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.getUUID(), ()))
app.master_node.getAddress(), ()))
handler.connectionCompleted(conn)
......@@ -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))
......
......@@ -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.getUUID(), [])
10, 0, None, self.app.primary_master_node.getAddress(), [])
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.getUUID(), [])
10, 0, None, self.app.primary_master_node.getAddress(), [])
self.checkNotClosed(conn)
class StorageAnswerHandlerTests(NeoUnitTestBase):
......
......@@ -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({
'getUUID': primary,
'getAddress': 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({
'getUUID': primary,
'getAddress': primary,
})
self.assertEqual(self._requestIdentification(), primary)
......
......@@ -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({
'getUUID': master,
'getAddress': master,
})
self.identification.requestIdentification(conn, NodeTypes.CLIENT, uuid,
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