Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete quiz attempts in chunks of 1000 #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

1katoda
Copy link

@1katoda 1katoda commented Feb 15, 2024

We have a pretty large database, where a need arose to delete quiz attempts that are at least a year old. When we ran the delete_attempts function, there was no output, the script just stopped after 2 seconds. Manually querying the database revealed that the script had about 750000 attempts to delete, which seems to have caused it to crash.

Modifying the loop to only hold 1000 attempts in memory at a time fixes that.

@vadimonus
Copy link
Owner

vadimonus commented Feb 17, 2024

@1katoda , thank's for your contribution. Currently code is using recordsets, recommended way of working with huge datasets. Moodle documentation do not say, that chunks are needed when working with recordset. So firstly i need some time to reproduce your problem, to be sure chunks are right solution.
Please provide information about your environment: OS, php version, moodle version, database type and version.
If you can find some php logs or OS logs (like oomkiller) that are relevant to situation, they would be very useful

@1katoda
Copy link
Author

1katoda commented Feb 17, 2024

Understandable, testing is needed.

The staging server where the bug was encountered is an 8-core VM with 16G of RAM and PHP 7.4. Database is a local MariaDB 10.5 instance and Moodle release 4.1.7+ (Build: 20231215).

The specific course from which attempts were attempted to be deleted had ~900.000 attempts with ~760.000 being older that one year.

Unfortunately I couldn't find any relevant logs in syslog for the issue and CLI PHP doesn't get logged. The script appeared to have run succesfully, as if there weren't any attempts to delete. It just exited and produced no output (with --verbose flag) after about 2 seconds. I then modified the plugin to turn on sql debugging before deleting attempts, which showed me the last query to run (recordset). I ran the query manually in the mysql client, where the query itself was finished in about 2s, but the client was still returning the data of those 750.000 records 20s in. So I modified the loop to delete in chunks, which solved the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants