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

Change postgres lock implementation to not depend on mdl_lock_db

    XMLWordPrintable

    Details

      Description

      The postgres advisory locks works with an integer, but the moodle lock API works with a string. So the postgres impl re-uses the mdl_lock_db table to manage this mapping:

      https://github.com/moodle/moodle/blob/master/lib/classes/lock/postgres_lock_factory.php#L144-L156

      This impl made some sense back when the number of resource keys was discrete, and essentially limited to just the names of scheduled tasks.

      Now I don't think this makes any sense, there are lots of ad hocs tasks and other clients of the Lock API which are single use (eg objectfs leverages this heaps). In our largest client we have 10's of million rows in mdl_lock_db and it is all junk.

      So I'm proposing to eliminate the db lookup and polling and convert this to a deterministic fast hash, eg something like string -> md5 / sha256 -> truncate to N chars -> convert to integer that fits inside a postgres bigint

      https://www.postgresql.org/docs/current/datatype-numeric.html

      bigint 8 bytes large-range integer -9223372036854775808 to 9223372036854775807

      And an upgrade task to truncate that table as needed

       

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              brendanheywood Brendan Heywood
              Participants:
              Component watchers:
              Andrew Nicols, Mathew May, Michael Hawkins, Shamim Rezaie, Simey Lameze, Matteo Scaramuccia, Jake Dallimore, Jun Pataleta, Ryan Wyllie
            • Votes:
              2 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated: