[Zodb-checkins] SVN: ZODB/trunk/ Merge rev 33285 from 3.4 branch.

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


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

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

-=-
Modified: ZODB/trunk/NEWS.txt
===================================================================
--- ZODB/trunk/NEWS.txt	2005-07-12 21:12:34 UTC (rev 33285)
+++ ZODB/trunk/NEWS.txt	2005-07-12 21:14:49 UTC (rev 33286)
@@ -27,6 +27,41 @@
   marked a savepoint as invalid after its first use.  The implementation has
   been repaired, to match the docs.
 
+Subtransactions
+---------------
+
+- (3.5a4) 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()
+
 Multi-database
 --------------
 
@@ -109,6 +144,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/trunk/src/BTrees/convert.py
===================================================================
--- ZODB/trunk/src/BTrees/convert.py	2005-07-12 21:12:34 UTC (rev 33285)
+++ ZODB/trunk/src/BTrees/convert.py	2005-07-12 21:14:49 UTC (rev 33286)
@@ -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/trunk/src/ZODB/ExportImport.py
===================================================================
--- ZODB/trunk/src/ZODB/ExportImport.py	2005-07-12 21:12:34 UTC (rev 33285)
+++ ZODB/trunk/src/ZODB/ExportImport.py	2005-07-12 21:14:49 UTC (rev 33286)
@@ -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