[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/locking/ deal with a horrid problem with the lock storage:

Fred L. Drake, Jr. fdrake at gmail.com
Fri Jul 22 18:43:38 EDT 2005


Log message for revision 37384:
  deal with a horrid problem with the lock storage:
  
  - create a persistent subclass of the lock storage that actually makes
    sense to use
  
  - disallow creation of the non-persistent lock storage class; its
    insane (existing pickles can be loaded, which is necessary if there
    are actually any instances)
  
  NOTICE:  If you have any instances of the LockStorage class, you
           *must* replace them with something that's persistent.  The
           easier way to do this to add a PersistentLockStorage and make
           it the active ILockStorage utility to replace the old one.
  

Changed:
  U   Zope3/trunk/src/zope/app/locking/storage.py
  U   Zope3/trunk/src/zope/app/locking/tests.py

-=-
Modified: Zope3/trunk/src/zope/app/locking/storage.py
===================================================================
--- Zope3/trunk/src/zope/app/locking/storage.py	2005-07-22 18:55:16 UTC (rev 37383)
+++ Zope3/trunk/src/zope/app/locking/storage.py	2005-07-22 22:43:38 UTC (rev 37384)
@@ -17,12 +17,18 @@
 $Id: $
 """
 
+import time
+
+import persistent
+
+from BTrees.OOBTree import OOBTree
+from BTrees.IOBTree import IOBTree
+
+import zope.interface
+
 from zope.app.keyreference.interfaces import IKeyReference
 from zope.app.locking.interfaces import ILockTracker
 from zope.app.locking.interfaces import LockingError
-from BTrees.OOBTree import OOBTree
-from BTrees.IOBTree import IOBTree
-import zope.interface, time
 
 
 timefunc = time.time
@@ -37,10 +43,24 @@
 
 
 class LockStorage(object):
-    """
+    # WARNING: This is not persistent.  Use PersistentLockStorage instead.
+    # This class must remain so that existing instances can be unpickled
+    # from the database.  New instances cannot be created without subclassing.
+    #
+    # The persistent.Persistent base class cannot be added to this
+    # without causing the containers to fail to unpickle properly
+    # since the pickle for a LockStorage is embedded in the pickle of
+    # the containing object.  For this reason, applications must
+    # replace existing LockStorage instances with some new class.  The
+    # LockStorage instances don't need to be removed, but an alternate
+    # class needs to be used instead.
+
+    """Peristent storage for locks.
+
     This class implements both the ILockTracker utility as well as the
     internal ILockStorage utility which is used by the ILockable adapter
     implementation. It acts as the persistent storage for locks.
+
     """
 
     zope.interface.implements(ILockStorage, ILockTracker)
@@ -48,6 +68,11 @@
     def __init__(self):
         self.timeouts = IOBTree()
         self.locks = OOBTree()
+        if self.__class__ is LockStorage:
+            raise TypeError(
+                "%s.LockStorage is insane; use a persistent subclass instead"
+                " (%s.PersistentLockStorage should do nicely)"
+                % (__name__, __name__))
 
     # ILockTracker implementation
     
@@ -113,5 +138,10 @@
                     del self.locks[keyref]
             del self.timeouts[key]
 
-        
 
+class PersistentLockStorage(persistent.Persistent, LockStorage):
+    """LockStorage that isn't fickle."""
+
+    # This is the class that should generally be used with Zope 3.
+    # Alternate subclasses can be used, but LockStorage can't be used
+    # directly.  Subclasses are responsible for providing persistence.

Modified: Zope3/trunk/src/zope/app/locking/tests.py
===================================================================
--- Zope3/trunk/src/zope/app/locking/tests.py	2005-07-22 18:55:16 UTC (rev 37383)
+++ Zope3/trunk/src/zope/app/locking/tests.py	2005-07-22 22:43:38 UTC (rev 37384)
@@ -68,14 +68,14 @@
     from zope.app.locking.interfaces import ILockable, ILockTracker
     from zope.app.locking.adapter import LockingAdapterFactory
     from zope.app.locking.adapter import LockingPathAdapter
-    from zope.app.locking.storage import ILockStorage, LockStorage
+    from zope.app.locking.storage import ILockStorage, PersistentLockStorage
     from zope.app.traversing.interfaces import IPathAdapter
 
     ztapi.provideAdapter(Interface, IKeyReference, FakeKeyReference)
     ztapi.provideAdapter(Interface, ILockable, LockingAdapterFactory)
     ztapi.provideAdapter(None, IPathAdapter, LockingPathAdapter,
                          "locking")
-    storage = LockStorage()
+    storage = PersistentLockStorage()
     ztapi.provideUtility(ILockStorage, storage)
     ztapi.provideUtility(ILockTracker, storage)
     test._storage = storage # keep-alive



More information about the Zope3-Checkins mailing list