Commit c4923901 authored by Grégory Wisniewski's avatar Grégory Wisniewski

(Re-)Implement nodes identification conflicts.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@689 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent af1db176
...@@ -51,27 +51,46 @@ class IdentificationEventHandler(MasterEventHandler): ...@@ -51,27 +51,46 @@ class IdentificationEventHandler(MasterEventHandler):
def handleRequestNodeIdentification(self, conn, packet, node_type, def handleRequestNodeIdentification(self, conn, packet, node_type,
uuid, ip_address, port, name): uuid, ip_address, port, name):
# TODO: handle broken nodes
self.checkClusterName(name) self.checkClusterName(name)
app, nm = self.app, self.app.nm app, nm = self.app, self.app.nm
server = (ip_address, port) server = (ip_address, port)
node_by_uuid = nm.getNodeByUUID(uuid) node_by_uuid = nm.getNodeByUUID(uuid)
node_by_addr = nm.getNodeByServer(server) node_by_addr = nm.getNodeByServer(server)
if node_by_uuid is not None and node_by_addr is not None and \ def changeNodeAddress(node, server):
node_by_uuid is not node_by_addr: from copy import copy
# got a conflict, but UUIDs should be more reliable if node_type == protocol.STORAGE_NODE_TYPE:
# TODO: delete the old node... args = (node.getServer(), server)
raise RuntimeError('node conflict not implemented yet') # remove storage from partition table
pass cell_list = app.pt.dropNode(node)
node = node_by_uuid or node_by_addr if cell_list:
ptid = app.pt.setNextID()
if node is not None and node.getServer() != server: app.broadcastPartitionChanges(ptid, cell_list)
# address changed # TODO: check this, avoid copy()
# TODO: delete or update the old node ? # set it to down state
node.setState(protocol.DOWN_STATE)
app.broadcastNodeInformation(node)
nm.remove(node)
# then update the address and set it to running state
node = copy(node)
node.setServer(server) node.setServer(server)
raise RuntimeError('node address changement not implemented yet') node.setState(protocol.RUNNING_STATE)
nm.add(node)
return node
# handle conflicts and broken nodes
node = node_by_uuid or node_by_addr
if node_by_uuid is not None:
if node.getServer() == server and node.getState() == protocol.BROKEN_STATE:
raise protocol.BrokenNodeDisallowedError
if node.getServer() != server:
if node.getState() == protocol.RUNNING_STATE:
raise protocol.ProtocolError('invalid server address')
node = changeNodeAddress(node, server)
if node_by_uuid is None and node_by_addr is not None:
if node.getState() == protocol.RUNNING_STATE:
raise protocol.ProtocolError('invalid server address')
node = changeNodeAddress(node, server)
# ask the app the node identification, if refused, an exception is raised # ask the app the node identification, if refused, an exception is raised
result = self.app.identifyNode(node_type, uuid, node) result = self.app.identifyNode(node_type, uuid, node)
...@@ -90,7 +109,6 @@ class IdentificationEventHandler(MasterEventHandler): ...@@ -90,7 +109,6 @@ class IdentificationEventHandler(MasterEventHandler):
# set up the connection # set up the connection
conn.setUUID(uuid) conn.setUUID(uuid)
conn.setHandler(handler) conn.setHandler(handler)
# XXX: Here we could bin conn and node together
# answer # answer
args = (protocol.MASTER_NODE_TYPE, app.uuid, app.server[0], app.server[1], args = (protocol.MASTER_NODE_TYPE, app.uuid, app.server[0], app.server[1],
app.pt.getPartitions(), app.pt.getReplicas(), uuid) app.pt.getPartitions(), app.pt.getReplicas(), uuid)
......
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