Moodle 3.1: Grade recalculation on every grade update

Moodle 3.1: Grade recalculation on every grade update

by Rajneel Totaram -
Number of replies: 0
Picture of Core developers Picture of Plugin developers

We are using Moodle v3.1.3+ and for one course, every time a marker grades an assessment item (assignment) for a student, we get into Recalculating grades for the course.

The course has over 2500 students and has about 20 assessment items (assignments, quizzes, lessons) in the gradebook.

The recalculating grades takes several minutes and sometimes results in "Error writing to database". Trying to do a bulk upload of feedback files or importing marks via CSV are also failing. Its coming to the end of the semester and we can't seem to release marks to the students.

This issue only affects one course. Other large courses are able to successfully complete CSV import and bulk feedback upload with a few minutes and recalculating grades only takes a few seconds in those courses.

Turning on debugging, we've noted that whenever marks are updated, even for a single user, the needsupdate flag the assessment being graded or the course gets set.

The error provided are : during bulk feedback file upload:

Debug info: Deadlock found when trying to get lock; try restarting transaction
UPDATE mdl_grade_items SET needsupdate = ? WHERE (itemtype='course' OR id=?) AND courseid=?
[array (
  0 => 1,
  1 => '106754',
  2 => '7086',
)]
Error code: dmlwriteexception


or when accessing the assignment grading page:

Debug info: Lock wait timeout exceeded; try restarting transaction
UPDATE mdl_grade_items SET needsupdate = ? WHERE id = ?
[array (
  0 => 0,
  1 => '106815',
)]
Error code: dmlwriteexception
Stack trace:

line 477 of /lib/dml/moodle_database.php: dml_write_exception thrown
line 1472 of /lib/dml/mysqli_native_moodle_database.php: call to moodle_database->query_end()
line 1749 of /lib/dml/moodle_database.php: call to mysqli_native_moodle_database->set_field_select()
line 690 of /lib/grade/grade_item.php: call to moodle_database->set_field()
line 1260 of /lib/gradelib.php: call to grade_item->regrading_finished()
line 440 of /lib/gradelib.php: call to grade_regrade_final_grades()
line 439 of /mod/assign/gradingtable.php: call to grade_get_grades()
line 3831 of /mod/assign/locallib.php: call to assign_grading_table->__construct()
line 3906 of /mod/assign/locallib.php: call to assign->view_grading_table()
line 573 of /mod/assign/locallib.php: call to assign->view_grading_page()
line 52 of /mod/assign/view.php: call to assign->view()


Is there any reason why the needsupdate flag is set for the entire course? Why isn't the userid passed so that the query only updates the calculations for the affected user?

Is there any option to disable automatic grade recalculation and do it manually, when needed?


Any advice on helping to find a fix will be greatly appreciated.


Thanks,
...Rajneel