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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
ZODB
Commits
b74eef76
Commit
b74eef76
authored
Aug 20, 2016
by
Julien Muchembled
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Call _p_resolveConflict() even if a conflicting change doesn't change the state
This reverts to the behaviour of 3.10.3 and older.
parent
b53c7019
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
29 additions
and
16 deletions
+29
-16
src/ZODB/ConflictResolution.py
src/ZODB/ConflictResolution.py
+0
-7
src/ZODB/tests/testconflictresolution.py
src/ZODB/tests/testconflictresolution.py
+29
-9
No files found.
src/ZODB/ConflictResolution.py
View file @
b74eef76
...
@@ -271,13 +271,6 @@ def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
...
@@ -271,13 +271,6 @@ def tryToResolveConflict(self, oid, committedSerial, oldSerial, newpickle,
if
not
committedData
:
if
not
committedData
:
committedData
=
self
.
loadSerial
(
oid
,
committedSerial
)
committedData
=
self
.
loadSerial
(
oid
,
committedSerial
)
if
newpickle
==
oldData
:
# old -> new diff is empty, so merge is trivial
return
committedData
if
committedData
==
oldData
:
# old -> committed diff is empty, so merge is trivial
return
newpickle
newstate
=
unpickler
.
load
()
newstate
=
unpickler
.
load
()
old
=
state
(
self
,
oid
,
oldSerial
,
prfactory
,
oldData
)
old
=
state
(
self
,
oid
,
oldSerial
,
prfactory
,
oldData
)
committed
=
state
(
self
,
oid
,
committedSerial
,
prfactory
,
committedData
)
committed
=
state
(
self
,
oid
,
committedSerial
,
prfactory
,
committedData
)
...
...
src/ZODB/tests/testconflictresolution.py
View file @
b74eef76
...
@@ -40,6 +40,15 @@ def tearDown(test):
...
@@ -40,6 +40,15 @@ def tearDown(test):
class
ResolveableWhenStateDoesNotChange
(
persistent
.
Persistent
):
class
ResolveableWhenStateDoesNotChange
(
persistent
.
Persistent
):
def
_p_resolveConflict
(
self
,
old
,
committed
,
new
):
def
_p_resolveConflict
(
self
,
old
,
committed
,
new
):
if
new
==
old
:
# old -> new diff is empty, so merge is trivial
committed
[
'resolved'
]
=
'committed'
return
committed
elif
committed
==
old
:
# old -> committed diff is empty, so merge is trivial
new
[
'resolved'
]
=
'new'
return
new
# 3-way merge
raise
ZODB
.
POSException
.
ConflictError
raise
ZODB
.
POSException
.
ConflictError
class
Unresolvable
(
persistent
.
Persistent
):
class
Unresolvable
(
persistent
.
Persistent
):
...
@@ -47,8 +56,17 @@ class Unresolvable(persistent.Persistent):
...
@@ -47,8 +56,17 @@ class Unresolvable(persistent.Persistent):
def
succeed_with_resolution_when_state_is_unchanged
():
def
succeed_with_resolution_when_state_is_unchanged
():
"""
"""
If a conflicting change doesn't change the state, then don't even
If a conflicting change doesn't change the state, then we must still call
bother calling _p_resolveConflict
_p_resolveConflict, even if in most cases the result would be either
committed or new (as shown above in ResolveableWhenStateDoesNotChange).
One use case is to implement an "asynchronous" cache:
- Initially, a cache value is not filled (e.g. None is used to describe
this state).
- A transaction fills the cache (actually done by a background application)
(None -> "foo").
- A concurrent transaction invalidates the cache due to some user action
(None -> None), and pushes a new background task to fill the cache.
Then the expected resolved value is None, and not "foo".
>>> db = ZODB.DB('t.fs') # FileStorage!
>>> db = ZODB.DB('t.fs') # FileStorage!
>>> storage = db.storage
>>> storage = db.storage
...
@@ -63,23 +81,23 @@ def succeed_with_resolution_when_state_is_unchanged():
...
@@ -63,23 +81,23 @@ def succeed_with_resolution_when_state_is_unchanged():
>>> oid = conn.root.x._p_oid
>>> oid = conn.root.x._p_oid
So, let's try resolving when the old and committed states are the same
So, let's try resolving when the old and committed states are the same
b
i
t the new state (pickle) is different:
b
u
t the new state (pickle) is different:
>>> p = storage.tryToResolveConflict(
>>> p = storage.tryToResolveConflict(
... oid, serial1, serial1, storage.loadSerial(oid, serial2))
... oid, serial1, serial1, storage.loadSerial(oid, serial2))
>>>
p == storage.loadSerial(oid, serial2)
>>>
conn._reader.getState(p)['resolved']
True
'new'
And when the old and new states are the same b
i
t the committed state
And when the old and new states are the same b
u
t the committed state
is different:
is different:
>>> p = storage.tryToResolveConflict(
>>> p = storage.tryToResolveConflict(
... oid, serial2, serial1, storage.loadSerial(oid, serial1))
... oid, serial2, serial1, storage.loadSerial(oid, serial1))
>>>
p == storage.loadSerial(oid, serial2)
>>>
conn._reader.getState(p)['resolved']
True
'committed'
But we still conflict if both the committed and new are different than
But we still conflict if both the committed and new are different than
the original:
the original:
...
@@ -92,7 +110,9 @@ the original:
...
@@ -92,7 +110,9 @@ the original:
ConflictError: database conflict error (oid 0x01, ...
ConflictError: database conflict error (oid 0x01, ...
Of course, none of this applies if content doesn't support conflict resolution.
Of course, there's also no automatic trivial merge if content doesn't support
conflict resolution. Touching an object without change is a common locking
mechanism.
>>> conn.root.y = Unresolvable()
>>> conn.root.y = Unresolvable()
>>> conn.root.y.v = 1
>>> conn.root.y.v = 1
...
...
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