[Zodb-checkins] SVN: ZODB/branches/3.4/ Convert internal uses of subtxns to use savepoints instead.

Tim Peters tim.one at comcast.net
Tue Jul 12 17:12:34 EDT 2005


Log message for revision 33285:
  Convert internal uses of subtxns to use savepoints instead.
  
  I suspect BTrees/convert.py should be removed instead.
  

Changed:
  U   ZODB/branches/3.4/NEWS.txt
  U   ZODB/branches/3.4/src/BTrees/convert.py
  U   ZODB/branches/3.4/src/ZODB/ExportImport.py

-=-
Modified: ZODB/branches/3.4/NEWS.txt
===================================================================
--- ZODB/branches/3.4/NEWS.txt	2005-07-12 20:52:23 UTC (rev 33284)
+++ ZODB/branches/3.4/NEWS.txt	2005-07-12 21:12:34 UTC (rev 33285)
@@ -28,6 +28,41 @@
   marked a savepoint as invalid after its first use.  The implementation has
   been repaired, to match the docs.
 
+Subtransactions
+---------------
+
+- (3.4.1a5) Internal uses of subtransactions (transaction ``commit()`` or
+  ``abort()`` passing a true argument) were rewritten to use savepoints
+  instead.  Application code is strongly encouraged to do this too:
+  subtransactions are weaker, will be deprecated soon, and do not mix well
+  with savepoints (when you do a subtransaction commit, all current
+  savepoints are made unusable).  In general, a subtransaction commit
+  done just to free memory can be changed from::
+
+      transaction.commit(1)
+
+  to::
+
+      transaction.savepoint()
+
+  That is, make a savepoint, and forget it.  In rarer cases, a
+  subtransaction commit is followed later by a subtransaction abort.  In
+  that case, change the initial::
+
+      transaction.commit(1)
+
+  to::
+
+      sp = transaction.savepoint()
+
+  and in place of the subtransaction abort::
+
+      transaction.abort(1)
+
+  roll back the savepoint instead::
+
+      sp.rollback()
+
 FileStorage
 -----------
 

Modified: ZODB/branches/3.4/src/BTrees/convert.py
===================================================================
--- ZODB/branches/3.4/src/BTrees/convert.py	2005-07-12 20:52:23 UTC (rev 33284)
+++ ZODB/branches/3.4/src/BTrees/convert.py	2005-07-12 21:12:34 UTC (rev 33285)
@@ -12,6 +12,11 @@
 #
 ##############################################################################
 
+# TODO:  does this script still serve a purpose?  Writing this in 2005,
+# "old btree" doesn't mean much to me.
+
+import transaction
+
 def convert(old, new, threshold=200, f=None):
     "Utility for converting old btree to new"
     n=0
@@ -20,9 +25,9 @@
         new[k]=v
         n=n+1
         if n > threshold:
-            transaction.commit(1)
+            transaction.savepoint()
             old._p_jar.cacheMinimize()
             n=0
 
-    transaction.commit(1)
+    transaction.savepoint()
     old._p_jar.cacheMinimize()

Modified: ZODB/branches/3.4/src/ZODB/ExportImport.py
===================================================================
--- ZODB/branches/3.4/src/ZODB/ExportImport.py	2005-07-12 20:52:23 UTC (rev 33284)
+++ ZODB/branches/3.4/src/ZODB/ExportImport.py	2005-07-12 21:12:34 UTC (rev 33285)
@@ -56,7 +56,7 @@
         # This is tricky, because we need to work in a transaction!
 
         if isinstance(f, str):
-            f = open(f,'rb')
+            f = open(f, 'rb')
 
         magic = f.read(4)
         if magic != 'ZEXP':
@@ -72,7 +72,7 @@
         return_oid_list = []
         self._import = f, return_oid_list
         self._register()
-        t.commit(1)
+        t.savepoint()
         # Return the root imported object.
         if return_oid_list:
             return self.get(return_oid_list[0])



More information about the Zodb-checkins mailing list