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
from time import time
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.event import EventManager
from neo.connection import ListeningConnection, ClientConnection
......@@ -73,7 +73,7 @@ class Application(object):
self.pt = None
self.uuid = None
self.primary_master_node = None
self.ptid = INVALID_PTID
self.ptid = None
self.monitoring_handler = MasterMonitoringEventHandler(self)
self.request_handler = MasterRequestEventHandler(self)
self.dispatcher = Dispatcher()
......
......@@ -26,9 +26,7 @@ from neo.client.mq import MQ
from neo.node import NodeManager, MasterNode, StorageNode
from neo.connection import MTClientConnection
from neo import protocol
from neo.protocol import INVALID_TID, INVALID_PARTITION, \
INVALID_PTID, CLIENT_NODE_TYPE, INVALID_SERIAL, \
DOWN_STATE, HIDDEN_STATE
from neo.protocol import DOWN_STATE, HIDDEN_STATE
from neo.client.handlers.master import PrimaryBootstrapHandler, \
PrimaryNotificationsHandler, PrimaryAnswersHandler
from neo.client.handlers.storage import StorageBootstrapHandler, \
......@@ -83,7 +81,7 @@ class ConnectionPool(object):
logging.error('Connection to storage node %s failed', node)
return None
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE,
p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE,
app.uuid, '0.0.0.0', 0, app.name)
msg_id = conn.ask(app.local_var.queue, p)
finally:
......@@ -255,7 +253,7 @@ class Application(object):
self.uuid = None
self.mq_cache = MQ()
self.new_oid_list = []
self.ptid = INVALID_PTID
self.ptid = None
self.storage_event_handler = StorageEventHandler(self, self.dispatcher)
self.storage_bootstrap_handler = StorageBootstrapHandler(self)
self.storage_handler = StorageAnswersHandler(self)
......@@ -441,7 +439,7 @@ class Application(object):
self.trying_master_node)
self.primary_master_node = None
break
p = protocol.requestNodeIdentification(CLIENT_NODE_TYPE,
p = protocol.requestNodeIdentification(protocol.CLIENT_NODE_TYPE,
self.uuid, '0.0.0.0', 0, self.name)
msg_id = conn.ask(self.local_var.queue, p)
finally:
......@@ -526,7 +524,7 @@ class Application(object):
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."""
cell_list = self._getCellListForID(oid, readable=True)
if len(cell_list) == 0:
......@@ -592,8 +590,6 @@ class Application(object):
self.mq_cache[oid] = start_serial, data
finally:
self._cache_lock_release()
if end_serial == INVALID_SERIAL:
end_serial = None
return data, start_serial, end_serial
......@@ -625,8 +621,6 @@ class Application(object):
def loadBefore(self, oid, tid):
"""Load an object for a given oid before tid committed."""
# 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))
data, start, end = self._load(oid, tid=tid)
if end is None:
......@@ -657,8 +651,6 @@ class Application(object):
"""Store object."""
if transaction is not self.local_var.txn:
raise StorageTransactionError(self, transaction)
if serial is None:
serial = INVALID_SERIAL
logging.debug('storing oid %s serial %s',
dump(oid), dump(serial))
# Find which storage node to use
......@@ -884,7 +876,7 @@ class Application(object):
try:
conn.ask(self.local_var.queue,
protocol.askTIDs(first, last, INVALID_PARTITION))
protocol.askTIDs(first, last, protocol.INVALID_PARTITION))
finally:
conn.unlock()
......
......@@ -24,7 +24,6 @@ from neo.config import ConfigurationManager
from neo import protocol
from neo.protocol import \
RUNNING_STATE, TEMPORARILY_DOWN_STATE, DOWN_STATE, \
INVALID_OID, INVALID_TID, INVALID_PTID, \
CLIENT_NODE_TYPE, MASTER_NODE_TYPE, STORAGE_NODE_TYPE, \
UUID_NAMESPACES, ADMIN_NODE_TYPE, BOOTING
from neo.node import NodeManager, MasterNode, StorageNode, ClientNode, AdminNode
......@@ -77,9 +76,9 @@ class Application(object):
self.uuid = self.getNewUUID(MASTER_NODE_TYPE)
# The last OID.
self.loid = INVALID_OID
self.loid = None
# The last TID.
self.ltid = INVALID_TID
self.ltid = None
# The target node's uuid to request next.
self.target_uuid = None
......@@ -372,9 +371,9 @@ class Application(object):
self.changeClusterState(protocol.RECOVERING)
em = self.em
self.loid = INVALID_OID
self.ltid = INVALID_TID
self.pt.setID(INVALID_PTID)
self.loid = None
self.ltid = None
self.pt.setID(None)
self.target_uuid = None
# collect the last partition table available
......@@ -386,7 +385,7 @@ class Application(object):
self.changeClusterState(protocol.VERIFYING)
logging.info('startup allowed')
if self.pt.getID() == INVALID_PTID:
if self.pt.getID() is None:
self.buildFromScratch()
# FIXME: storage node with existing partition but not in the selected PT
......
......@@ -21,7 +21,7 @@ from neo import protocol
from neo.protocol import RUNNING_STATE, BROKEN_STATE, \
TEMPORARILY_DOWN_STATE, CLIENT_NODE_TYPE, ADMIN_NODE_TYPE
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.util import dump
......@@ -89,7 +89,7 @@ class RecoveryHandler(MasterHandler):
app.loid = loid
if 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
app.pt.setID(lptid)
app.target_uuid = conn.getUUID()
......
......@@ -28,7 +28,7 @@ class PartitionTable(neo.pt.PartitionTable):
self.id = id
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'
last_id = unpack('!Q', self.id)[0]
self.id = pack('!Q', last_id + 1)
......
......@@ -18,7 +18,6 @@
import logging
from neo.protocol import node_types, node_states
from neo.protocol import INVALID_PTID
from neo.event import EventManager
from neo.connection import ClientConnection
from neo.exception import OperationFailure
......@@ -144,7 +143,7 @@ class Application(object):
self.connector_handler = getConnectorHandler(handler)
self.server = (ip, port)
self.em = EventManager()
self.ptid = INVALID_PTID
self.ptid = None
def getConnection(self):
if self.conn is None:
......
This diff is collapsed.
......@@ -57,7 +57,7 @@ class PartitionTable(object):
"""This class manages a partition table."""
def __init__(self, num_partitions, num_replicas):
self.id = protocol.INVALID_PTID
self.id = None
self.np = num_partitions
self.nr = num_replicas
self.num_filled_rows = 0
......
......@@ -23,7 +23,7 @@ from collections import deque
from neo.config import ConfigurationManager
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
from neo.node import NodeManager, MasterNode, StorageNode
from neo.event import EventManager
......@@ -95,9 +95,7 @@ class Application(object):
dm.setName(self.name)
elif name != self.name:
raise RuntimeError('name does not match with the database')
self.ptid = dm.getPTID() # return ptid or INVALID_PTID
if self.ptid == INVALID_PTID:
dm.setPTID(self.ptid)
self.ptid = dm.getPTID()
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))
......
......@@ -226,16 +226,9 @@ class BaseClientAndStorageOperationHandler(BaseStorageHandler):
app.queueEvent(self.handleAskObject, conn, packet, oid,
serial, tid)
return
if serial == protocol.INVALID_SERIAL:
serial = None
if tid == protocol.INVALID_TID:
tid = None
o = app.dm.getObject(oid, serial, tid)
if o is not None:
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',
dump(oid), dump(serial), dump(next_serial))
p = protocol.answerObject(oid, serial, next_serial,
......
......@@ -19,7 +19,7 @@ import logging
from neo import protocol
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
from neo.util import dump
......
......@@ -19,8 +19,7 @@ import logging
from neo import protocol
from neo.storage.handlers import BaseMasterHandler
from neo.protocol import INVALID_SERIAL, INVALID_TID, INVALID_PARTITION, \
TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.protocol import TEMPORARILY_DOWN_STATE, DISCARDED_STATE, OUT_OF_DATE_STATE
from neo.util import dump
from neo.node import StorageNode
from neo.exception import PrimaryFailure, OperationFailure
......
......@@ -113,7 +113,7 @@ class ReplicationHandler(BaseStorageHandler):
present_serial_list = app.dm.getSerialListPresent(oid, serial_list)
serial_set = set(serial_list) - set(present_serial_list)
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.
app.replicator.serial_offset += 1000
......
......@@ -28,8 +28,8 @@ class StorageOperationHandler(BaseClientAndStorageOperationHandler):
def handleAskLastIDs(self, conn, packet):
app = self.app
oid = app.dm.getLastOID() or protocol.INVALID_OID
tid = app.dm.getLastTID() or protocol.INVALID_TID
oid = app.dm.getLastOID()
tid = app.dm.getLastTID()
p = protocol.answerLastIDs(oid, tid, app.ptid)
conn.answer(p, packet)
......
......@@ -18,7 +18,7 @@
import logging
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.util import dump
from neo.node import StorageNode
......@@ -29,8 +29,8 @@ class VerificationHandler(BaseMasterHandler):
def handleAskLastIDs(self, conn, packet):
app = self.app
oid = app.dm.getLastOID() or INVALID_OID
tid = app.dm.getLastTID() or INVALID_TID
oid = app.dm.getLastOID()
tid = app.dm.getLastTID()
p = protocol.answerLastIDs(oid, tid, app.ptid)
conn.answer(p, packet)
......
......@@ -25,7 +25,7 @@ from struct import pack, unpack
from neo.storage.database import DatabaseManager
from neo.exception import DatabaseFailure
from neo.protocol import DISCARDED_STATE, INVALID_PTID
from neo.protocol import DISCARDED_STATE
LOG_QUERIES = False
......@@ -243,10 +243,7 @@ class MySQLDatabaseManager(DatabaseManager):
self.commit()
def getPTID(self):
ptid = self.getConfiguration('ptid')
if ptid is None:
return INVALID_PTID
return ptid
return self.getConfiguration('ptid')
def setPTID(self, ptid):
self.begin()
......
......@@ -21,7 +21,7 @@ from random import choice
from neo.storage import handlers
from neo import protocol
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.util import dump
......
......@@ -27,7 +27,7 @@ from neo.storage.app import Application, StorageNode
from neo.storage.handlers import InitializationHandler
from neo.protocol import STORAGE_NODE_TYPE, MASTER_NODE_TYPE, CLIENT_NODE_TYPE
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, \
NOTIFY_PARTITION_CHANGES, STOP_OPERATION, ASK_LAST_IDS, ASK_PARTITION_TABLE, \
ANSWER_OBJECT_PRESENT, ASK_OBJECT_PRESENT, OID_NOT_FOUND_CODE, LOCK_INFORMATION, \
......
......@@ -19,7 +19,7 @@ import unittest, logging, os
from mock import Mock
from neo.tests.base import NeoTestBase
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
from neo.node import MasterNode, ClientNode, StorageNode
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