[Zodb-checkins] SVN: ZODB/branches/3.8/src/ZEO/ Complain if server invalidations are applied out of order.

Jim Fulton jim at zope.com
Mon Jul 14 10:59:07 EDT 2008


Log message for revision 88352:
  Complain if server invalidations are applied out of order.
  

Changed:
  U   ZODB/branches/3.8/src/ZEO/cache.py
  U   ZODB/branches/3.8/src/ZEO/tests/test_cache.py

-=-
Modified: ZODB/branches/3.8/src/ZEO/cache.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/cache.py	2008-07-14 14:39:30 UTC (rev 88351)
+++ ZODB/branches/3.8/src/ZEO/cache.py	2008-07-14 14:59:06 UTC (rev 88352)
@@ -607,15 +607,30 @@
     # data for `oid`, stop believing we have current data, and mark the
     # data we had as being valid only up to `tid`.  In all other cases, do
     # nothing.
-    # @param oid object id
-    # @param version name of version to invalidate.
-    # @param tid the id of the transaction that wrote a new revision of oid,
+    #
+    # Paramters:
+    #
+    # - oid object id
+    # - version name of version to invalidate.
+    # - tid the id of the transaction that wrote a new revision of oid,
     #        or None to forget all cached info about oid (version, current
     #        revision, and non-current revisions)
+    # - server_invalidation, a flag indicating whether the
+    #       invalidation has come from the server. It's possible, due
+    #       to threading issues, that when applying a local
+    #       invalidation after a store, that later invalidations from
+    #       the server may already have arrived.
+    
     @locked
-    def invalidate(self, oid, version, tid):
-        if tid > self.tid and tid is not None:
-            self.setLastTid(tid)
+    def invalidate(self, oid, version, tid, server_invalidation=True):
+        if tid is not None:
+            if tid > self.tid:
+                self.setLastTid(tid)
+            elif tid < self.tid:
+                if server_invalidation:
+                    raise ValueError("invalidation tid (%s) must not be less"
+                                     " than previous one (%s)" %
+                                     (u64(tid), u64(self.tid)))
 
         ofs = self.current.get(oid)
         if ofs is None:

Modified: ZODB/branches/3.8/src/ZEO/tests/test_cache.py
===================================================================
--- ZODB/branches/3.8/src/ZEO/tests/test_cache.py	2008-07-14 14:39:30 UTC (rev 88351)
+++ ZODB/branches/3.8/src/ZEO/tests/test_cache.py	2008-07-14 14:59:06 UTC (rev 88352)
@@ -44,7 +44,6 @@
         self.assertEqual(self.cache.getLastTid(), None)
         self.cache.setLastTid(n2)
         self.assertEqual(self.cache.getLastTid(), n2)
-        self.cache.invalidate(n1, "", n1)
         self.assertEqual(self.cache.getLastTid(), n2)
         self.cache.invalidate(n1, "", n3)
         self.assertEqual(self.cache.getLastTid(), n3)
@@ -64,8 +63,8 @@
     def testInvalidate(self):
         data1 = "data for n1"
         self.cache.store(n1, "", n3, None, data1)
-        self.cache.invalidate(n1, "", n4)
         self.cache.invalidate(n2, "", n2)
+        self.cache.invalidate(n1, "", n4)
         self.assertEqual(self.cache.load(n1, ""), None)
         self.assertEqual(self.cache.loadBefore(n1, n4),
                          (data1, n3, n4))



More information about the Zodb-checkins mailing list