[Zodb-checkins] CVS: ZODB3/bsddb3Storage/bsddb3Storage - BerkeleyBase.py:1.22

Barry Warsaw barry@wooz.org
Mon, 11 Nov 2002 15:56:31 -0500


Update of /cvs-repository/ZODB3/bsddb3Storage/bsddb3Storage
In directory cvs.zope.org:/tmp/cvs-serv20990

Modified Files:
	BerkeleyBase.py 
Log Message:
Refactoring from Full and Minimal.  Specifically,

BerkeleyConfig: Clarify in the docstring the semantics of the various
autopack variables, w.r.t. the differences between Full and Minimal
autopacking (the latter always does a gc pack because there's nothing
else it /could/ do :).

__init__(): We can create the packlock here, allowing us to get rid of
the __init__'s in the derived classes.

_withtxn(): Turns out to be useful for both storages.


=== ZODB3/bsddb3Storage/bsddb3Storage/BerkeleyBase.py 1.21 => 1.22 ===
--- ZODB3/bsddb3Storage/bsddb3Storage/BerkeleyBase.py:1.21	Fri Nov  8 18:18:12 2002
+++ ZODB3/bsddb3Storage/bsddb3Storage/BerkeleyBase.py	Mon Nov 11 15:56:30 2002
@@ -29,6 +29,7 @@
 from ZODB.lock_file import lock_file
 from ZODB.BaseStorage import BaseStorage
 from ZODB.referencesf import referencesf
+import ThreadLock
 
 GBYTES = 1024 * 1024 * 1000
 
@@ -89,12 +90,13 @@
 
     - packtime is the time in seconds marking the moment in the past at which
       to autopack to.  E.g. if packtime is 14400, autopack will pack to 4
-      hours in the past.
+      hours in the past.  For Minimal storage, this value is ignored.
 
     - classicpack is an integer indicating how often an autopack phase should
       do a full classic pack.  E.g. if classicpack is 24 and frequence is
       3600, a classic pack will be performed once per day.  Set to zero to
-      never automatically do classic packs.
+      never automatically do classic packs.  For Minimal storage, this value
+      is ignored -- all packs are classic packs.
     """
     interval = 100
     kbyte = 0
@@ -162,6 +164,9 @@
 
         BaseStorage.__init__(self, name)
 
+        # Instantiate a pack lock
+        self._packlock = ThreadLock.allocate_lock()
+        self._autopacker = None
         # Initialize a few other things
         self._prefix = prefix
         # Give the subclasses a chance to interpose into the database setup
@@ -306,6 +311,20 @@
             return meth(*args)
         finally:
             self._lock_release()
+
+    def _withtxn(self, meth, *args, **kws):
+        txn = self._env.txn_begin()
+        try:
+            ret = meth(txn, *args, **kws)
+        except:
+            #import traceback ; traceback.print_exc()
+            txn.abort()
+            self._docheckpoint()
+            raise
+        else:
+            txn.commit()
+            self._docheckpoint()
+            return ret