Skip to content
Snippets Groups Projects
Verified Commit 806d1b10 authored by Petr Špaček's avatar Petr Špaček
Browse files

lua: expose cache miss detection in request objects

It seems there is no reason to keep this function private in policy
module.
parent 452b9d1d
Branches
Tags
1 merge request!957per-request verbose logging and debug log improvements
......@@ -727,6 +727,22 @@ ffi.metatype( kr_query_t, {
local kr_request_t = ffi.typeof('struct kr_request')
ffi.metatype( kr_request_t, {
__index = {
-- makes sense only when request is finished
all_from_cache = function(req)
assert(ffi.istype(kr_request_t, req))
local rplan = ffi.C.kr_resolve_plan(req)
if tonumber(rplan.pending.len) > 0 then
-- an unresolved query,
-- i.e. something is missing from the cache
return false
end
for idx=0, tonumber(rplan.resolved.len) - 1 do
if not rplan.resolved.at[idx].flags.CACHED then
return false
end
end
return true
end,
current = function(req)
assert(ffi.istype(kr_request_t, req))
if req.current_query == nil then return nil end
......
......@@ -579,23 +579,9 @@ function policy.DEBUG_IF(test)
end
end
local function is_request_answered_from_cache(req)
local rplan = ffi.C.kr_resolve_plan(req)
if tonumber(rplan.pending.len) > 0 then
-- an unresolved query, i.e. something is missing from the cache
return false
end
for idx=0, tonumber(rplan.resolved.len) - 1 do
if not rplan.resolved.at[idx].flags.CACHED then
return false
end
end
return true
end
policy.DEBUG_CACHE_MISS = policy.DEBUG_IF(
function(req)
return not is_request_answered_from_cache(req)
return not req:all_from_cache()
end
)
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment