[Checkins] SVN: ZODB/trunk/src/ Clarified the return Value for lastTransaction in the case when

Jim Fulton jim at zope.com
Mon Sep 13 02:36:14 EDT 2010


Log message for revision 116337:
  Clarified the return Value for lastTransaction in the case when
  there aren't any transactions.  Now a string of 8 nulls (aka "z64")
  is specified.
  

Changed:
  U   ZODB/trunk/src/CHANGES.txt
  U   ZODB/trunk/src/ZEO/ClientStorage.py
  U   ZODB/trunk/src/ZEO/ServerStub.py
  U   ZODB/trunk/src/ZEO/StorageServer.py
  U   ZODB/trunk/src/ZEO/cache.py
  U   ZODB/trunk/src/ZEO/tests/testZEO.py
  U   ZODB/trunk/src/ZEO/tests/test_cache.py
  U   ZODB/trunk/src/ZODB/MappingStorage.py
  U   ZODB/trunk/src/ZODB/interfaces.py
  U   ZODB/trunk/src/ZODB/tests/BasicStorage.py
  U   ZODB/trunk/src/ZODB/tests/test_storage.py

-=-
Modified: ZODB/trunk/src/CHANGES.txt
===================================================================
--- ZODB/trunk/src/CHANGES.txt	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/CHANGES.txt	2010-09-13 06:36:14 UTC (rev 116337)
@@ -21,6 +21,10 @@
 - Objects added in transactions that were later aborted could have
   _p_changed still set (https://bugs.launchpad.net/zodb/+bug/615758).
 
+- Clarified the return Value for lastTransaction in the case when
+  there aren't any transactions.  Now a string of 8 nulls (aka "z64")
+  is specified.
+
 3.10.0b6 (2010-09-08)
 =====================
 

Modified: ZODB/trunk/src/ZEO/ClientStorage.py
===================================================================
--- ZODB/trunk/src/ZEO/ClientStorage.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZEO/ClientStorage.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -1343,7 +1343,7 @@
         if not self._cache:
             logger.info("%s No verification necessary -- empty cache",
                         self.__name__)
-            if ltid and ltid != utils.z64:
+            if ltid != utils.z64:
                 self._cache.setLastTid(ltid)
             self.finish_verification()
             return "empty cache"
@@ -1375,14 +1375,14 @@
                             self.__name__, len(pair[1]))
                 self.finish_verification(pair)
                 return "quick verification"
-        elif ltid and ltid != utils.z64:
+        elif ltid != utils.z64:
 
-            # XXX Hm, to have gotten here, the cache is non-empty, but
+            # Hm, to have gotten here, the cache is non-empty, but
             # it has no last tid. This doesn't seem like good situation.
-            # We shouldn't treat it so lightly.
-
+            # We'll have to verify the cache, if we're willing.
             self._cache.setLastTid(ltid)
 
+
         zope.event.notify(ZEO.interfaces.StaleCache(self))
 
         # From this point on, we do not have complete information about

Modified: ZODB/trunk/src/ZEO/ServerStub.py
===================================================================
--- ZODB/trunk/src/ZEO/ServerStub.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZEO/ServerStub.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -15,6 +15,7 @@
 
 import os
 import time
+from ZODB.utils import z64
 
 ##
 # ZEO storage server.
@@ -86,7 +87,7 @@
 
     def lastTransaction(self):
         # Not in protocol version 2.0.0; see __init__()
-        return self.rpc.call('lastTransaction')
+        return self.rpc.call('lastTransaction') or z64
 
     ##
     # Return invalidations for all transactions after tid.

Modified: ZODB/trunk/src/ZEO/StorageServer.py
===================================================================
--- ZODB/trunk/src/ZEO/StorageServer.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZEO/StorageServer.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -926,11 +926,9 @@
             # be good. :) Doing this allows clients that were up to
             # date when a server was restarted to pick up transactions
             # it subsequently missed.
-            self.invq[name] = [(storage.lastTransaction(), None)]
+            self.invq[name] = [(storage.lastTransaction() or z64, None)]
         else:
-            self.invq[name] = list(
-                lastInvalidations(self.invq_bound)
-                )
+            self.invq[name] = list(lastInvalidations(self.invq_bound))
             self.invq[name].reverse()
 
 

Modified: ZODB/trunk/src/ZEO/cache.py
===================================================================
--- ZODB/trunk/src/ZEO/cache.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZEO/cache.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -473,13 +473,9 @@
     ##
     # Return the last transaction seen by the cache.
     # @return a transaction id
-    # @defreturn string, or None if no transaction is yet known
+    # @defreturn string, or 8 nulls if no transaction is yet known
     def getLastTid(self):
-        tid = self.tid
-        if tid == z64:
-            return None
-        else:
-            return tid
+        return self.tid
 
     ##
     # Return the current data record for oid.

Modified: ZODB/trunk/src/ZEO/tests/testZEO.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/testZEO.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZEO/tests/testZEO.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -128,7 +128,7 @@
         addr = self._storage._addr
         storage2 = ClientStorage(addr)
         self.assert_(storage2.is_connected())
-        self.assertEquals(None, storage2.lastTransaction())
+        self.assertEquals(ZODB.utils.z64, storage2.lastTransaction())
         storage2.close()
 
         self._dostore()

Modified: ZODB/trunk/src/ZEO/tests/test_cache.py
===================================================================
--- ZODB/trunk/src/ZEO/tests/test_cache.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZEO/tests/test_cache.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -27,7 +27,7 @@
 import zope.testing.setupstack
 
 import ZEO.cache
-from ZODB.utils import p64, u64
+from ZODB.utils import p64, u64, z64
 
 n1 = p64(1)
 n2 = p64(2)
@@ -79,7 +79,7 @@
         ZODB.tests.util.TestCase.tearDown(self)
 
     def testLastTid(self):
-        self.assertEqual(self.cache.getLastTid(), None)
+        self.assertEqual(self.cache.getLastTid(), z64)
         self.cache.setLastTid(n2)
         self.assertEqual(self.cache.getLastTid(), n2)
         self.assertEqual(self.cache.getLastTid(), n2)

Modified: ZODB/trunk/src/ZODB/MappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/MappingStorage.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZODB/MappingStorage.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -39,7 +39,7 @@
         self.__name__ = name
         self._data = {}                               # {oid->{tid->pickle}}
         self._transactions = BTrees.OOBTree.OOBTree() # {tid->TransactionRecord}
-        self._ltid = None
+        self._ltid = ZODB.utils.z64
         self._last_pack = None
         _lock = threading.RLock()
         self._lock_acquire = _lock.acquire
@@ -129,8 +129,7 @@
     # ZODB.interfaces.IStorage
     @ZODB.utils.locked(opened)
     def lastTransaction(self):
-        if self._ltid is not None:
-            return self._ltid
+        return self._ltid
 
     # ZODB.interfaces.IStorage
     @ZODB.utils.locked(opened)

Modified: ZODB/trunk/src/ZODB/interfaces.py
===================================================================
--- ZODB/trunk/src/ZODB/interfaces.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZODB/interfaces.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -532,7 +532,10 @@
         # transiently.  It would be better to just have read-only errors.
 
     def lastTransaction():
-        """Return the id of the last committed transaction
+        """Return the id of the last committed transaction.
+
+        If no transactions have been committed, return a string of 8
+        null (0) characters.
         """
 
     def __len__():

Modified: ZODB/trunk/src/ZODB/tests/BasicStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/BasicStorage.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZODB/tests/BasicStorage.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -34,6 +34,8 @@
 
 class BasicStorage:
     def checkBasics(self):
+        self.assertEqual(self._storage.lastTransaction(), '\0'*8)
+
         t = transaction.Transaction()
         self._storage.tpc_begin(t)
         self.assertRaises(POSException.StorageTransactionError,

Modified: ZODB/trunk/src/ZODB/tests/test_storage.py
===================================================================
--- ZODB/trunk/src/ZODB/tests/test_storage.py	2010-09-12 15:49:36 UTC (rev 116336)
+++ ZODB/trunk/src/ZODB/tests/test_storage.py	2010-09-13 06:36:14 UTC (rev 116337)
@@ -60,6 +60,8 @@
         # _cur maps oid to current tid
         self._cur = {}
 
+        self._ltid = z64
+
     def isCurrent(self, oid, serial):
         return serial == self._cur[oid]
 



More information about the checkins mailing list