Skip to content

Commit

Permalink
add yielding
Browse files Browse the repository at this point in the history
  • Loading branch information
dndx committed Nov 15, 2023
1 parent 45767b3 commit b9c9aae
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/resty/lmdb.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@ local status = require("resty.lmdb.status")

local assert = assert
local prefix_page = prefix.page
local get_phase = ngx.get_phase
local ngx_sleep = ngx.sleep


local CACHED_TXN = transaction.begin(1)
local CAN_YIELD_PHASES = {
["rewrite"] = true,
["access"] = true,
["content"] = true,
["timer"] = true,
["ssl_cert"] = true,
["ssl_session_store"] = true,
["ssl_session_fetch"] = true,
}


function _M.get(key, db)
Expand Down Expand Up @@ -54,6 +65,7 @@ end
function _M.prefix(prefix, db)
local res, i, res_n, err_or_more
local last = prefix
local can_yield = CAN_YIELD_PHASES[get_phase()]

return function()
::more::
Expand Down Expand Up @@ -92,6 +104,11 @@ function _M.prefix(prefix, db)
if err_or_more then
last = res[i - 1].key
res = nil

if can_yield then
ngx_sleep(0)
end

goto more
end

Expand Down

0 comments on commit b9c9aae

Please sign in to comment.