Skip to content

Commit

Permalink
improve readability: rename err to lock_err
Browse files Browse the repository at this point in the history
  • Loading branch information
chobits committed Mar 21, 2024
1 parent 689d37b commit f8e8962
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions kong/resty/mlcache/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -826,14 +826,15 @@ function _M:renew(key, opts, cb, ...)

local version_before = get_version(shmerr or 0)

local lock, err = resty_lock:new(self.shm_locks, self.resty_lock_opts)
local lock, lock_err = resty_lock:new(self.shm_locks, self.resty_lock_opts)
if not lock then
return nil, "could not create lock: " .. err
return nil, "could not create lock: " .. lock_err
end

local elapsed, err = lock:lock(LOCK_KEY_PREFIX .. namespaced_key)
if not elapsed and err ~= "timeout" then
return nil, "could not acquire callback lock: " .. err
local elapsed
elapsed, lock_err = lock:lock(LOCK_KEY_PREFIX .. namespaced_key)
if not elapsed and lock_err ~= "timeout" then
return nil, "could not acquire callback lock: " .. lock_err
end

local is_hit
Expand All @@ -847,11 +848,11 @@ function _M:renew(key, opts, cb, ...)
if shmerr then
-- shmerr can be 'flags' upon successful get_stale() calls, so we
-- also check v == nil
if not err then
if not lock_err then
return unlock_and_ret(lock, nil,
"could not read from lua_shared_dict: " .. shmerr)
end
return nil, "could not acquire callback lock: " .. err
return nil, "could not acquire callback lock: " .. lock_err
end

-- if we specified shm_miss, it might be a negative hit cached
Expand All @@ -864,11 +865,11 @@ function _M:renew(key, opts, cb, ...)
elseif shmerr then
-- shmerr can be 'flags' upon successful get_stale() calls, so we
-- also check v == nil
if not err then
if not lock_err then
return unlock_and_ret(lock, nil,
"could not read from lua_shared_dict (miss): " .. shmerr)
end
return nil, "could not acquire callback lock: " .. err
return nil, "could not acquire callback lock: " .. lock_err
end
end
end
Expand All @@ -889,20 +890,19 @@ function _M:renew(key, opts, cb, ...)

if ttl_left then
v = decode(v)
if not err then
if not lock_err then
return unlock_and_ret(lock, v, nil, ttl_left)
end
return v, nil, ttl_left
end
end
end

if err == "timeout" then
if lock_err == "timeout" then
return nil, "could not acquire callback lock: timeout"
end

local ok, data, new_ttl
ok, data, err, new_ttl = xpcall(cb, traceback, ...)
local ok, data, err, new_ttl = xpcall(cb, traceback, ...)
if not ok then
return unlock_and_ret(lock, nil, "callback threw an error: " .. tostring(data))
end
Expand Down

0 comments on commit f8e8962

Please sign in to comment.