glacier-ng 4.0.0
This commit is contained in:
commit
0cf4829fa5
159 files changed
+33717
No files matched your search
@@ -0,0 +1,59 @@
|
||||
-- test_lock_crash_recovery.lua
|
||||
--
|
||||
-- This is the actual regression test for the O_EXCL fix. The old
|
||||
-- gl_begin_transaction used open(O_CREAT|O_EXCL), so a crashed holder
|
||||
-- left a lock file on disk that permanently blocked every future
|
||||
-- transaction for that uid/scope until someone manually rm'd it. The
|
||||
-- fix relies on flock() being tied to the open file description, which
|
||||
-- the kernel releases automatically when the holding process dies —
|
||||
-- including via SIGKILL, which gives the process no chance to run any
|
||||
-- cleanup code at all.
|
||||
--
|
||||
-- fork() duplicates the whole LuaJIT VM. To keep this safe, the child
|
||||
-- does the absolute minimum (one FFI call, then _exit) and touches no
|
||||
-- further Lua state before exiting.
|
||||
|
||||
local glacier = require("glacier_ffi")
|
||||
local h = require("test_helpers")
|
||||
local ffi = glacier.ffi
|
||||
|
||||
h.reset_glacier_root()
|
||||
|
||||
local uid = 1000
|
||||
io.write("== test_lock_crash_recovery (uid " .. uid .. ") ==\n")
|
||||
|
||||
glacier.lib.gl_init_user(uid, false)
|
||||
|
||||
local child = glacier.C.fork()
|
||||
if child == 0 then
|
||||
-- CHILD: acquire the lock, then simulate a wedged/crashed
|
||||
-- process by sleeping. No cleanup, no unlock — the parent will
|
||||
-- SIGKILL this before it ever gets a chance to.
|
||||
local ctx = glacier.new_context()
|
||||
local st = glacier.lib.gl_init_stage_context(ctx, glacier.SCOPE_USR, uid)
|
||||
if tonumber(st) ~= 0 then
|
||||
glacier.C._exit(1)
|
||||
end
|
||||
glacier.C.sleep(30)
|
||||
glacier.C._exit(0)
|
||||
end
|
||||
|
||||
-- PARENT: give the child a moment to actually acquire the lock before
|
||||
-- killing it.
|
||||
glacier.C.sleep(1)
|
||||
|
||||
glacier.C.kill(child, 9) -- SIGKILL — no handlers, no cleanup, ever
|
||||
local status = ffi.new("int[1]")
|
||||
glacier.C.waitpid(child, status, 0)
|
||||
|
||||
local ctx2 = glacier.new_context()
|
||||
local st2 = glacier.lib.gl_init_stage_context(ctx2, glacier.SCOPE_USR, uid)
|
||||
h.check(tonumber(st2) == 0,
|
||||
"stage context acquired immediately after the holder was SIGKILLed: " ..
|
||||
glacier.txn_name(st2))
|
||||
|
||||
if tonumber(st2) == 0 then
|
||||
glacier.lib.gl_abort_transaction(ctx2)
|
||||
end
|
||||
|
||||
h.summary()
|
||||
Reference in new issue
Block a user