Skip to content

Optimization of Lua Global Locks #2162

@i18nsite

Description

@i18nsite

Search before asking

  • I had searched in the issues and found no similar issues.

Motivation

Kvrocks 是目前开源磁盘 Redis 里面同时支持 Lua 和事务的选型,同时在命令支持上也是比较完善。为了简化实现复杂度,Lua 和事务相关命令执行时会限制为类似 Redis 的单线程执行。实现方式是在 Lua 和事务相关执行命令加上全局锁,代码如下:


我这个感觉其实可以根据redis lua函数的keys来锁定,不需要做全局锁。
为了避免兼容问题,可以加一个配置选项,lua_lock_level = global / keys ,确认可以用键级锁的自己打开


redis 规范: https://redis.io/docs/interact/programmability/eval-intro/

重要提示:为了确保脚本的正确执行,无论是在独立部署还是集群部署中,脚本访问的所有键名称都必须显式提供作为输入键参数。该脚本应该只访问其名称作为输入参数给出的键。脚本永远不应访问具有以编程方式生成的名称或基于数据库中存储的数据结构内容的密钥。


Kvrocks is an open-source disk-based Redis that simultaneously supports Lua scripts and transactions, and is also quite comprehensive in terms of command support. To simplify the complexity of implementation, the execution of Lua scripts and transaction-related commands is restricted to single-threaded execution similar to Redis. The implementation method involves adding a global lock when executing Lua scripts and transaction-related commands.

I think this approach could potentially be modified to lock based on keys rather than a global lock. To avoid compatibility issues, a configuration option could be added, such as lua_lock_level=global / keys, allowing users to enable key-level locking if they confirm it works as expected.

https://redis.io/docs/interact/programmability/eval-intro/

Important: to ensure the correct execution of scripts, both in standalone and clustered deployments, all names of keys that a script accesses must be explicitly provided as input key arguments. The script should only access keys whose names are given as input arguments. Scripts should never access keys with programmatically-generated names or based on the contents of data structures stored in the database.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions