Commit caea03ca authored by Julien Muchembled's avatar Julien Muchembled

IStorage: simplify the API of store/tpc_finish to notify of resolved conflicts

parent cf02e50a
......@@ -28,7 +28,7 @@ from pickle import PicklingError
logger = logging.getLogger('ZODB.ConflictResolution')
ResolvedSerial = b'rs'
ResolvedSerial = b'rs' # deprecated: store/tpc_finish should just use True
class BadClassName(Exception):
pass
......
......@@ -705,7 +705,7 @@ class Connection(ExportImport, object):
self._handle_serial(oid, s)
def _handle_serial(self, oid, serial, change=True):
def _handle_serial(self, oid, serial=True, change=True):
# if we write an object, we don't want to check if it was read
# while current. This is a convenient choke point to do this.
......@@ -713,7 +713,9 @@ class Connection(ExportImport, object):
if not serial:
return
if not isinstance(serial, bytes):
if serial is True:
serial = ResolvedSerial
elif not isinstance(serial, bytes):
raise serial
obj = self._cache.get(oid, None)
if obj is None:
......@@ -721,6 +723,7 @@ class Connection(ExportImport, object):
if serial == ResolvedSerial:
del obj._p_changed # transition from changed to ghost
else:
self._warn_about_returned_serial()
if change:
obj._p_changed = 0 # transition from changed to up-to-date
obj._p_serial = serial
......@@ -790,6 +793,11 @@ class Connection(ExportImport, object):
raise
if s:
if type(s[0]) is bytes:
for oid in s:
self._handle_serial(oid)
return
self._warn_about_returned_serial()
for oid, serial in s:
self._handle_serial(oid, serial)
......@@ -829,9 +837,9 @@ class Connection(ExportImport, object):
self._warn_about_returned_serial = lambda: None
else:
warnings.warn(
"In ZODB 5+, it will be required for tpc_finish to return the"
" committed tid. store/tpc_vote will only have to notify about"
" resolved conflicts.",
"In ZODB 5+, the new API for the returned value of"
" store/tpc_vote/tpc_finish will be mandatory."
" See IStorage for more information.",
DeprecationWarning, 2)
Connection._warn_about_returned_serial = lambda self: None
......
......@@ -797,13 +797,14 @@ class IStorage(Interface):
without an error, then there must not be an error if
tpc_finish or tpc_abort is called subsequently.
The return value can be either None or a sequence of object-id
and serial pairs giving new serials for objects who's ids were
passed to previous store calls in the same transaction.
A serial returned in a sequence of oid/serial pairs, may be
the special value ZODB.ConflictResolution.ResolvedSerial to
indicate that a conflict occured and that the object should be
The return value can be either None or a sequence of oids for which
a conflict was resolved.
For compatibility, the return value can also be a sequence of object-id
and serial pairs giving new serials for objects whose ids were
passed to previous store calls in the same transaction. The serial
can be the special value ZODB.ConflictResolution.ResolvedSerial to
indicate that a conflict occurred and that the object should be
invalidated.
After the tpc_vote call, all solved conflicts must have been notified,
......
......@@ -58,8 +58,8 @@ class DemoStorage(ZODB.DemoStorage.DemoStorage):
assert type(s) is bytes, s
return
if not self.delayed_store:
return s
self.__stored.append((oid, s))
return True
self.__stored.append(oid)
tpc_vote = property(lambda self: self._tpc_vote, lambda *_: None)
......
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