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

Cache loader coursemodinfo setaftervalidation can create a lock issue

XMLWordPrintable

    • MOODLE_401_STABLE, MOODLE_402_STABLE
    • MOODLE_401_STABLE, MOODLE_402_STABLE
    • MDL-76865-401
    • MDL-76865-master
    • Hide

      Using a fresh installation from the latest master branch...

      1. Add a new File cache store instance called "local_file", set the directory name to an empty directory (e.g. "/tmp/muc") and tick auto create directory option if required.
      2. Add another new File cache store instance called "stacked_file", set the directory name to a different empty directory (e.g. "/tmp/muc2") and tick auto create directory option if required.
      3. Edit the core/coursemodinfo definition store mappings and set the primary store to local_file and the final store to stacked_file.
      4. Create a new empty course page, no need to add any activities.
      5. Change the default "General" heading of your new course page using the in-place editor to prime both cache stores.
      6. Remove any directories inside /tmp/muc/core_coursemodinfo to clear the local cache, but leave the stacked cache primed.
      7. Change the section 1 heading a second time.
      8. Before fix: Observe the web service request to core_update_inplace_editable takes a very long time to return anything (Maximum lock wait time * number of store instances) without this patch.
        After fix: The web service returned promptly and the section heading updates without a long wait, as in step 5.
      Show
      Using a fresh installation from the latest master branch... Add a new File cache store instance called "local_file", set the directory name to an empty directory (e.g. "/tmp/muc") and tick auto create directory option if required. Add another new File cache store instance called "stacked_file", set the directory name to a different empty directory (e.g. "/tmp/muc2") and tick auto create directory option if required. Edit the core/coursemodinfo definition store mappings and set the primary store to local_file and the final store to stacked_file. Create a new empty course page, no need to add any activities. Change the default "General" heading of your new course page using the in-place editor to prime both cache stores. Remove any directories inside /tmp/muc/core_coursemodinfo to clear the local cache, but leave the stacked cache primed. Change the section 1 heading a second time. Before fix: Observe the web service request to core_update_inplace_editable takes a very long time to return anything (Maximum lock wait time * number of store instances) without this patch. After fix: The web service returned promptly and the section heading updates without a long wait, as in step 5.

      Currently when coursemodinfo cache uses 2 stores (i.e. a shared store and a local store) it will obtain a lock when setting the shared store cache into the local store due to requirelockingbeforewrite.

      This can become an issue for the purge_course_*_cache functions that acquire a lock before get_implementation tries to acquire a lock due to requirelockingbeforewrite, creating a wait on a lock that won't release.

      Case:

      1. User is on a course page
      2. Something happens that changes the coursemodinfo cache version
      3. User tries to change a section name inplace
      4. Service calls a frontend that doesn't have the most current coursemodinfo cache
      5. purge_course_section_cache_by_id acquires a lock before calling $cache->get_versioned
      6. Further in the code get_implementation finds the local cache store doesn't have the correct cache version, deletes it, then checks the next store (the shared store), finds the correct version and tries to set it in the local store
      7. Because requirelockingbeforewrite is set for coursemodinfo it will try to acquire a lock before set_implementation is called
      8. Because of 5. we are now waiting to acquire a lock that we already have
      9. get_lock will eventually timeout and the service call will complete
      10. The user will see the section name has now updated after a long time (depending on the timeout)
      11. Due to the service call taking a long time because of to the cache lock the user cannot do anything else because of the session lock

      Simple fix would be to check the lock state before we try to acquire the lock in 7.

        1. screencast.mp4
          11.64 MB
          Dale Davies
        2. MDL-76865.png
          392 kB
          Ron Carl Alfon Yu

            daviesdale Dale Davies
            rhell4 Rossco Hellmans
            Mark Johnson Mark Johnson
            Ilya Tregubov Ilya Tregubov
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            9 Vote for this issue
            Watchers:
            16 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 2 minutes
                2h 2m

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