Commit 77424415 authored by Julien Muchembled's avatar Julien Muchembled

CMFActivity: enable node preference by default in some safe cases

parent 301962ad
......@@ -68,6 +68,8 @@ class ActiveObject(ExtensionClass.Base):
- "same": prefer execution on this node, to make
better use of the ZODB Storage cache
- "": no node preference
- None (default): let CMFActivity decide between the above 2 choice
(see ActivityTool.activateObject)
at_date -- request execution date for this activate call
(default: date of commit)
......
......@@ -91,6 +91,11 @@ _server_address = None
ROLE_IDLE = 0
ROLE_PROCESSING = 1
# Activating a path means we tried to avoid loading useless
# data in cache so there would be no gain to expect.
# And all nodes are likely to have tools already loaded.
NO_DEFAULT_NODE_PREFERENCE = str, BaseTool
# Logging channel definitions
import logging
# Main logging channel
......@@ -1205,14 +1210,25 @@ class ActivityTool (BaseTool):
url = object.getPhysicalPath()
if serialization_tag is not None:
kw['serialization_tag'] = serialization_tag
if node is not None:
if node != 'same':
while 1: # not a loop
if node is None:
# The caller lets us decide whether we prefer to execute on same node
# (to increase the efficiency of the ZODB Storage cache).
if (isinstance(object, NO_DEFAULT_NODE_PREFERENCE)
# A grouped activity is the sign we may have many of them so make
# sure that this node won't overprioritize too many activities.
or kw.get('group_method_id', '') != ''):
break
elif node == '':
break
elif node != 'same':
raise ValueError("Invalid node argument %r" % node)
try:
kw['node'] = 1 + self.getNodeList(
role=ROLE_PROCESSING).index(getCurrentNode())
except ValueError:
pass
break
return ActiveWrapper(self, url, oid, activity,
active_process, active_process_uid, kw,
getattr(self, 'REQUEST', None))
......
......@@ -2490,7 +2490,7 @@ class TestCMFActivity(ERP5TypeTestCase, LogInterceptor):
activities = 'SQLDict', 'SQLQueue'
for activities in product(activities, activities):
for node, expected in (None, '21'), ("same", '12'):
for node, expected in (None, '12'), ('', '21'), ('same', '12'):
o._setTitle('0')
# The dance around getNodeDict is to simulate the creation of
# activities from 2 different nodes. We also change title in 2
......
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