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

Store the PTID in memory as an integer.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2309 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 061d2e99
......@@ -23,14 +23,14 @@ class PartitionTable(neo.pt.PartitionTable):
"""This class manages a partition table for the primary master node"""
def setID(self, id):
self.id = id
assert isinstance(id, (int, long)) or id is None, id
self._id = id
def setNextID(self):
if self.id is None:
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)
return self.id
self._id += 1
return self._id
def getPartition(self, oid_or_tid):
return unpack('!Q', oid_or_tid)[0] % self.getPartitions()
......@@ -38,7 +38,7 @@ class PartitionTable(neo.pt.PartitionTable):
def make(self, node_list):
"""Make a new partition table from scratch."""
# start with the first PTID
self.id = pack('!Q', 1)
self._id = 1
# First, filter the list of nodes.
node_list = [n for n in node_list if n.isRunning() \
and n.getUUID() is not None]
......@@ -115,7 +115,7 @@ class PartitionTable(neo.pt.PartitionTable):
raise IndexError, offset
# store the partition table
self.clear()
self.id = ptid
self._id = ptid
new_nodes = []
for offset, row in row_list:
for uuid, state in row:
......
......@@ -202,12 +202,13 @@ def _encodeUUID(uuid):
def _decodePTID(ptid):
if ptid == INVALID_PTID:
return None
return ptid
return unpack('!Q', ptid)[0]
def _encodePTID(ptid):
if ptid is None:
return INVALID_PTID
return ptid
assert isinstance(ptid, (int, long)), ptid
return pack('!Q', ptid)
def _decodeTID(tid):
if tid == INVALID_TID:
......
......@@ -70,7 +70,7 @@ class PartitionTable(object):
"""This class manages a partition table."""
def __init__(self, num_partitions, num_replicas):
self.id = None
self._id = None
self.np = num_partitions
self.nr = num_replicas
self.num_filled_rows = 0
......@@ -81,7 +81,7 @@ class PartitionTable(object):
self.count_dict = {}
def getID(self):
return self.id
return self._id
def getPartitions(self):
return self.np
......@@ -91,7 +91,7 @@ class PartitionTable(object):
def clear(self):
"""Forget an existing partition table."""
self.id = None
self._id = None
self.num_filled_rows = 0
# Note: don't use [[]] * self.np construct, as it duplicates
# instance *references*, so the outer list contains really just one
......@@ -201,7 +201,7 @@ class PartitionTable(object):
content.
"""
self.clear()
self.id = ptid
self._id = ptid
for offset, row in row_list:
if offset >= self.getPartitions():
raise IndexError
......@@ -219,10 +219,10 @@ class PartitionTable(object):
if the partition table ID is not greater than the current one. If a node
is not known, it is created in the node manager and set as unavailable
"""
if ptid <= self.id:
if ptid <= self._id:
logging.warning('ignoring older partition changes')
return
self.id = ptid
self._id = ptid
for offset, uuid, state in cell_list:
node = nm.getByUUID(uuid)
assert node is not None, 'No node found for uuid %r' % (dump(uuid), )
......
......@@ -149,13 +149,16 @@ class DatabaseManager(object):
"""
Load a Partition Table ID from a database.
"""
return util.bin(self.getConfiguration('ptid'))
return long(self.getConfiguration('ptid'))
def setPTID(self, ptid):
"""
Store a Partition Table ID into a database.
"""
self.setConfiguration('ptid', util.dump(ptid))
if ptid is not None:
assert isinstance(ptid, (int, long)), ptid
ptid = str(ptid)
self.setConfiguration('ptid', ptid)
def getLastOID(self):
"""
......
......@@ -132,10 +132,10 @@ class NeoTestBase(unittest.TestCase):
return tid
def getPTID(self, i=None):
""" Return a 8-bytes PTID """
""" Return an integer PTID """
if i is None:
return os.urandom(8)
return pack('!Q', i)
return os.unpack('!Q', os.urandom(8))[0]
return i
def getOID(self, i=None):
""" Return a 8-bytes OID """
......
......@@ -30,7 +30,7 @@ class MasterClientHandlerTests(NeoTestBase):
config = self.getMasterConfiguration(master_number=1, replicas=1)
self.app = Application(config)
self.app.pt.clear()
self.app.pt.setID(pack('!Q', 1))
self.app.pt.setID(1)
self.app.em = Mock()
self.app.loid = '\0' * 8
self.app.tm.setLastTID('\0' * 8)
......
......@@ -32,7 +32,6 @@ class MasterStorageHandlerTests(NeoTestBase):
config = self.getMasterConfiguration(master_number=1, replicas=1)
self.app = Application(config)
self.app.pt.clear()
self.app.pt.setID(pack('!Q', 1))
self.app.em = Mock()
self.service = StorageServiceHandler(self.app)
self.client_handler = ClientServiceHandler(self.app)
......
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