Skip to content
Snippets Groups Projects
Commit 6fa6e212 authored by Vladimir Davydov's avatar Vladimir Davydov Committed by Vladimir Davydov
Browse files

lua/fiber: add compat option for default slice

The new compat option 'fiber_slice_default' is added to control
the default value of the max fiber slice. The old default is no limit
(both warning and error slice equals TIMEOUT_INFINITY). The new default
is {warn = 0.5, err = 1.0}.

Follow-up #6085

NO_DOC=tarantool/doc#3057
NO_CHANGELOG=unreleased
parent 448c3a05
No related branches found
No related tags found
No related merge requests found
## feature/core
* **[Breaking change]** Introduced the mechanism for catching fibers running
without yielding for too long. Now box operations, such as `select` and
`replace`, will throw an error if the fiber execution time since yield
exceeds the limit. The limit can also be checked from the application code
with `fiber.check_slice()`. The default limit is one second; you can
overwrite it with `fiber.set_slice()` (gh-6085).
----
Breaking change: long-running non-yielding fibers can be interrupted because of
the fiber execution time slice limit.
* Introduced the mechanism for catching fibers running without yielding for too
long. Now box operations, such as `select` and `replace`, will throw an error
if the fiber execution time since yield exceeds the limit. The limit can also
be checked from the application code with `fiber.check_slice()`. The default
limit is controlled by the new `compat` option `fiber_slice_default`. The old
default is no limit. The new default is one second. You can overwrite it with
`fiber.set_slice()` (gh-6085).
-- fiber.lua (internal file)
local compat = require('compat')
local fiber = require('fiber')
local ffi = require('ffi')
ffi.cdef[[
......@@ -14,6 +15,34 @@ fiber_clock64(void);
]]
local C = ffi.C
local TIMEOUT_INFINITY = 100 * 365 * 86400
local FIBER_SLICE_DEFAULT_BRIEF = [[
Sets the default value for the max fiber slice. The old value is infinity
(no warnings or errors). The new value is {warn = 0.5, err = 1.0}.
https://tarantool.io/compat/fiber_slice_default
]]
compat.add_option({
name = 'fiber_slice_default',
default = 'old',
obsolete = nil,
brief = FIBER_SLICE_DEFAULT_BRIEF,
action = function(is_new)
local slice = {}
if is_new then
slice.warn = 0.5
slice.err = 1.0
else
slice.warn = TIMEOUT_INFINITY
slice.err = TIMEOUT_INFINITY
end
fiber.set_max_slice(slice)
end,
run_action_now = true,
})
local function fiber_time()
return tonumber(C.fiber_time())
end
......
......@@ -171,3 +171,26 @@ g.test_info = function()
check_default(slice, info)
end
end
g.before_test('test_compat', function()
g.server = server:new({alias = 'default'})
g.server:start()
end)
g.after_test('test_compat', function()
g.server:drop()
end)
g.test_compat = function()
g.server:exec(function()
local compat = require('compat')
local fiber = require('fiber')
t.assert_equals(compat.fiber_slice_default.current, 'default')
t.assert_equals(compat.fiber_slice_default.default, 'old')
t.assert_equals(fiber.self():info().max_slice, nil)
compat.fiber_slice_default = 'new'
t.assert_equals(fiber.self():info().max_slice, {warn = 0.5, err = 1.0})
compat.fiber_slice_default = 'old'
t.assert_equals(fiber.self():info().max_slice, nil)
end)
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment