[Neo-report] r2309 gregory - in /trunk/neo: ./ master/ storage/database/ tests/ tests/master/

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Sep 23 17:00:45 CEST 2010


Author: gregory
Date: Thu Sep 23 17:00:45 2010
New Revision: 2309

Log:
Store the PTID in memory as an integer.

Modified:
    trunk/neo/master/pt.py
    trunk/neo/protocol.py
    trunk/neo/pt.py
    trunk/neo/storage/database/manager.py
    trunk/neo/tests/__init__.py
    trunk/neo/tests/master/testClientHandler.py
    trunk/neo/tests/master/testStorageHandler.py

Modified: trunk/neo/master/pt.py
==============================================================================
--- trunk/neo/master/pt.py [iso-8859-1] (original)
+++ trunk/neo/master/pt.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -23,14 +23,14 @@ class PartitionTable(neo.pt.PartitionTab
     """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.PartitionTab
     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.PartitionTab
                 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:

Modified: trunk/neo/protocol.py
==============================================================================
--- trunk/neo/protocol.py [iso-8859-1] (original)
+++ trunk/neo/protocol.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -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:

Modified: trunk/neo/pt.py
==============================================================================
--- trunk/neo/pt.py [iso-8859-1] (original)
+++ trunk/neo/pt.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -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), )

Modified: trunk/neo/storage/database/manager.py
==============================================================================
--- trunk/neo/storage/database/manager.py [iso-8859-1] (original)
+++ trunk/neo/storage/database/manager.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -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):
         """

Modified: trunk/neo/tests/__init__.py
==============================================================================
--- trunk/neo/tests/__init__.py [iso-8859-1] (original)
+++ trunk/neo/tests/__init__.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -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 """

Modified: trunk/neo/tests/master/testClientHandler.py
==============================================================================
--- trunk/neo/tests/master/testClientHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/master/testClientHandler.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -30,7 +30,7 @@ class MasterClientHandlerTests(NeoTestBa
         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)

Modified: trunk/neo/tests/master/testStorageHandler.py
==============================================================================
--- trunk/neo/tests/master/testStorageHandler.py [iso-8859-1] (original)
+++ trunk/neo/tests/master/testStorageHandler.py [iso-8859-1] Thu Sep 23 17:00:45 2010
@@ -32,7 +32,6 @@ class MasterStorageHandlerTests(NeoTestB
         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)





More information about the Neo-report mailing list