Problem/Motivation

On a Drupal installation with a large number of configuration files (I have one with over 1,900), It is not possible to update Drupal core to 9.3.0. When the update gets to the "sort_all_config" post-update hook, that hook fails with allowed memory exhausted.

Proposed resolution

The function system_post_update_sort_all_config() in system.post_update.php attempts to update all configuration files in a single execution. This should be converted to a batch process.

Remaining tasks

Review the patch file provided in this issue.

Release notes snippet

TBD

Comments

paulmckibben created an issue. See original summary.

paulmckibben’s picture

Status: Active » Needs review
StatusFileSize
new1.26 KB
paulmckibben’s picture

Issue summary: View changes

(fixed typo in description)

cilefen’s picture

Title: Update from 9.2.9 to 9.3.0 fails: Update aborted by system_post_update_sort_all_config - out of memory » system_post_update_sort_all_config can exhaust PHP memory in 9.3.0
Priority: Major » Critical
longwave’s picture

Thanks for working on this.

  1. +++ b/core/modules/system/system.post_update.php
    @@ -208,9 +208,29 @@ function system_post_update_delete_authorize_settings() {
    +  $iteration_size = 50;
    

    I think this should use entity_update_batch_size:

    /**
     * The default number of entities to update in a batch process.
     *
     * This is used by update and post-update functions that need to go through and
     * change all the entities on a site, so it is useful to increase this number
     * if your hosting configuration (i.e. RAM allocation, CPU speed) allows for a
     * larger number of entities to be processed in a single batch run.
     */
    $settings['entity_update_batch_size'] = 50;
    
  2. +++ b/core/modules/system/system.post_update.php
    @@ -208,9 +208,29 @@ function system_post_update_delete_authorize_settings() {
    +  if ($sandbox['max'] > 0) {
    

    Not sure this is necessary, there must be at least one config entity?

paulmckibben’s picture

StatusFileSize
new1.27 KB
new1.08 KB

@longwave Thanks for the review! I didn't know about that setting - great idea. I've updated my patch addressing both of your comments.

ranjith_kumar_k_u’s picture

StatusFileSize
new1.51 KB
new805 bytes

Fixed CS error.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

Looks good, ran it locally and get a nice progress bar and everything.

Took a look at maybe simplifying the logic a little bit to make it a little easier to read, but this works so ¯\_(ツ)_/¯

longwave’s picture

Over in #3254169-34: Update aborted by system_post_update_sort_all_config. Drush command terminated abnormally. Output is empty. @bmango reports:

I have applied the patch from #3254403: system_post_update_sort_all_config can exhaust PHP memory in 9.3.0, and I am still getting out of memory. I also flushed caches.

longwave’s picture

Posting just to add I don't think this should stop this being committed, as batching the update can only make it better - even if it hasn't solved it for everyone.

  • catch committed d55c0cb on 10.0.x
    Issue #3254403 by paulmckibben, ranjith_kumar_k_u, longwave, Lendude,...

  • catch committed 45c6d25 on 9.4.x
    Issue #3254403 by paulmckibben, ranjith_kumar_k_u, longwave, Lendude,...

  • catch committed 08a4f0f on 9.3.x
    Issue #3254403 by paulmckibben, ranjith_kumar_k_u, longwave, Lendude,...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Would normally use array_chunk() for an update function like this, but the for loop is fine.

If this was all config entities we could have used config entity updater, but it's not, so the manual batch is OK. And even though they're not entities, using the entity_update_batch size seems correct here.

Committed/pushed to 10.0.x and cherry-picked to 9.4.x and 9.3.x, thanks!

vlyalko’s picture

Have applied the patch and still getting out of memory.

cilefen’s picture

Are you certain the system_post_update_sort_all_config function is executing when that occurs?

vlyalko’s picture

Yes, I am 100% sure

vlyalko’s picture

It worked on sanitized database, but not on prod. Set php and drush memory limit to 2G. Still not working. Tried even set to 3G, but drush limit not taking 3G. We are using mariadb 10.5.12
memory limit error

vlyalko’s picture

StatusFileSize
new134.68 KB
cilefen’s picture

What is entity_update_batch_size set to on that instance?

vlyalko’s picture

in settings.php: $settings['entity_update_batch_size'] = 50;

vlyalko’s picture

Status: Fixed » Needs work
cilefen’s picture

Title: system_post_update_sort_all_config can exhaust PHP memory in 9.3.0 » system_post_update_sort_all_config can exhaust PHP memory in 9.3.0 because processing is not batched
Status: Needs work » Fixed

Let’s leave this one fixed and work the other issue for whatever cases don’t seem to be fixed by batching.

abhishek.kumar’s picture

StatusFileSize
new1.3 MB

I did upgrade my Drupal from 8.9.x to 9.3.2 and I am still facing the issue to perform database updates. In 9.3.2 no need to apply the patch however going through this thread I have reduced $iteration_size = 1; and still memory utilization going more than 100GB and after some time it throws "The process has been signaled with signal "9". "

Please find the attached screen for the same. Does anyone have any solution to this?

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

hasinanjaratin’s picture

Run first, drush cim before updatedb