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

Replace INVALID_UUID values with None out of protocol.py module to unify

condition. Packet encoding and decoding handle None/INVALID_UUID mapping.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@871 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 00705a8c
...@@ -19,7 +19,7 @@ import logging ...@@ -19,7 +19,7 @@ import logging
from time import time from time import time
from neo.config import ConfigurationManager from neo.config import ConfigurationManager
from neo.protocol import INVALID_UUID, INVALID_PTID, MASTER_NODE_TYPE from neo.protocol import INVALID_PTID, MASTER_NODE_TYPE
from neo.node import NodeManager, MasterNode from neo.node import NodeManager, MasterNode
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ListeningConnection, ClientConnection from neo.connection import ListeningConnection, ClientConnection
...@@ -71,7 +71,7 @@ class Application(object): ...@@ -71,7 +71,7 @@ class Application(object):
# The partition table is initialized after getting the number of # The partition table is initialized after getting the number of
# partitions. # partitions.
self.pt = None self.pt = None
self.uuid = INVALID_UUID self.uuid = None
self.primary_master_node = None self.primary_master_node = None
self.ptid = INVALID_PTID self.ptid = INVALID_PTID
self.monitoring_handler = MasterMonitoringEventHandler(self) self.monitoring_handler = MasterMonitoringEventHandler(self)
...@@ -153,7 +153,7 @@ class Application(object): ...@@ -153,7 +153,7 @@ class Application(object):
row = [] row = []
try: try:
for cell in self.pt.getCellList(offset): for cell in self.pt.getCellList(offset):
if uuid != INVALID_UUID and cell.getUUID() != uuid: if uuid is not None and cell.getUUID() != uuid:
continue continue
else: else:
row.append((cell.getUUID(), cell.getState())) row.append((cell.getUUID(), cell.getState()))
......
...@@ -18,8 +18,7 @@ ...@@ -18,8 +18,7 @@
import logging import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo.protocol import INVALID_UUID, \ from neo.protocol import MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
ADMIN_NODE_TYPE, TEMPORARILY_DOWN_STATE ADMIN_NODE_TYPE, TEMPORARILY_DOWN_STATE
from neo.node import MasterNode, StorageNode, ClientNode, AdminNode from neo.node import MasterNode, StorageNode, ClientNode, AdminNode
from neo import protocol from neo import protocol
...@@ -168,11 +167,11 @@ class MasterBaseEventHandler(EventHandler): ...@@ -168,11 +167,11 @@ class MasterBaseEventHandler(EventHandler):
addr = (ip_address, port) addr = (ip_address, port)
# Try to retrieve it from nm # Try to retrieve it from nm
n = None n = None
if uuid != INVALID_UUID: if uuid is not None:
n = nm.getNodeByUUID(uuid) n = nm.getNodeByUUID(uuid)
if n is None: if n is None:
n = nm.getNodeByServer(addr) n = nm.getNodeByServer(addr)
if n is not None and uuid != INVALID_UUID: if n is not None and uuid is not None:
# node only exists by address, remove it # node only exists by address, remove it
nm.remove(n) nm.remove(n)
n = None n = None
...@@ -185,15 +184,15 @@ class MasterBaseEventHandler(EventHandler): ...@@ -185,15 +184,15 @@ class MasterBaseEventHandler(EventHandler):
if n is None: if n is None:
n = MasterNode(server = addr) n = MasterNode(server = addr)
nm.add(n) nm.add(n)
if uuid != INVALID_UUID: if uuid is not None:
# If I don't know the UUID yet, believe what the peer # If I don't know the UUID yet, believe what the peer
# told me at the moment. # told me at the moment.
if n.getUUID() is None: if n.getUUID() is None:
n.setUUID(uuid) n.setUUID(uuid)
else: else:
n.setUUID(INVALID_UUID) n.setUUID(None)
elif node_type in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE): elif node_type in (STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE):
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
if n is None: if n is None:
......
...@@ -32,7 +32,7 @@ class BootstrapManager(EventHandler): ...@@ -32,7 +32,7 @@ class BootstrapManager(EventHandler):
Manage the bootstrap stage, lookup for the primary master then connect to it Manage the bootstrap stage, lookup for the primary master then connect to it
""" """
def __init__(self, app, name, node_type, uuid=protocol.INVALID_UUID, server=NO_SERVER): def __init__(self, app, name, node_type, uuid=None, server=NO_SERVER):
EventHandler.__init__(self, app) EventHandler.__init__(self, app)
self.primary = None self.primary = None
self.server = server self.server = server
......
...@@ -26,7 +26,7 @@ from neo.client.mq import MQ ...@@ -26,7 +26,7 @@ from neo.client.mq import MQ
from neo.node import NodeManager, MasterNode, StorageNode from neo.node import NodeManager, MasterNode, StorageNode
from neo.connection import MTClientConnection from neo.connection import MTClientConnection
from neo import protocol from neo import protocol
from neo.protocol import INVALID_UUID, INVALID_TID, INVALID_PARTITION, \ from neo.protocol import INVALID_TID, INVALID_PARTITION, \
INVALID_PTID, CLIENT_NODE_TYPE, INVALID_SERIAL, \ INVALID_PTID, CLIENT_NODE_TYPE, INVALID_SERIAL, \
DOWN_STATE, HIDDEN_STATE DOWN_STATE, HIDDEN_STATE
from neo.client.handlers.master import PrimaryBootstrapHandler, \ from neo.client.handlers.master import PrimaryBootstrapHandler, \
...@@ -252,7 +252,7 @@ class Application(object): ...@@ -252,7 +252,7 @@ class Application(object):
master_node_list.append(server) master_node_list.append(server)
self.nm.add(MasterNode(server=server)) self.nm.add(MasterNode(server=server))
# no self-assigned UUID, primary master will supply us one # no self-assigned UUID, primary master will supply us one
self.uuid = INVALID_UUID self.uuid = None
self.mq_cache = MQ() self.mq_cache = MQ()
self.new_oid_list = [] self.new_oid_list = []
self.ptid = INVALID_PTID self.ptid = INVALID_PTID
...@@ -463,7 +463,7 @@ class Application(object): ...@@ -463,7 +463,7 @@ class Application(object):
# (...per client) # (...per client)
# - have a sleep in the code (yuck !) # - have a sleep in the code (yuck !)
sleep(5) sleep(5)
if self.uuid != INVALID_UUID: if self.uuid is not None:
# TODO: pipeline those 2 requests # TODO: pipeline those 2 requests
# This is currently impossible because _waitMessage can only # This is currently impossible because _waitMessage can only
# wait on one message at a time # wait on one message at a time
...@@ -481,7 +481,7 @@ class Application(object): ...@@ -481,7 +481,7 @@ class Application(object):
finally: finally:
conn.unlock() conn.unlock()
self._waitMessage(conn, msg_id, handler=self.primary_bootstrap_handler) self._waitMessage(conn, msg_id, handler=self.primary_bootstrap_handler)
ready = self.uuid != INVALID_UUID and self.pt is not None \ ready = self.uuid is not None and self.pt is not None \
and self.pt.operational() and self.pt.operational()
logging.info("connected to primary master node %s" % self.primary_master_node) logging.info("connected to primary master node %s" % self.primary_master_node)
return conn return conn
......
...@@ -19,7 +19,7 @@ import logging ...@@ -19,7 +19,7 @@ import logging
from neo.client.handlers import BaseHandler, AnswerBaseHandler from neo.client.handlers import BaseHandler, AnswerBaseHandler
from neo.protocol import MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \ from neo.protocol import MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
INVALID_UUID, RUNNING_STATE, TEMPORARILY_DOWN_STATE RUNNING_STATE, TEMPORARILY_DOWN_STATE
from neo.node import MasterNode, StorageNode from neo.node import MasterNode, StorageNode
from neo.pt import MTPartitionTable as PartitionTable from neo.pt import MTPartitionTable as PartitionTable
from neo.util import dump from neo.util import dump
...@@ -63,7 +63,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -63,7 +63,7 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
conn.setUUID(uuid) conn.setUUID(uuid)
node.setUUID(uuid) node.setUUID(uuid)
if your_uuid != INVALID_UUID: if your_uuid is not None:
# got an uuid from the primary master # got an uuid from the primary master
app.uuid = your_uuid app.uuid = your_uuid
...@@ -80,13 +80,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler): ...@@ -80,13 +80,13 @@ class PrimaryBootstrapHandler(AnswerBaseHandler):
if n is None: if n is None:
n = MasterNode(server = addr) n = MasterNode(server = addr)
app.nm.add(n) app.nm.add(n)
if uuid != INVALID_UUID: if uuid is not None:
# If I don't know the UUID yet, believe what the peer # If I don't know the UUID yet, believe what the peer
# told me at the moment. # told me at the moment.
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 != INVALID_UUID: if primary_uuid is not None:
primary_node = app.nm.getNodeByUUID(primary_uuid) primary_node = app.nm.getNodeByUUID(primary_uuid)
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
...@@ -236,11 +236,11 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -236,11 +236,11 @@ class PrimaryNotificationsHandler(BaseHandler):
addr = (ip_address, port) addr = (ip_address, port)
# Try to retrieve it from nm # Try to retrieve it from nm
n = None n = None
if uuid != INVALID_UUID: if uuid is not None:
n = nm.getNodeByUUID(uuid) n = nm.getNodeByUUID(uuid)
if n is None: if n is None:
n = nm.getNodeByServer(addr) n = nm.getNodeByServer(addr)
if n is not None and uuid != INVALID_UUID: if n is not None and uuid is not None:
# node only exists by address, remove it # node only exists by address, remove it
nm.remove(n) nm.remove(n)
n = None n = None
...@@ -253,13 +253,13 @@ class PrimaryNotificationsHandler(BaseHandler): ...@@ -253,13 +253,13 @@ class PrimaryNotificationsHandler(BaseHandler):
if n is None: if n is None:
n = MasterNode(server = addr) n = MasterNode(server = addr)
nm.add(n) nm.add(n)
if uuid != INVALID_UUID: if uuid is not None:
# If I don't know the UUID yet, believe what the peer # If I don't know the UUID yet, believe what the peer
# told me at the moment. # told me at the moment.
if n.getUUID() is None: if n.getUUID() is None:
n.setUUID(uuid) n.setUUID(uuid)
elif node_type == STORAGE_NODE_TYPE: elif node_type == STORAGE_NODE_TYPE:
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
if n is None: if n is None:
......
...@@ -200,7 +200,7 @@ class EpollEventManager(object): ...@@ -200,7 +200,7 @@ class EpollEventManager(object):
""" Return the connection associated to the UUID, None if the UUID is """ Return the connection associated to the UUID, None if the UUID is
None, invalid or not found""" None, invalid or not found"""
# FIXME: We may optimize this by using use a dict on UUIDs # FIXME: We may optimize this by using use a dict on UUIDs
if uuid in (None, protocol.INVALID_UUID): if uuid is None:
return None return None
for conn in self.connection_dict.values(): for conn in self.connection_dict.values():
if conn.getUUID() == uuid: if conn.getUUID() == uuid:
......
...@@ -24,7 +24,7 @@ from neo.config import ConfigurationManager ...@@ -24,7 +24,7 @@ from neo.config import ConfigurationManager
from neo import protocol from neo import protocol
from neo.protocol import \ from neo.protocol import \
RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \ RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
INVALID_UUID, INVALID_OID, INVALID_TID, INVALID_PTID, \ INVALID_OID, INVALID_TID, INVALID_PTID, \
CLIENT_NODE_TYPE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \ CLIENT_NODE_TYPE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \
UUID_NAMESPACES, ADMIN_NODE_TYPE, BOOTING UUID_NAMESPACES, ADMIN_NODE_TYPE, BOOTING
from neo.node import NodeManager, MasterNode, StorageNode, ClientNode, AdminNode from neo.node import NodeManager, MasterNode, StorageNode, ClientNode, AdminNode
...@@ -341,7 +341,7 @@ class Application(object): ...@@ -341,7 +341,7 @@ class Application(object):
except TypeError: except TypeError:
ip_address, port = '0.0.0.0', 0 ip_address, port = '0.0.0.0', 0
node_list.append((n.getNodeType(), ip_address, port, node_list.append((n.getNodeType(), ip_address, port,
n.getUUID() or INVALID_UUID, n.getState())) n.getUUID(), n.getState()))
# Split the packet if too huge. # Split the packet if too huge.
if len(node_list) == 10000: if len(node_list) == 10000:
conn.notify(protocol.notifyNodeInformation(node_list)) conn.notify(protocol.notifyNodeInformation(node_list))
...@@ -709,7 +709,7 @@ class Application(object): ...@@ -709,7 +709,7 @@ class Application(object):
def getNewUUID(self, node_type): def getNewUUID(self, node_type):
# build an UUID # build an UUID
uuid = os.urandom(15) uuid = os.urandom(15)
while uuid == INVALID_UUID[1:]: while uuid == '\00' * 15: # XXX: INVALID_UUID[1:]
uuid = os.urandom(15) uuid = os.urandom(15)
# look for the prefix # look for the prefix
prefix = UUID_NAMESPACES.get(node_type, None) prefix = UUID_NAMESPACES.get(node_type, None)
...@@ -721,7 +721,7 @@ class Application(object): ...@@ -721,7 +721,7 @@ class Application(object):
node = self.nm.getNodeByUUID(uuid) node = self.nm.getNodeByUUID(uuid)
if node is not None and node.getServer() is not None and node.getServer() != addr: if node is not None and node.getServer() is not None and node.getServer() != addr:
return False return False
return uuid != self.uuid and uuid != INVALID_UUID return uuid != self.uuid and uuid is not None
def getClusterState(self): def getClusterState(self):
return self.cluster_state return self.cluster_state
...@@ -762,26 +762,26 @@ class Application(object): ...@@ -762,26 +762,26 @@ class Application(object):
def identifyStorageNode(self, uuid, node): def identifyStorageNode(self, uuid, node):
# TODO: check all cases here, when server address change... # TODO: check all cases here, when server address change...
# in verification and running states, if the node is unknown but the # in verification and running states, if the node is unknown but the
# uuid != INVALID_UUID, we have to give it a new uuid, but in recovery # uuid is not None, we have to give it a new uuid, but in recovery
# the node must keep it's UUID # the node must keep it's UUID
state = protocol.RUNNING_STATE state = protocol.RUNNING_STATE
handler = None handler = None
if self.cluster_state == protocol.RECOVERING: if self.cluster_state == protocol.RECOVERING:
if uuid == protocol.INVALID_UUID: if uuid is None:
logging.info('reject empty storage node') logging.info('reject empty storage node')
raise protocol.NotReadyError raise protocol.NotReadyError
handler = handlers.RecoveryHandler handler = handlers.RecoveryHandler
elif self.cluster_state == protocol.VERIFYING: elif self.cluster_state == protocol.VERIFYING:
if uuid == INVALID_UUID or node is None: if uuid is None or node is None:
# if node is unknown, it has been forget when the current # if node is unknown, it has been forget when the current
# partition was validated by the admin # partition was validated by the admin
uuid = INVALID_UUID uuid = None
state = protocol.PENDING_STATE state = protocol.PENDING_STATE
handler = handlers.VerificationHandler handler = handlers.VerificationHandler
elif self.cluster_state == protocol.RUNNING: elif self.cluster_state == protocol.RUNNING:
if uuid == INVALID_UUID or node is None: if uuid is None or node is None:
# same as for verification # same as for verification
uuid = INVALID_UUID uuid = None
state = protocol.PENDING_STATE state = protocol.PENDING_STATE
handler = handlers.StorageServiceHandler handler = handlers.StorageServiceHandler
elif self.cluster_state == protocol.STOPPING: elif self.cluster_state == protocol.STOPPING:
......
...@@ -118,19 +118,18 @@ class MasterHandler(EventHandler): ...@@ -118,19 +118,18 @@ class MasterHandler(EventHandler):
elif app.primary_master_node is not None: elif app.primary_master_node is not None:
primary_uuid = app.primary_master_node.getUUID() primary_uuid = app.primary_master_node.getUUID()
else: else:
primary_uuid = protocol.INVALID_UUID primary_uuid = None
known_master_list = [app.server + (app.uuid, )] known_master_list = [app.server + (app.uuid, )]
for n in app.nm.getMasterNodeList(): for n in app.nm.getMasterNodeList():
if n.getState() == protocol.BROKEN_STATE: if n.getState() == protocol.BROKEN_STATE:
continue continue
known_master_list.append(n.getServer() + \ known_master_list.append(n.getServer() + (n.getUUID(), ))
(n.getUUID() or protocol.INVALID_UUID, ))
conn.answer(protocol.answerPrimaryMaster(primary_uuid, conn.answer(protocol.answerPrimaryMaster(primary_uuid,
known_master_list), packet) known_master_list), packet)
def handleAskClusterState(self, conn, packet): def handleAskClusterState(self, conn, packet):
assert conn.getUUID() != protocol.INVALID_UUID assert conn.getUUID() is not None
state = self.app.getClusterState() state = self.app.getClusterState()
conn.answer(protocol.answerClusterState(state), packet) conn.answer(protocol.answerClusterState(state), packet)
...@@ -155,7 +154,7 @@ class BaseServiceHandler(MasterHandler): ...@@ -155,7 +154,7 @@ class BaseServiceHandler(MasterHandler):
# No interest. # No interest.
continue continue
if uuid == protocol.INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
......
...@@ -22,7 +22,7 @@ from neo.protocol import CLIENT_NODE_TYPE, \ ...@@ -22,7 +22,7 @@ from neo.protocol import CLIENT_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, \
UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE, \ UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE, \
STORAGE_NODE_TYPE, ADMIN_NODE_TYPE, OUT_OF_DATE_STATE, \ STORAGE_NODE_TYPE, ADMIN_NODE_TYPE, OUT_OF_DATE_STATE, \
HIDDEN_STATE, INVALID_UUID, INTERNAL_ERROR_CODE HIDDEN_STATE, INTERNAL_ERROR_CODE
from neo.master.handlers import BaseServiceHandler from neo.master.handlers import BaseServiceHandler
from neo.protocol import UnexpectedPacketError from neo.protocol import UnexpectedPacketError
from neo.util import dump from neo.util import dump
......
...@@ -23,7 +23,6 @@ from neo.protocol import MASTER_NODE_TYPE, \ ...@@ -23,7 +23,6 @@ from neo.protocol import MASTER_NODE_TYPE, \
DOWN_STATE DOWN_STATE
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure from neo.exception import ElectionFailure
from neo.protocol import INVALID_UUID
from neo.node import MasterNode from neo.node import MasterNode
class ElectionHandler(MasterHandler): class ElectionHandler(MasterHandler):
...@@ -51,7 +50,7 @@ class ElectionHandler(MasterHandler): ...@@ -51,7 +50,7 @@ class ElectionHandler(MasterHandler):
app.nm.add(node) app.nm.add(node)
app.unconnected_master_node_set.add(addr) app.unconnected_master_node_set.add(addr)
if uuid != INVALID_UUID: if uuid is not None:
# If I don't know the UUID yet, believe what the peer # If I don't know the UUID yet, believe what the peer
# told me at the moment. # told me at the moment.
if node.getUUID() is None: if node.getUUID() is None:
...@@ -179,13 +178,13 @@ class ClientElectionHandler(MasterHandler): ...@@ -179,13 +178,13 @@ class ClientElectionHandler(MasterHandler):
app.nm.add(n) app.nm.add(n)
app.unconnected_master_node_set.add(addr) app.unconnected_master_node_set.add(addr)
if uuid != INVALID_UUID: if uuid is not None:
# If I don't know the UUID yet, believe what the peer # If I don't know the UUID yet, believe what the peer
# told me at the moment. # told me at the moment.
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 != INVALID_UUID: if primary_uuid 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_uuid:
......
...@@ -63,7 +63,7 @@ class IdentificationHandler(MasterHandler): ...@@ -63,7 +63,7 @@ class IdentificationHandler(MasterHandler):
# 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)
(uuid, node, state, handler, klass) = result (uuid, node, state, handler, klass) = result
if uuid == protocol.INVALID_UUID: if uuid is None:
# no valid uuid, give it one # no valid uuid, give it one
uuid = app.getNewUUID(node_type) uuid = app.getNewUUID(node_type)
if node is None: if node is None:
......
...@@ -21,7 +21,7 @@ from neo import protocol ...@@ -21,7 +21,7 @@ from neo import protocol
from neo.protocol import RUNNING_STATE, BROKEN_STATE, \ from neo.protocol import RUNNING_STATE, BROKEN_STATE, \
TEMPORARILY_DOWN_STATE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE TEMPORARILY_DOWN_STATE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.protocol import UnexpectedPacketError, INVALID_UUID, INVALID_PTID from neo.protocol import UnexpectedPacketError, INVALID_PTID
from neo.node import StorageNode from neo.node import StorageNode
from neo.util import dump from neo.util import dump
...@@ -39,7 +39,7 @@ class RecoveryHandler(MasterHandler): ...@@ -39,7 +39,7 @@ class RecoveryHandler(MasterHandler):
# No interest. # No interest.
continue continue
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
......
...@@ -21,7 +21,7 @@ from neo.protocol import MASTER_NODE_TYPE, \ ...@@ -21,7 +21,7 @@ from neo.protocol import MASTER_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, DOWN_STATE RUNNING_STATE, BROKEN_STATE, DOWN_STATE
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import ElectionFailure, PrimaryFailure from neo.exception import ElectionFailure, PrimaryFailure
from neo.protocol import UnexpectedPacketError, INVALID_UUID from neo.protocol import UnexpectedPacketError
from neo.node import MasterNode from neo.node import MasterNode
class SecondaryMasterHandler(MasterHandler): class SecondaryMasterHandler(MasterHandler):
...@@ -79,7 +79,7 @@ class PrimaryMasterHandler(MasterHandler): ...@@ -79,7 +79,7 @@ class PrimaryMasterHandler(MasterHandler):
n = MasterNode(server = addr) n = MasterNode(server = addr)
app.nm.add(n) app.nm.add(n)
if uuid != INVALID_UUID: if uuid is not None:
# If I don't know the UUID yet, believe what the peer # If I don't know the UUID yet, believe what the peer
# told me at the moment. # told me at the moment.
if n.getUUID() is None: if n.getUUID() is None:
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
import logging import logging
from neo import protocol from neo import protocol
from neo.protocol import CLIENT_NODE_TYPE, ADMIN_NODE_TYPE, INVALID_UUID, \ from neo.protocol import CLIENT_NODE_TYPE, ADMIN_NODE_TYPE, \
RUNNING_STATE, STORAGE_NODE_TYPE, TEMPORARILY_DOWN_STATE, STOPPING RUNNING_STATE, STORAGE_NODE_TYPE, TEMPORARILY_DOWN_STATE, STOPPING
from neo.master.handlers import BaseServiceHandler from neo.master.handlers import BaseServiceHandler
from neo import decorators from neo import decorators
...@@ -60,7 +60,7 @@ class ShutdownHandler(BaseServiceHandler): ...@@ -60,7 +60,7 @@ class ShutdownHandler(BaseServiceHandler):
# No interest. # No interest.
continue continue
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
......
...@@ -22,7 +22,7 @@ from neo.protocol import CLIENT_NODE_TYPE, \ ...@@ -22,7 +22,7 @@ from neo.protocol import CLIENT_NODE_TYPE, \
RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, \ RUNNING_STATE, BROKEN_STATE, TEMPORARILY_DOWN_STATE, \
UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE, \ UP_TO_DATE_STATE, FEEDING_STATE, DISCARDED_STATE, \
STORAGE_NODE_TYPE, ADMIN_NODE_TYPE, OUT_OF_DATE_STATE, \ STORAGE_NODE_TYPE, ADMIN_NODE_TYPE, OUT_OF_DATE_STATE, \
HIDDEN_STATE, INVALID_UUID, INTERNAL_ERROR_CODE HIDDEN_STATE, INTERNAL_ERROR_CODE
from neo.master.handlers import BaseServiceHandler from neo.master.handlers import BaseServiceHandler
from neo.protocol import UnexpectedPacketError from neo.protocol import UnexpectedPacketError
from neo.exception import OperationFailure from neo.exception import OperationFailure
......
...@@ -21,7 +21,6 @@ from neo.protocol import CLIENT_NODE_TYPE, RUNNING_STATE, BROKEN_STATE, \ ...@@ -21,7 +21,6 @@ from neo.protocol import CLIENT_NODE_TYPE, RUNNING_STATE, BROKEN_STATE, \
TEMPORARILY_DOWN_STATE, ADMIN_NODE_TYPE TEMPORARILY_DOWN_STATE, ADMIN_NODE_TYPE
from neo.master.handlers import MasterHandler from neo.master.handlers import MasterHandler
from neo.exception import VerificationFailure from neo.exception import VerificationFailure
from neo.protocol import INVALID_UUID
from neo.util import dump from neo.util import dump
class VerificationHandler(MasterHandler): class VerificationHandler(MasterHandler):
...@@ -41,7 +40,7 @@ class VerificationHandler(MasterHandler): ...@@ -41,7 +40,7 @@ class VerificationHandler(MasterHandler):
# No interest. # No interest.
continue continue
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import logging import logging
from neo.protocol import node_types, node_states from neo.protocol import node_types, node_states
from neo.protocol import INVALID_UUID, INVALID_PTID from neo.protocol import INVALID_PTID
from neo.event import EventManager from neo.event import EventManager
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.exception import OperationFailure from neo.exception import OperationFailure
...@@ -118,7 +118,7 @@ def printPTAction(options): ...@@ -118,7 +118,7 @@ def printPTAction(options):
if len(options): if len(options):
uuid = bin(options.pop(0)) uuid = bin(options.pop(0))
else: else:
uuid = INVALID_UUID uuid = None
return protocol.askPartitionList(min_offset, max_offset, uuid) return protocol.askPartitionList(min_offset, max_offset, uuid)
action_dict = { action_dict = {
......
...@@ -165,7 +165,7 @@ class NodeManager(object): ...@@ -165,7 +165,7 @@ class NodeManager(object):
return self.server_dict.get(server) return self.server_dict.get(server)
def getNodeByUUID(self, uuid): def getNodeByUUID(self, uuid):
if uuid in (None, protocol.INVALID_UUID): if uuid is None:
return None return None
return self.uuid_dict.get(uuid) return self.uuid_dict.get(uuid)
......
This diff is collapsed.
...@@ -23,7 +23,7 @@ from collections import deque ...@@ -23,7 +23,7 @@ from collections import deque
from neo.config import ConfigurationManager from neo.config import ConfigurationManager
from neo import protocol from neo import protocol
from neo.protocol import TEMPORARILY_DOWN_STATE, INVALID_UUID, INVALID_PTID, \ from neo.protocol import TEMPORARILY_DOWN_STATE, INVALID_PTID, \
partition_cell_states, HIDDEN_STATE partition_cell_states, HIDDEN_STATE
from neo.node import NodeManager, MasterNode, StorageNode from neo.node import NodeManager, MasterNode, StorageNode
from neo.event import EventManager from neo.event import EventManager
...@@ -81,9 +81,6 @@ class Application(object): ...@@ -81,9 +81,6 @@ class Application(object):
dm = self.dm dm = self.dm
self.uuid = dm.getUUID() self.uuid = dm.getUUID()
if self.uuid is None:
self.uuid = INVALID_UUID
num_partitions = dm.getNumPartitions() num_partitions = dm.getNumPartitions()
num_replicas = dm.getNumReplicas() num_replicas = dm.getNumReplicas()
......
...@@ -20,7 +20,7 @@ import logging ...@@ -20,7 +20,7 @@ import logging
from neo.handler import EventHandler from neo.handler import EventHandler
from neo import protocol from neo import protocol
from neo.protocol import Packet, UnexpectedPacketError, \ from neo.protocol import Packet, UnexpectedPacketError, \
INVALID_UUID, RUNNING_STATE, BROKEN_STATE, \ RUNNING_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \ MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE
from neo.util import dump from neo.util import dump
...@@ -104,11 +104,11 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -104,11 +104,11 @@ class BaseMasterHandler(BaseStorageHandler):
addr = (ip_address, port) addr = (ip_address, port)
# Try to retrieve it from nm # Try to retrieve it from nm
n = None n = None
if uuid != INVALID_UUID: if uuid is not None:
n = app.nm.getNodeByUUID(uuid) n = app.nm.getNodeByUUID(uuid)
if n is None: if n is None:
n = app.nm.getNodeByServer(addr) n = app.nm.getNodeByServer(addr)
if n is not None and uuid != INVALID_UUID: if n is not None and uuid is not None:
# node only exists by address, remove it # node only exists by address, remove it
app.nm.remove(n) app.nm.remove(n)
n = None n = None
...@@ -127,12 +127,12 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -127,12 +127,12 @@ class BaseMasterHandler(BaseStorageHandler):
app.nm.add(n) app.nm.add(n)
n.setState(state) n.setState(state)
if uuid != INVALID_UUID: if uuid is not None:
if n.getUUID() is None: if n.getUUID() is None:
n.setUUID(uuid) n.setUUID(uuid)
elif node_type == STORAGE_NODE_TYPE: elif node_type == STORAGE_NODE_TYPE:
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
...@@ -155,7 +155,7 @@ class BaseMasterHandler(BaseStorageHandler): ...@@ -155,7 +155,7 @@ class BaseMasterHandler(BaseStorageHandler):
n.setState(state) n.setState(state)
elif node_type == CLIENT_NODE_TYPE: elif node_type == CLIENT_NODE_TYPE:
if uuid == INVALID_UUID: if uuid is None:
# No interest. # No interest.
continue continue
......
...@@ -19,7 +19,7 @@ import logging ...@@ -19,7 +19,7 @@ import logging
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import Packet, \ from neo.protocol import Packet, \
INVALID_UUID, RUNNING_STATE, BROKEN_STATE, \ RUNNING_STATE, BROKEN_STATE, \
MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \ MASTER_NODE_TYPE, STORAGE_NODE_TYPE, CLIENT_NODE_TYPE, \
DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE, \ DOWN_STATE, TEMPORARILY_DOWN_STATE, HIDDEN_STATE, \
DISCARDED_STATE, OUT_OF_DATE_STATE, UnexpectedPacketError DISCARDED_STATE, OUT_OF_DATE_STATE, UnexpectedPacketError
...@@ -51,7 +51,7 @@ class HiddenHandler(BaseMasterHandler): ...@@ -51,7 +51,7 @@ class HiddenHandler(BaseMasterHandler):
for node_type, ip_address, port, uuid, state in node_list: for node_type, ip_address, port, uuid, state in node_list:
if node_type == STORAGE_NODE_TYPE: if node_type == STORAGE_NODE_TYPE:
if uuid == INVALID_UUID: if uuid == None:
# No interest. # No interest.
continue continue
......
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