Commit fe9fcbe3 authored by Tim Peters's avatar Tim Peters

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.
parent e8b2c3c9
...@@ -27,6 +27,41 @@ Savepoints ...@@ -27,6 +27,41 @@ Savepoints
marked a savepoint as invalid after its first use. The implementation has marked a savepoint as invalid after its first use. The implementation has
been repaired, to match the docs. 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 Multi-database
-------------- --------------
...@@ -109,6 +144,41 @@ Savepoints ...@@ -109,6 +144,41 @@ Savepoints
marked a savepoint as invalid after its first use. The implementation has marked a savepoint as invalid after its first use. The implementation has
been repaired, to match the docs. 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 FileStorage
----------- -----------
......
...@@ -12,6 +12,11 @@ ...@@ -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): def convert(old, new, threshold=200, f=None):
"Utility for converting old btree to new" "Utility for converting old btree to new"
n=0 n=0
...@@ -20,9 +25,9 @@ def convert(old, new, threshold=200, f=None): ...@@ -20,9 +25,9 @@ def convert(old, new, threshold=200, f=None):
new[k]=v new[k]=v
n=n+1 n=n+1
if n > threshold: if n > threshold:
transaction.commit(1) transaction.savepoint()
old._p_jar.cacheMinimize() old._p_jar.cacheMinimize()
n=0 n=0
transaction.commit(1) transaction.savepoint()
old._p_jar.cacheMinimize() old._p_jar.cacheMinimize()
...@@ -56,7 +56,7 @@ class ExportImport: ...@@ -56,7 +56,7 @@ class ExportImport:
# This is tricky, because we need to work in a transaction! # This is tricky, because we need to work in a transaction!
if isinstance(f, str): if isinstance(f, str):
f = open(f,'rb') f = open(f, 'rb')
magic = f.read(4) magic = f.read(4)
if magic != 'ZEXP': if magic != 'ZEXP':
...@@ -72,7 +72,7 @@ class ExportImport: ...@@ -72,7 +72,7 @@ class ExportImport:
return_oid_list = [] return_oid_list = []
self._import = f, return_oid_list self._import = f, return_oid_list
self._register() self._register()
t.commit(1) t.savepoint()
# Return the root imported object. # Return the root imported object.
if return_oid_list: if return_oid_list:
return self.get(return_oid_list[0]) return self.get(return_oid_list[0])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment