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