Skip to content

MySQL get_lock is no longer limited to one lock per session #4

@vickenty

Description

@vickenty

Default query for MySQL uses get_lock function in the WHERE clause to find rows that are not locked by any other process and to lock one of them at the same time. E.g.:

select ... where flag=0 and get_lock(concat_ws('=', 'prefix', id))!=0

It relies on the fact that a database session is only allowed to hold one lock at a time, and get_lock is automatically releasing any previously held locks. This behaviour ensures that after this query is executed, worker has a row that isn't locked by anyone else and it has only one row locked.

This no longer works correctly under MySQL 5.7, which removed one-lock-per-session limitation. Now worker can end up locking as much as all rows in a table, preventing all other workers from claiming any items in the queue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions