Is lua script atomic execution guaranteed? #3489
-
|
Hey team, I have wondered about the behavior of Lua script in term of atomic execution. In Redis database, atomic execution is assured by nature because Redis is the single-threaded engine. While KVRocks does not employ the single-threaded model, is the atomic execution guaranteed? P/s: By saying atomic operation, I mean there is no interleaving during script execution. Meaning that, all check-then-act operations in Lua script do not undergo race condition. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
|
Yes, it can be guaranteed. By default, write scripts are made atomic by a global exclusivity lock (EVAL/FCALL are exclusive when lua-strict-key-accessing=no) cc @git-hulk Please confirm that my understanding is accurate. |
Beta Was this translation helpful? Give feedback.
-
|
When For both scenarios, atomic is guaranteed. |
Beta Was this translation helpful? Give feedback.
When
lua-strict-key-accessingisno, a global lock is enabled for all EVAL/FCALL commands (slower);and when
lua-strict-key-accessingisyes, EVAL/FCALL commands will be controlled by fine-grained key locks (faster).For both scenarios, atomic is guaranteed.