Issue Details (XML | Word | Printable)

Key: MDL-11160
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Minor Minor
Assignee: Nick Freear
Reporter: Nick Freear
Votes: 0
Watchers: 3
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Cron exhausts memory on "Removing expired enrolments ..."

Created: 08/Sep/07 12:29 AM   Updated: 19/Sep/07 11:40 AM
Return to search
Component/s: Database SQL/XMLDB
Affects Version/s: 1.8, 1.9
Fix Version/s: 1.8.3, 1.9

File Attachments: 1. File patch-Bug-3791-cron_memory_enrolments_2.diff (2 kB)
2. File patch-Bug-3791-cron_memory_enrolments_4.diff (2 kB)

Environment:
The following SQL on the OU's live system returned count = 176574,
    SELECT COUNT(*) FROM mdl_role_assignments WHERE timeend > 0 AND timeend < 1189123200;
Issue Links:
Relates
 

Database: PostgreSQL
Participants: Eloy Lafuente (stronk7), Martin Dougiamas, Martín Langhoff, Nick Freear and Yu Zhang
Security Level: None
Resolved date: 14/Sep/07
Affected Branches: MOODLE_18_STABLE, MOODLE_19_STABLE
Fixed Branches: MOODLE_18_STABLE, MOODLE_19_STABLE


 Description  « Hide
Escalated from OU Bug 3791, 'Live cron exhausts memory, before "core" jobs including sync_metacourses'

Cron is consistently failing on
   "Removing expired enrolments ...Allowed memory size of 134217728 bytes exhausted..."

The attached patch uses the preferred 'rs_fetch_next_record' call, and only gets required fields, to reduce memory use.
It removes the 'course' table, enrolperiod>0 check and loop, introduced for Bug MDL-10181 (also MDL-8785) - is this really necessary? If so this SQL join could form the basis.

SELECT ra.roleid, ra.userid, ra.contextid
  FROM mdl_course c
  INNER JOIN mdl_context cx ON cx.instanceid = c.id
  INNER JOIN mdl_role_assignments ra ON ra.contextid = cx.id
  WHERE cx.contextlevel = '50'
  AND timeend > 0
  AND timeend < 1189123200;
--AND c.enrolperiod > 0;

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Nick Freear committed 1 file to 'Moodle CVS' - 13/Sep/07 05:13 PM
MDL-11160, Cron exhausts memory on "Removing expired enrolments ..." - changing nested foreach to JOINs with while(..rs_fetch_next_record).
MODIFY admin/cron.php   Rev. 1.116    (+17 -12 lines)
Nick Freear committed 1 file to 'Moodle CVS' on branch 'MOODLE_18_STABLE' - 14/Sep/07 11:48 PM
MDL-11160 'Live cron runs out of memory, before "core" ...' - tailored get_recordset_.. fix for 1.8 branch.
MODIFY admin/cron.php   Rev. 1.98.2.8    (+14 -8 lines)
Nick Freear committed 1 file to 'Moodle CVS' on branch 'MOODLE_18_STABLE' - 17/Sep/07 05:19 PM
MDL-11160 'Live cron runs out of memory ...' - added enrolment check, to match HEAD.
MODIFY admin/cron.php   Rev. 1.98.2.9    (+13 -6 lines)