Commit dbfbdcd4 authored by Jérome Perrin's avatar Jérome Perrin

upgrader: really execute the whole `upgrade` step in one transaction

Documentation says this step is done in one transaction, so implement
this as documented.

Detecting developer mistake and automagically running this step in smaller
transactions if more than 100 documents seems unnecessary. At least, it
contredicts documentation.
parent 59cce559
Pipeline #2553 skipped
...@@ -50,19 +50,14 @@ ...@@ -50,19 +50,14 @@
</item> </item>
<item> <item>
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <value> <string>"""\n
"""\n
Run Upgrade step\n Run Upgrade step\n
\n \n
IMPORTANT: Don\'t use the constraint_type upgrader to data migration or big amount of objects,\n IMPORTANT: Don\'t use the constraint_type upgrader to data migration or big amount of objects,\n
because this step is suppose to run all constraints in the same transaction. \n because this step is suppose to run all constraints in the same transaction. \n
To not kill the instance, searchAndActivate will be used if countResults() > REINDEX_SPLIT_COUNT\n
"""\n """\n
\n \n
REINDEX_SPLIT_COUNT = 100\n
portal = context.getPortalObject()\n portal = context.getPortalObject()\n
portal_alarms = portal.portal_alarms\n
\n \n
_, type_per_constraint_type = context.Base_getConstraintTypeListPerPortalType()\n _, type_per_constraint_type = context.Base_getConstraintTypeListPerPortalType()\n
portal_type_list = type_per_constraint_type.get(\'upgrader\', [])\n portal_type_list = type_per_constraint_type.get(\'upgrader\', [])\n
...@@ -82,22 +77,16 @@ with context.defaultActivateParameterDict(activate_kw, placeless=True):\n ...@@ -82,22 +77,16 @@ with context.defaultActivateParameterDict(activate_kw, placeless=True):\n
\'activate_kw\': activate_kw,\n \'activate_kw\': activate_kw,\n
}\n }\n
\n \n
# always run on portal_templates, regardless of catalog state.\n
portal.portal_templates.Base_postCheckConsistencyResult(**method_kw)\n portal.portal_templates.Base_postCheckConsistencyResult(**method_kw)\n
for portal_type in portal_type_list:\n \n
if portal.portal_catalog.countResults(\n # run on all portal_types with an `upgrader` constraint, except portal_templates we already run before.\n
portal_type=portal_type_list)[0][0] > REINDEX_SPLIT_COUNT:\n if portal_type_list:\n
portal.portal_catalog.searchAndActivate(\'Base_postCheckConsistencyResult\',\n for result in portal.portal_catalog(portal_type=portal_type_list):\n
activate_kw=activate_kw,\n
portal_type=portal_type,\n
method_kw=method_kw)\n
else:\n
for result in portal.portal_catalog(portal_type=portal_type):\n
result.Base_postCheckConsistencyResult(**method_kw)\n result.Base_postCheckConsistencyResult(**method_kw)\n
\n \n
context.setEnabled(False)\n context.setEnabled(False)\n
</string> </value>
]]></string> </value>
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
......
...@@ -333,28 +333,12 @@ class TestUpgrader(ERP5TypeTestCase): ...@@ -333,28 +333,12 @@ class TestUpgrader(ERP5TypeTestCase):
self.assertEqual({'immediateReindexObject', 'unindexObject'}, self.assertEqual({'immediateReindexObject', 'unindexObject'},
{x.method_id for x in portal_activities.getMessageList()}) {x.method_id for x in portal_activities.getMessageList()})
def stepCreateBigIncosistentData(self, sequence=None):
for _ in range(101):
self.portal.organisation_module.newContent(
portal_type="Organisation",
title="org_%s" % self.portal.organisation_module.getLastId())
def stepCreateSmallIncosistentData(self, sequence=None): def stepCreateSmallIncosistentData(self, sequence=None):
for _ in range(4): for _ in range(4):
self.portal.organisation_module.newContent( self.portal.organisation_module.newContent(
portal_type="Organisation", portal_type="Organisation",
title="org_%s" % self.portal.organisation_module.getLastId()) title="org_%s" % self.portal.organisation_module.getLastId())
def stepCheckActivitiesCreated(self, sequence=None):
portal_activities = self.getActivityTool()
self.assertEqual({'Alarm_runUpgrader', 'notify'},
{x.method_id for x in portal_activities.getMessageList()})
for message in portal_activities.getMessageList():
portal_activities.manageInvoke(message.object_path, message.method_id)
self.commit()
self.assertIn('Base_postCheckConsistencyResult',
{x.method_id for x in portal_activities.getMessageList()})
def stepUninstallERP5UpgraderTestBT(self, sequence=None): def stepUninstallERP5UpgraderTestBT(self, sequence=None):
bt5 = self.portal.portal_templates.getInstalledBusinessTemplate('erp5_web') bt5 = self.portal.portal_templates.getInstalledBusinessTemplate('erp5_web')
bt5.uninstall() bt5.uninstall()
...@@ -568,12 +552,6 @@ class TestUpgrader(ERP5TypeTestCase): ...@@ -568,12 +552,6 @@ class TestUpgrader(ERP5TypeTestCase):
stepTic stepTic
stepRunUpgrader stepRunUpgrader
stepCheckNoActivitiesCreated stepCheckNoActivitiesCreated
stepCreateBigIncosistentData
stepTic
stepActiveSenseUpgradeAlarm
stepTic
stepRunUpgrader
stepCheckActivitiesCreated
stepRemoveConstraintFromOrganisationPortalType stepRemoveConstraintFromOrganisationPortalType
""" """
sequence_list.addSequenceString(sequence_string) sequence_list.addSequenceString(sequence_string)
......
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