Commit 6df1aa10 authored by Grégory Wisniewski's avatar Grégory Wisniewski

Do not use INVALID_OID/INVALID_TID/INVALID_PTID out of protocol.py module,

handle special cases with None values, protocol handle the few cases where a TID
can be invalid to indicate there is no value.


git-svn-id: https://svn.erp5.org/repos/neo/branches/prototype3@872 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent ad0d2ccf
...@@ -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_PTID, MASTER_NODE_TYPE from neo.protocol import 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
...@@ -73,7 +73,7 @@ class Application(object): ...@@ -73,7 +73,7 @@ class Application(object):
self.pt = None self.pt = None
self.uuid = None self.uuid = None
self.primary_master_node = None self.primary_master_node = None
self.ptid = INVALID_PTID self.ptid = None
self.monitoring_handler = MasterMonitoringEventHandler(self) self.monitoring_handler = MasterMonitoringEventHandler(self)
self.request_handler = MasterRequestEventHandler(self) self.request_handler = MasterRequestEventHandler(self)
self.dispatcher = Dispatcher() self.dispatcher = Dispatcher()
......
...@@ -26,9 +26,7 @@ from neo.client.mq import MQ ...@@ -26,9 +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_TID, INVALID_PARTITION, \ from neo.protocol import DOWN_STATE, HIDDEN_STATE
INVALID_PTID, CLIENT_NODE_TYPE, INVALID_SERIAL, \
DOWN_STATE, HIDDEN_STATE
from neo.client.handlers.master import PrimaryBootstrapHandler, \ from neo.client.handlers.master import PrimaryBootstrapHandler, \
PrimaryNotificationsHandler, PrimaryAnswersHandler PrimaryNotificationsHandler, PrimaryAnswersHandler
from neo.client.handlers.storage import StorageBootstrapHandler, \ from neo.client.handlers.storage import StorageBootstrapHandler, \
...@@ -83,7 +81,7 @@ class ConnectionPool(object): ...@@ -83,7 +81,7 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node) logging.error('Connection to storage node %s failed', node)
return None return None
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE,
app.uuid, '0.0.0.0', 0, app.name) app.uuid, '0.0.0.0', 0, app.name)
msg_id = conn.ask(app.local_var.queue, p) msg_id = conn.ask(app.local_var.queue, p)
finally: finally:
...@@ -255,7 +253,7 @@ class Application(object): ...@@ -255,7 +253,7 @@ class Application(object):
self.uuid = None 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 = None
self.storage_event_handler = StorageEventHandler(self, self.dispatcher) self.storage_event_handler = StorageEventHandler(self, self.dispatcher)
self.storage_bootstrap_handler = StorageBootstrapHandler(self) self.storage_bootstrap_handler = StorageBootstrapHandler(self)
self.storage_handler = StorageAnswersHandler(self) self.storage_handler = StorageAnswersHandler(self)
...@@ -441,7 +439,7 @@ class Application(object): ...@@ -441,7 +439,7 @@ class Application(object):
self.trying_master_node) self.trying_master_node)
self.primary_master_node = None self.primary_master_node = None
break break
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE, p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE,
self.uuid, '0.0.0.0', 0, self.name) self.uuid, '0.0.0.0', 0, self.name)
msg_id = conn.ask(self.local_var.queue, p) msg_id = conn.ask(self.local_var.queue, p)
finally: finally:
...@@ -526,7 +524,7 @@ class Application(object): ...@@ -526,7 +524,7 @@ class Application(object):
return hist[1][0][0] return hist[1][0][0]
def _load(self, oid, serial = INVALID_TID, tid = INVALID_TID, cache = 0): def _load(self, oid, serial=None, tid=None, cache=0):
"""Internal method which manage load ,loadSerial and loadBefore.""" """Internal method which manage load ,loadSerial and loadBefore."""
cell_list = self._getCellListForID(oid, readable=True) cell_list = self._getCellListForID(oid, readable=True)
if len(cell_list) == 0: if len(cell_list) == 0:
...@@ -592,8 +590,6 @@ class Application(object): ...@@ -592,8 +590,6 @@ class Application(object):
self.mq_cache[oid] = start_serial, data self.mq_cache[oid] = start_serial, data
finally: finally:
self._cache_lock_release() self._cache_lock_release()
if end_serial == INVALID_SERIAL:
end_serial = None
return data, start_serial, end_serial return data, start_serial, end_serial
...@@ -625,8 +621,6 @@ class Application(object): ...@@ -625,8 +621,6 @@ class Application(object):
def loadBefore(self, oid, tid): def loadBefore(self, oid, tid):
"""Load an object for a given oid before tid committed.""" """Load an object for a given oid before tid committed."""
# Do not try in cache as it manages only up-to-date object # Do not try in cache as it manages only up-to-date object
if tid is None:
tid = INVALID_TID
logging.debug('loading %s before %s', dump(oid), dump(tid)) logging.debug('loading %s before %s', dump(oid), dump(tid))
data, start, end = self._load(oid, tid=tid) data, start, end = self._load(oid, tid=tid)
if end is None: if end is None:
...@@ -657,8 +651,6 @@ class Application(object): ...@@ -657,8 +651,6 @@ class Application(object):
"""Store object.""" """Store object."""
if transaction is not self.local_var.txn: if transaction is not self.local_var.txn:
raise StorageTransactionError(self, transaction) raise StorageTransactionError(self, transaction)
if serial is None:
serial = INVALID_SERIAL
logging.debug('storing oid %s serial %s', logging.debug('storing oid %s serial %s',
dump(oid), dump(serial)) dump(oid), dump(serial))
# Find which storage node to use # Find which storage node to use
...@@ -884,7 +876,7 @@ class Application(object): ...@@ -884,7 +876,7 @@ class Application(object):
try: try:
conn.ask(self.local_var.queue, conn.ask(self.local_var.queue,
protocol.askTIDs(first, last, INVALID_PARTITION)) protocol.askTIDs(first, last, protocol.INVALID_PARTITION))
finally: finally:
conn.unlock() conn.unlock()
......
...@@ -24,7 +24,6 @@ from neo.config import ConfigurationManager ...@@ -24,7 +24,6 @@ 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_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
...@@ -77,9 +76,9 @@ class Application(object): ...@@ -77,9 +76,9 @@ class Application(object):
self.uuid = self.getNewUUID(MASTER_NODE_TYPE) self.uuid = self.getNewUUID(MASTER_NODE_TYPE)
# The last OID. # The last OID.
self.loid = INVALID_OID self.loid = None
# The last TID. # The last TID.
self.ltid = INVALID_TID self.ltid = None
# The target node's uuid to request next. # The target node's uuid to request next.
self.target_uuid = None self.target_uuid = None
...@@ -372,9 +371,9 @@ class Application(object): ...@@ -372,9 +371,9 @@ class Application(object):
self.changeClusterState(protocol.RECOVERING) self.changeClusterState(protocol.RECOVERING)
em = self.em em = self.em
self.loid = INVALID_OID self.loid = None
self.ltid = INVALID_TID self.ltid = None
self.pt.setID(INVALID_PTID) self.pt.setID(None)
self.target_uuid = None self.target_uuid = None
# collect the last partition table available # collect the last partition table available
...@@ -386,7 +385,7 @@ class Application(object): ...@@ -386,7 +385,7 @@ class Application(object):
self.changeClusterState(protocol.VERIFYING) self.changeClusterState(protocol.VERIFYING)
logging.info('startup allowed') logging.info('startup allowed')
if self.pt.getID() == INVALID_PTID: if self.pt.getID() is None:
self.buildFromScratch() self.buildFromScratch()
# FIXME: storage node with existing partition but not in the selected PT # FIXME: storage node with existing partition but not in the selected PT
......
...@@ -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_PTID from neo.protocol import UnexpectedPacketError
from neo.node import StorageNode from neo.node import StorageNode
from neo.util import dump from neo.util import dump
...@@ -89,7 +89,7 @@ class RecoveryHandler(MasterHandler): ...@@ -89,7 +89,7 @@ class RecoveryHandler(MasterHandler):
app.loid = loid app.loid = loid
if app.ltid < ltid: if app.ltid < ltid:
app.ltid = ltid app.ltid = ltid
if app.pt.getID() == INVALID_PTID or app.pt.getID() < lptid: if app.pt.getID() is None or app.pt.getID() < lptid:
# something newer # something newer
app.pt.setID(lptid) app.pt.setID(lptid)
app.target_uuid = conn.getUUID() app.target_uuid = conn.getUUID()
......
...@@ -28,7 +28,7 @@ class PartitionTable(neo.pt.PartitionTable): ...@@ -28,7 +28,7 @@ class PartitionTable(neo.pt.PartitionTable):
self.id = id self.id = id
def setNextID(self): def setNextID(self):
if self.id == protocol.INVALID_PTID: if self.id is None:
raise RuntimeError, 'I do not know the last Partition Table ID' raise RuntimeError, 'I do not know the last Partition Table ID'
last_id = unpack('!Q', self.id)[0] last_id = unpack('!Q', self.id)[0]
self.id = pack('!Q', last_id + 1) self.id = pack('!Q', last_id + 1)
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
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_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
...@@ -144,7 +143,7 @@ class Application(object): ...@@ -144,7 +143,7 @@ class Application(object):
self.connector_handler = getConnectorHandler(handler) self.connector_handler = getConnectorHandler(handler)
self.server = (ip, port) self.server = (ip, port)
self.em = EventManager() self.em = EventManager()
self.ptid = INVALID_PTID self.ptid = None
def getConnection(self): def getConnection(self):
if self.conn is None: if self.conn is None:
......
This diff is collapsed.
...@@ -57,7 +57,7 @@ class PartitionTable(object): ...@@ -57,7 +57,7 @@ class PartitionTable(object):
"""This class manages a partition table.""" """This class manages a partition table."""
def __init__(self, num_partitions, num_replicas): def __init__(self, num_partitions, num_replicas):
self.id = protocol.INVALID_PTID self.id = None
self.np = num_partitions self.np = num_partitions
self.nr = num_replicas self.nr = num_replicas
self.num_filled_rows = 0 self.num_filled_rows = 0
......
...@@ -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_PTID, \ from neo.protocol import TEMPORARILY_DOWN_STATE, \
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
...@@ -95,9 +95,7 @@ class Application(object): ...@@ -95,9 +95,7 @@ class Application(object):
dm.setName(self.name) dm.setName(self.name)
elif name != self.name: elif name != self.name:
raise RuntimeError('name does not match with the database') raise RuntimeError('name does not match with the database')
self.ptid = dm.getPTID() # return ptid or INVALID_PTID self.ptid = dm.getPTID()
if self.ptid == INVALID_PTID:
dm.setPTID(self.ptid)
logging.info("loaded configuration from db : uuid = %s, ptid = %s, name = %s, np = %s, nr = %s" \ logging.info("loaded configuration from db : uuid = %s, ptid = %s, name = %s, np = %s, nr = %s" \
%(dump(self.uuid), dump(self.ptid), name, num_partitions, num_replicas)) %(dump(self.uuid), dump(self.ptid), name, num_partitions, num_replicas))
......
...@@ -226,16 +226,9 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler): ...@@ -226,16 +226,9 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
app.queueEvent(self.handleAskObject, conn, packet, oid, app.queueEvent(self.handleAskObject, conn, packet, oid,
serial, tid) serial, tid)
return return
if serial == protocol.INVALID_SERIAL:
serial = None
if tid == protocol.INVALID_TID:
tid = None
o = app.dm.getObject(oid, serial, tid) o = app.dm.getObject(oid, serial, tid)
if o is not None: if o is not None:
serial, next_serial, compression, checksum, data = o serial, next_serial, compression, checksum, data = o
if next_serial is None:
next_serial = protocol.INVALID_SERIAL
logging.debug('oid = %s, serial = %s, next_serial = %s', logging.debug('oid = %s, serial = %s, next_serial = %s',
dump(oid), dump(serial), dump(next_serial)) dump(oid), dump(serial), dump(next_serial))
p = protocol.answerObject(oid, serial, next_serial, p = protocol.answerObject(oid, serial, next_serial,
......
...@@ -19,7 +19,7 @@ import logging ...@@ -19,7 +19,7 @@ import logging
from neo import protocol from neo import protocol
from neo.storage.handlers import BaseClientAndStorageOperationHandler from neo.storage.handlers import BaseClientAndStorageOperationHandler
from neo.protocol import INVALID_SERIAL, INVALID_TID, INVALID_PARTITION, \ from neo.protocol import INVALID_PARTITION, \
TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.util import dump from neo.util import dump
......
...@@ -19,8 +19,7 @@ import logging ...@@ -19,8 +19,7 @@ import logging
from neo import protocol from neo import protocol
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import INVALID_SERIAL, INVALID_TID, INVALID_PARTITION, \ from neo.protocol import TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.util import dump from neo.util import dump
from neo.node import StorageNode from neo.node import StorageNode
from neo.exception import PrimaryFailure, OperationFailure from neo.exception import PrimaryFailure, OperationFailure
......
...@@ -113,7 +113,7 @@ class ReplicationHandler(BaseStorageHandler): ...@@ -113,7 +113,7 @@ class ReplicationHandler(BaseStorageHandler):
present_serial_list = app.dm.getSerialListPresent(oid, serial_list) present_serial_list = app.dm.getSerialListPresent(oid, serial_list)
serial_set = set(serial_list) - set(present_serial_list) serial_set = set(serial_list) - set(present_serial_list)
for serial in serial_set: for serial in serial_set:
conn.ask(protocol.askObject(oid, serial, protocol.INVALID_TID), timeout=300) conn.ask(protocol.askObject(oid, serial, None), timeout=300)
# And, ask more serials. # And, ask more serials.
app.replicator.serial_offset += 1000 app.replicator.serial_offset += 1000
......
...@@ -28,8 +28,8 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler): ...@@ -28,8 +28,8 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler):
def handleAskLastIDs(self, conn, packet): def handleAskLastIDs(self, conn, packet):
app = self.app app = self.app
oid = app.dm.getLastOID() or protocol.INVALID_OID oid = app.dm.getLastOID()
tid = app.dm.getLastTID() or protocol.INVALID_TID tid = app.dm.getLastTID()
p = protocol.answerLastIDs(oid, tid, app.ptid) p = protocol.answerLastIDs(oid, tid, app.ptid)
conn.answer(p, packet) conn.answer(p, packet)
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
import logging import logging
from neo.storage.handlers import BaseMasterHandler from neo.storage.handlers import BaseMasterHandler
from neo.protocol import INVALID_OID, INVALID_TID, TEMPORARILY_DOWN_STATE from neo.protocol import TEMPORARILY_DOWN_STATE
from neo import protocol from neo import protocol
from neo.util import dump from neo.util import dump
from neo.node import StorageNode from neo.node import StorageNode
...@@ -29,8 +29,8 @@ class VerificationHandler(BaseMasterHandler): ...@@ -29,8 +29,8 @@ class VerificationHandler(BaseMasterHandler):
def handleAskLastIDs(self, conn, packet): def handleAskLastIDs(self, conn, packet):
app = self.app app = self.app
oid = app.dm.getLastOID() or INVALID_OID oid = app.dm.getLastOID()
tid = app.dm.getLastTID() or INVALID_TID tid = app.dm.getLastTID()
p = protocol.answerLastIDs(oid, tid, app.ptid) p = protocol.answerLastIDs(oid, tid, app.ptid)
conn.answer(p, packet) conn.answer(p, packet)
......
...@@ -25,7 +25,7 @@ from struct import pack, unpack ...@@ -25,7 +25,7 @@ from struct import pack, unpack
from neo.storage.database import DatabaseManager from neo.storage.database import DatabaseManager
from neo.exception import DatabaseFailure from neo.exception import DatabaseFailure
from neo.protocol import DISCARDED_STATE, INVALID_PTID from neo.protocol import DISCARDED_STATE
LOG_QUERIES = False LOG_QUERIES = False
...@@ -243,10 +243,7 @@ class MySQLDatabaseManager(DatabaseManager): ...@@ -243,10 +243,7 @@ class MySQLDatabaseManager(DatabaseManager):
self.commit() self.commit()
def getPTID(self): def getPTID(self):
ptid = self.getConfiguration('ptid') return self.getConfiguration('ptid')
if ptid is None:
return INVALID_PTID
return ptid
def setPTID(self, ptid): def setPTID(self, ptid):
self.begin() self.begin()
......
...@@ -21,7 +21,7 @@ from random import choice ...@@ -21,7 +21,7 @@ from random import choice
from neo.storage import handlers from neo.storage import handlers
from neo import protocol from neo import protocol
from neo.protocol import STORAGE_NODE_TYPE, UP_TO_DATE_STATE, \ from neo.protocol import STORAGE_NODE_TYPE, UP_TO_DATE_STATE, \
OUT_OF_DATE_STATE, INVALID_TID, RUNNING_STATE OUT_OF_DATE_STATE, RUNNING_STATE
from neo.connection import ClientConnection from neo.connection import ClientConnection
from neo.util import dump from neo.util import dump
......
...@@ -27,7 +27,7 @@ from neo.storage.app import Application, StorageNode ...@@ -27,7 +27,7 @@ from neo.storage.app import Application, StorageNode
from neo.storage.handlers import InitializationHandler from neo.storage.handlers import InitializationHandler
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE
from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \ from neo.protocol import BROKEN_STATE, RUNNING_STATE, Packet, INVALID_UUID, \
UP_TO_DATE_STATE, INVALID_OID, INVALID_TID, PROTOCOL_ERROR_CODE UP_TO_DATE_STATE, INVALID_TID, PROTOCOL_ERROR_CODE
from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \ from neo.protocol import ACCEPT_NODE_IDENTIFICATION, REQUEST_NODE_IDENTIFICATION, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \ NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \ ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \
......
...@@ -19,7 +19,7 @@ import unittest, logging, os ...@@ -19,7 +19,7 @@ import unittest, logging, os
from mock import Mock from mock import Mock
from neo.tests.base import NeoTestBase from neo.tests.base import NeoTestBase
from neo.storage.app import Application from neo.storage.app import Application
from neo.protocol import INVALID_PTID, INVALID_OID, INVALID_TID, \ from neo.protocol import INVALID_PTID, INVALID_TID, \
INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE INVALID_UUID, Packet, NOTIFY_NODE_INFORMATION, UP_TO_DATE_STATE
from neo.node import MasterNode, ClientNode, StorageNode from neo.node import MasterNode, ClientNode, StorageNode
from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager from neo.storage.mysqldb import p64, u64, MySQLDatabaseManager
......
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