Commit 10c96d61 authored by Vincent Pelletier's avatar Vincent Pelletier

After undoing an object, its current serial goes back in time.

This is important for chaining "undo" for a given object in a single
transaction, to allow checking for conflicts.
Also, this means that get_baseTID return value cannot be used to update
cache when undoing, so only update cache when storing a new revision.
Actually, cache was never updated when undoing anyway, as current snapshot
TID was unlikely to exist as a serial for any object, so it would not be
found in cache and update would be a no-op.

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2597 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 7fccafeb
...@@ -102,6 +102,7 @@ class ThreadContext(object): ...@@ -102,6 +102,7 @@ class ThreadContext(object):
'txn': None, 'txn': None,
'data_dict': {}, 'data_dict': {},
'data_list': [], 'data_list': [],
'object_base_serial_dict': {},
'object_serial_dict': {}, 'object_serial_dict': {},
'object_stored_counter_dict': {}, 'object_stored_counter_dict': {},
'conflict_serial_dict': {}, 'conflict_serial_dict': {},
...@@ -727,6 +728,9 @@ class Application(object): ...@@ -727,6 +728,9 @@ class Application(object):
data_dict[oid] = data data_dict[oid] = data
# Store data on each node # Store data on each node
self.local_var.object_stored_counter_dict[oid] = {} self.local_var.object_stored_counter_dict[oid] = {}
object_base_serial_dict = local_var.object_base_serial_dict
if oid not in object_base_serial_dict:
object_base_serial_dict[oid] = serial
self.local_var.object_serial_dict[oid] = serial self.local_var.object_serial_dict[oid] = serial
queue = self.local_var.queue queue = self.local_var.queue
add_involved_nodes = self.local_var.involved_nodes.add add_involved_nodes = self.local_var.involved_nodes.add
...@@ -760,6 +764,7 @@ class Application(object): ...@@ -760,6 +764,7 @@ class Application(object):
local_var = self.local_var local_var = self.local_var
# Check for conflicts # Check for conflicts
data_dict = local_var.data_dict data_dict = local_var.data_dict
object_base_serial_dict = local_var.object_base_serial_dict
object_serial_dict = local_var.object_serial_dict object_serial_dict = local_var.object_serial_dict
conflict_serial_dict = local_var.conflict_serial_dict.copy() conflict_serial_dict = local_var.conflict_serial_dict.copy()
local_var.conflict_serial_dict.clear() local_var.conflict_serial_dict.clear()
...@@ -815,6 +820,8 @@ class Application(object): ...@@ -815,6 +820,8 @@ class Application(object):
dump(conflict_serial)) dump(conflict_serial))
# Mark this conflict as resolved # Mark this conflict as resolved
resolved_serial_set.update(conflict_serial_set) resolved_serial_set.update(conflict_serial_set)
# Base serial changes too, as we resolved a conflict
object_base_serial_dict[oid] = conflict_serial
# Try to store again # Try to store again
self._store(oid, conflict_serial, new_data) self._store(oid, conflict_serial, new_data)
append(oid) append(oid)
...@@ -983,7 +990,7 @@ class Application(object): ...@@ -983,7 +990,7 @@ class Application(object):
assert next_tid is None, (dump(oid), dump(base_tid), assert next_tid is None, (dump(oid), dump(base_tid),
dump(next_tid)) dump(next_tid))
return (data, tid) return (data, tid)
get_baseTID = local_var.object_serial_dict.get get_baseTID = local_var.object_base_serial_dict.get
for oid, data in local_var.data_dict.iteritems(): for oid, data in local_var.data_dict.iteritems():
if data is None: if data is None:
# this is just a remain of # this is just a remain of
......
...@@ -362,11 +362,8 @@ class DatabaseManager(object): ...@@ -362,11 +362,8 @@ class DatabaseManager(object):
undone_tid = u64(undone_tid) undone_tid = u64(undone_tid)
_getDataTID = self._getDataTID _getDataTID = self._getDataTID
if transaction_object is not None: if transaction_object is not None:
toid, tcompression, tchecksum, tdata, tvalue_serial = \ _, _, _, _, tvalue_serial = transaction_object
transaction_object current_tid = current_data_tid = u64(tvalue_serial)
current_tid, current_data_tid = self._getDataTIDFromData(oid,
(ltid, None, tcompression, tchecksum, tdata,
u64(tvalue_serial)))
else: else:
current_tid, current_data_tid = _getDataTID(oid, before_tid=ltid) current_tid, current_data_tid = _getDataTID(oid, before_tid=ltid)
if current_tid is None: if current_tid is None:
......
...@@ -729,14 +729,14 @@ class StorageDBTests(NeoUnitTestBase): ...@@ -729,14 +729,14 @@ class StorageDBTests(NeoUnitTestBase):
# Undoing oid1 tid1 with tid2 being undone in same transaction, # Undoing oid1 tid1 with tid2 being undone in same transaction,
# OK: tid1 is latest # OK: tid1 is latest
# Result: current tid is tid2, data_tid is None (undoing object # Result: current tid is tid1, data_tid is None (undoing object
# creation) # creation)
# Explanation of transaction_object: oid1, no data but a data serial # Explanation of transaction_object: oid1, no data but a data serial
# to tid1 # to tid1
self.assertEqual( self.assertEqual(
db.findUndoTID(oid1, tid5, tid4, tid1, db.findUndoTID(oid1, tid5, tid4, tid1,
(u64(oid1), None, None, None, tid1)), (u64(oid1), None, None, None, tid1)),
(tid4, None, True)) (tid1, None, True))
# Store a new transaction # Store a new transaction
db.storeTransaction( db.storeTransaction(
......
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