Skip to content

fix: add mysql user-level lock functions#25019

Open
jiangxinmeng1 wants to merge 7 commits into
matrixorigin:mainfrom
jiangxinmeng1:cherry-pick-pr-24909-main
Open

fix: add mysql user-level lock functions#25019
jiangxinmeng1 wants to merge 7 commits into
matrixorigin:mainfrom
jiangxinmeng1:cherry-pick-pr-24909-main

Conversation

@jiangxinmeng1

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

issue #24728

What this PR does / why we need it:

  • Add MySQL-compatible GET_LOCK, RELEASE_LOCK, and IS_FREE_LOCK built-in functions.
  • Register function IDs, name mappings, and overloads for SQL planning.
  • Implement process-local named user-level lock behavior keyed by connection ID.
  • Add tests for acquire, release, free-state checks, non-owner release, missing locks, and NULL inputs.
  • Add function lookup coverage for the new built-ins.

jiangxinmeng1 and others added 6 commits June 17, 2026 10:57
1. RELEASE_LOCK now returns NULL (via isNull flag) when the named lock
   does not exist or was already released, matching MySQL behavior.
   When local refcount is 0, the code probes the lockservice with
   FastFail to distinguish 'lock does not exist' (NULL) from 'lock
   exists but held by another session' (0).

2. Enforce MySQL-compatible 64-character limit on lock names in
   getUserLevelLock, releaseUserLevelLock, and isUserLevelLockFree.

3. Add tests:
   - RELEASE_LOCK on never-created lock returns NULL
   - RELEASE_LOCK on already-released lock returns NULL
   - RELEASE_LOCK on lock held by another session returns 0
   - Overlong lock names are rejected
   - Exactly-max-length lock names work

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
- Replace validateUserLevelLockName with normalizeUserLevelLockName that
  lowercases names for case-insensitive matching (MySQL requirement).
- Enforce 64-character limit using utf8.RuneCountInString (character
  count), not len() (byte count), matching MySQL's documented behavior.
- Reject empty lock names in GET_LOCK, RELEASE_LOCK, and IS_FREE_LOCK.
- Add tests for empty-name rejection, case-insensitive contention, and
  multibyte character boundary (64/65 Chinese characters).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants