Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
ZODB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Nicolas Wavrant
ZODB
Commits
c04b9daf
Commit
c04b9daf
authored
Feb 03, 2006
by
Shane Hathaway
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backported the multiple undo fix to ZODB 3.6. (I wonder if this should
be backported further.)
parent
8f5e4a1b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
1 deletion
+52
-1
src/ZODB/DB.py
src/ZODB/DB.py
+16
-1
src/ZODB/tests/testZODB.py
src/ZODB/tests/testZODB.py
+36
-0
No files found.
src/ZODB/DB.py
View file @
c04b9daf
...
@@ -679,6 +679,9 @@ class DB(object):
...
@@ -679,6 +679,9 @@ class DB(object):
def
versionEmpty
(
self
,
version
):
def
versionEmpty
(
self
,
version
):
return
self
.
_storage
.
versionEmpty
(
version
)
return
self
.
_storage
.
versionEmpty
(
version
)
resource_counter_lock
=
threading
.
Lock
()
resource_counter
=
0
class
ResourceManager
(
object
):
class
ResourceManager
(
object
):
"""Transaction participation for a version or undo resource."""
"""Transaction participation for a version or undo resource."""
...
@@ -689,8 +692,20 @@ class ResourceManager(object):
...
@@ -689,8 +692,20 @@ class ResourceManager(object):
self
.
tpc_finish
=
self
.
_db
.
_storage
.
tpc_finish
self
.
tpc_finish
=
self
.
_db
.
_storage
.
tpc_finish
self
.
tpc_abort
=
self
.
_db
.
_storage
.
tpc_abort
self
.
tpc_abort
=
self
.
_db
.
_storage
.
tpc_abort
# Get a number from a simple thread-safe counter, then
# increment it, for the purpose of sorting ResourceManagers by
# creation order. This ensures that multiple ResourceManagers
# within a transaction commit in a predictable sequence.
resource_counter_lock
.
acquire
()
try
:
global
resource_counter
self
.
_count
=
resource_counter
resource_counter
+=
1
finally
:
resource_counter_lock
.
release
()
def
sortKey
(
self
):
def
sortKey
(
self
):
return
"%s:%
s"
%
(
self
.
_db
.
_storage
.
sortKey
(),
id
(
self
)
)
return
"%s:%
016x"
%
(
self
.
_db
.
_storage
.
sortKey
(),
self
.
_count
)
def
tpc_begin
(
self
,
txn
,
sub
=
False
):
def
tpc_begin
(
self
,
txn
,
sub
=
False
):
if
sub
:
if
sub
:
...
...
src/ZODB/tests/testZODB.py
View file @
c04b9daf
...
@@ -728,6 +728,42 @@ class ZODBTests(unittest.TestCase):
...
@@ -728,6 +728,42 @@ class ZODBTests(unittest.TestCase):
cn
.
close
()
cn
.
close
()
cn2
.
close
()
cn2
.
close
()
def
checkMultipleUndoInOneTransaction
(
self
):
# Verify that it's possible to perform multiple undo
# operations within a transaction. If ZODB performs the undo
# operations in a nondeterministic order, this test will often
# fail.
conn
=
self
.
_db
.
open
()
try
:
root
=
conn
.
root
()
# Add transactions that set root["state"] to (0..5)
for
state_num
in
range
(
6
):
transaction
.
begin
()
root
[
'state'
]
=
state_num
transaction
.
get
().
note
(
'root["state"] = %d'
%
state_num
)
transaction
.
commit
()
# Undo all but the first. Note that no work is actually
# performed yet.
transaction
.
begin
()
log
=
self
.
_db
.
undoLog
()
for
i
in
range
(
5
):
self
.
_db
.
undo
(
log
[
i
][
'id'
])
transaction
.
get
().
note
(
'undo states 1 through 5'
)
# Now attempt all those undo operations.
transaction
.
commit
()
# Sanity check: we should be back to the first state.
self
.
assertEqual
(
root
[
'state'
],
0
)
finally
:
transaction
.
abort
()
conn
.
close
()
class
PoisonedError
(
Exception
):
class
PoisonedError
(
Exception
):
pass
pass
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment