xtco3o opened a new pull request, #3505: URL: https://github.com/apache/kvrocks/pull/3505
References: - SCRIPT KILL: https://redis.io/docs/latest/commands/script-kill/ - EVAL: https://redis.io/docs/latest/commands/eval/ This PR adds support for the lua-time-limit configuration option and the SCRIPT KILL command to interrupt long-running Lua scripts. Changes and Technical Rationale: Lua Hook with JIT Execution - Register LuaMaskCountHook via lua_sethook to check running time every 100,000 instructions. - Pass -DLUAJIT_ENABLE_CHECKHOOK to luajit compilation flags (cmake/luajit.cmake). This allows the LuaJIT VM to check hooks inside compiled machine code without disabling the JIT engine, which preserves execution performance. - Avoid linker crash on macOS Xcode 15/16 by adding -Wl,-no_deduplicate to linker flags when luajit is enabled (CMakeLists.txt). Lock Bypass for SCRIPT KILL - Bypass WorkConcurrencyGuard and WorkExclusivityGuard for SCRIPT KILL and SHUTDOWN (src/server/redis_connection.cc). If these commands required database locks, they would queue behind the blocked script and never execute. Bypassing guards allows SCRIPT KILL to run concurrently on another worker thread to set the is_killed flag. - Intercept incoming commands and return BUSY error if a script is timed out. macOS Listener Socket Sharing - Share the listener socket among worker threads via dup() on macOS instead of binding separate sockets (src/server/worker.cc). On macOS, SO_REUSEPORT routes connections to the worker that bound the socket. If that worker is blocked by a script, new connections queue in the backlog. Sharing the socket allows idle workers to accept connections and process SCRIPT KILL. Lock-Free Fast Path for Timeout Check - Track running scripts in a list in Server (src/server/server.h, src/server/server.cc). - Add running_script_count_ atomic counter. This allows an O(1) lock-free check to bypass timeout evaluations on the command path when no scripts are running. SSL Output Flushing in Event Loop - Implement Worker::PollEventLoop to run the event loop and flush buffers (src/server/worker.cc). - Detect SSL connections using bufferevent_openssl_get_ssl before writing to avoid writing unencrypted bytes to TLS sockets. Tests - Add integration tests for SCRIPT KILL and lua-time-limit (tests/gocase/unit/scripting/scripting_test.go). - Modify test framework directory creation on macOS to handle slashes in test names (tests/gocase/util/server.go). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
