Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-79639

Deadlock while running adhoc task quiz_statistics\task\recalculate

XMLWordPrintable

    • MOODLE_401_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE, MOODLE_403_STABLE
    • MDL-79639_401_STABLE
    • MDL-79639_402_STABLE
    • MDL-79639_403_STABLE
    • MDL-79639_master
    • Hide

      Please refer to Jordi's comments from 17th October for evidence that this patch resolves the problem. Due to the complexity of this scenario, these instructions don't attempt to reproduce the whole set-up, but provide steps to ensure that the fix does not cause any regressions within the calculation process.

      Environment: MySQL (whichever version is supported for each tested version of Moodle)

      1. Create a course with some enrolled students.
      2. Create a quiz and add some questions.
      3. Log in as a student and attempt the quiz.
      4. Either wait 1 hour, or run the following query: `UPDATE mdl_tasks_adhoc SET nextruntime=0 WHERE class='\quiz_statistics\task\recalculate'`
      5. Run `php admin/cli/adhoc_task.php "--execute=\quiz_statistics\task\recalculate"` to run the recalculation task. (php `admin/cli/adhoc_task.php --execute` on Moodle 4.1).
        • Confirm that the task runs without error.
      6. Attempt the quiz again.
      7. Repeat steps 4 and 5 again to re-run the calculations. As this is running a second time, it will also clear the cached data from the first run, which covers the code modified by this fix.
        • Confirm that the task runs without error.
      Show
      Please refer to Jordi's comments from 17th October for evidence that this patch resolves the problem. Due to the complexity of this scenario, these instructions don't attempt to reproduce the whole set-up, but provide steps to ensure that the fix does not cause any regressions within the calculation process. Environment: MySQL (whichever version is supported for each tested version of Moodle) Create a course with some enrolled students. Create a quiz and add some questions. Log in as a student and attempt the quiz. Either wait 1 hour, or run the following query: `UPDATE mdl_tasks_adhoc SET nextruntime=0 WHERE class='\quiz_statistics\task\recalculate'` Run `php admin/cli/adhoc_task.php "--execute=\quiz_statistics\task\recalculate"` to run the recalculation task. (php `admin/cli/adhoc_task.php --execute` on Moodle 4.1). Confirm that the task runs without error. Attempt the quiz again. Repeat steps 4 and 5 again to re-run the calculations. As this is running a second time, it will also clear the cached data from the first run, which covers the code modified by this fix. Confirm that the task runs without error.

      I think this is something not addressed on MDL-78580.

      Context

      Moodle 4.1.6 (Build: 20231009), with MDL-78580 included.
      MySQL 5.7
      Execution of every adhoc task quiz_statistics\task\recalculate

      Problem

      We can see this kind of errors on every run of the adhoc task:

      Execute adhoc task: quiz_statistics\task\recalculate
      Adhoc task id: 18149902
      Adhoc task custom data:

      {"quizid":99498}

      ... started 09:02:16. Current memory use 47.2 MB.
      Re-calculating statistics for quiz Qüestionari Termo Tema 1 (99498) from course 23-24 TERMODINÀMICA I HIDRÀULICA (118824) (98715) with 37 attempts, start time 10/10/23, 09:02:16 ...
      ... used 796 dbqueries
      ... used 81.458127975464 seconds
      Adhoc task failed: quiz_statistics\task\recalculate,S'ha produït un error en escriure a la base de dades. (Deadlock found when trying to get lock; try restarting transaction
      DELETE FROM mdl_question_response_count WHERE analysisid IN (
      SELECT id
      FROM mdl_question_response_analysis
      WHERE hashcode= ? AND whichtries = ? AND questionid = ?
      )
      [array (
      0 => '1c744dc827c01f5b9c472805aa25d2381a1ea7e0',
      1 => 'alltries',
      2 => '24480951',
      )])
      Debug info:
      Deadlock found when trying to get lock; try restarting transaction
      DELETE FROM mdl_question_response_count WHERE analysisid IN (
      SELECT id
      FROM mdl_question_response_analysis
      WHERE hashcode= ? AND whichtries = ? AND questionid = ?
      )
      [array (
      0 => '1c744dc827c01f5b9c472805aa25d2381a1ea7e0',
      1 => 'alltries',
      2 => '24480951',
      )]
      Backtrace:

      • line 293 of /lib/dml/moodle_read_slave_trait.php: call to moodle_database->query_end()
      • line 1703 of /lib/dml/mysqli_native_moodle_database.php: call to mysqli_native_moodle_database->query_end()
      • line 216 of /question/classes/statistics/responses/analysis_for_question.php: call to mysqli_native_moodle_database->delete_records_select()
      • line 140 of /question/classes/statistics/responses/analyser.php: call to core_question\statistics\responses\analysis_for_question->cache()
      • line 803 of /mod/quiz/report/statistics/report.php: call to core_question\statistics\responses\analyser->calculate()
      • line 774 of /mod/quiz/report/statistics/report.php: call to quiz_statistics_report->analyse_responses_for_questions()
      • line 721 of /mod/quiz/report/statistics/report.php: call to quiz_statistics_report->analyse_responses_for_all_questions_and_subquestions()
      • line 1003 of /mod/quiz/report/statistics/report.php: call to quiz_statistics_report->get_all_stats_and_analysis()
      • line 94 of /mod/quiz/report/statistics/classes/task/recalculate.php: call to quiz_statistics_report->calculate_questions_stats_for_question_bank()
      • line 367 of /lib/cronlib.php: call to quiz_statistics\task\recalculate->execute()
      • line 198 of /lib/cronlib.php: call to cron_run_inner_adhoc_task()
      • line 76 of /lib/cronlib.php: call to cron_run_adhoc_tasks()
      • line 178 of /admin/cli/cron.php: call to cron_run()

      What is it expected?

      No error and normal execution.

      Related information

            marxjohnson Mark Johnson
            jpahullo Jordi Pujol-Ahulló
            Tim Hunt Tim Hunt
            Huong Nguyen Huong Nguyen
            Mathew May Mathew May
            Votes:
            5 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 hour, 25 minutes
                1h 25m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.