Commit 563c86c1 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Ensure that SQLDict never leave messages as processed

when a ConflictError occurs.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@8157 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 196a98b1
...@@ -233,20 +233,21 @@ class SQLDict(RAMDict): ...@@ -233,20 +233,21 @@ class SQLDict(RAMDict):
activity_tool.SQLDict_processMessage(uid = uid_list) activity_tool.SQLDict_processMessage(uid = uid_list)
get_transaction().commit() # Release locks before starting a potentially long calculation get_transaction().commit() # Release locks before starting a potentially long calculation
# This may lead (1 for 1,000,000 in case of reindexing) to messages left in processing state # This may lead (1 for 1,000,000 in case of reindexing) to messages left in processing state
# At this point, messages are marked as processed. So catch any kind of exception to make sure
# that they are unmarked on error.
try:
m = self.loadMessage(line.message, uid = line.uid) m = self.loadMessage(line.message, uid = line.uid)
message_list = [m] message_list = [m]
# Validate message (make sure object exists, priority OK, etc.) # Validate message (make sure object exists, priority OK, etc.)
if self.validateMessage(activity_tool, m, uid_list, line.priority, processing_node): if not self.validateMessage(activity_tool, m, uid_list, line.priority, processing_node):
return 0
group_method_id = m.activity_kw.get('group_method_id') group_method_id = m.activity_kw.get('group_method_id')
if group_method_id is not None: if group_method_id is not None:
# Count the number of objects to prevent too many objects. # Count the number of objects to prevent too many objects.
if m.hasExpandMethod(): if m.hasExpandMethod():
try:
count = len(m.getObjectList(activity_tool)) count = len(m.getObjectList(activity_tool))
except:
# Here, simply ignore an exception. The same exception should be handled later.
LOG('SQLDict', 0, 'ignoring an exception from getObjectList', error=sys.exc_info())
count = 0
else: else:
count = 1 count = 1
...@@ -269,25 +270,37 @@ class SQLDict(RAMDict): ...@@ -269,25 +270,37 @@ class SQLDict(RAMDict):
# Set selected messages to processing # Set selected messages to processing
activity_tool.SQLDict_processMessage(uid = uid_list) activity_tool.SQLDict_processMessage(uid = uid_list)
get_transaction().commit() # Release locks before starting a potentially long calculation get_transaction().commit() # Release locks before starting a potentially long calculation
# Save this newly marked uids as soon as possible.
uid_list_list.append(uid_list)
m = self.loadMessage(line.message, uid = line.uid) m = self.loadMessage(line.message, uid = line.uid)
if self.validateMessage(activity_tool, m, uid_list, line.priority, processing_node): if self.validateMessage(activity_tool, m, uid_list, line.priority, processing_node):
if m.hasExpandMethod(): if m.hasExpandMethod():
try:
count += len(m.getObjectList(activity_tool)) count += len(m.getObjectList(activity_tool))
except:
# Here, simply ignore an exception. The same exception should be handled later.
LOG('SQLDict', 0, 'ignoring an exception from getObjectList', error=sys.exc_info())
pass
else: else:
count += 1 count += 1
message_list.append(m) message_list.append(m)
uid_list_list.append(uid_list)
priority_list.append(line.priority) priority_list.append(line.priority)
if count >= MAX_GROUPED_OBJECTS: if count >= MAX_GROUPED_OBJECTS:
break break
else:
# If the uids were not valid, remove them from the list, as validateMessage
# unmarked them.
uid_list_list.pop()
# Release locks before starting a potentially long calculation # Release locks before starting a potentially long calculation
get_transaction().commit() get_transaction().commit()
except:
# If an exception occurs, abort the transaction to minimize the impact,
# then simply delay the operations.
get_transaction().abort()
for uid_list in uid_list_list:
activity_tool.SQLDict_setPriority(uid = uid_list, delay = VALIDATION_ERROR_DELAY,
retry = 1)
get_transaction().commit()
return 0
# Try to invoke # Try to invoke
if group_method_id is not None: if group_method_id is not None:
LOG('SQLDict', TRACE, LOG('SQLDict', TRACE,
......
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