Skip to content

Commit af43c2e

Browse files
zloidemonLeonidVas
authored andcommitted
add callbacks on full scan iteration stages
Added callbacks for a task at various stages of the full scan iteration. `on_full_scan_start` - call function on starting full scan iteration. `on_full_scan_complete` - call function on complete full scan iteration. `on_full_scan_success` - call function on success full scan iteration. `on_full_scan_error` - call function on error full scan iteration. Closes #25
1 parent e20a89d commit af43c2e

File tree

2 files changed

+60
-2
lines changed

2 files changed

+60
-2
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ opt
4646
* `full_scan_time` - time required for full index scan (in seconds)
4747
* `iteration_delay` - max sleep time between iterations (in seconds)
4848
* `full_scan_delay` - sleep time between full scans (in seconds)
49+
* `on_full_scan_start` - call function on starting full scan iteration
50+
Receives `(task)` as arguments.
51+
* `on_full_scan_complete` - call function on complete full scan iteration.
52+
Called after `on_full_scan_success` or `on_full_scan_error`.
53+
Receives `(task)` as arguments.
54+
* `on_full_scan_success` - call function on success full scan iteration
55+
Receives `(task)` as arguments.
56+
* `on_full_scan_error` - call function on error full scan iteration
57+
Receives `(task, error)` as arguments.
4958
* `force` - run, even on replica
5059

5160
### `expirationd.kill (name)`

expirationd.lua

+51-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ local constants = {
4343
-- assumed size of vinyl space (in the first iteration)
4444
default_vinyl_assumed_space_len = math.pow(10, 7),
4545
-- factor for recalculation of vinyl space size
46-
default_vinyl_assumed_space_len_factor = 2
46+
default_vinyl_assumed_space_len_factor = 2,
47+
-- default function on full scan
48+
default_on_full_scan = function(...) end
4749
}
4850

4951
-- ========================================================================= --
@@ -160,7 +162,18 @@ local function worker_loop(task)
160162

161163
while true do
162164
if (box.cfg.replication_source == nil and box.cfg.replication == nil) or task.force then
163-
task.do_worker_iteration(task)
165+
task.on_full_scan_start(task)
166+
local state, err = pcall(task.do_worker_iteration, task)
167+
if state then
168+
task.on_full_scan_success(task)
169+
else
170+
task.on_full_scan_error(task, err)
171+
end
172+
173+
task.on_full_scan_complete(task)
174+
if not state then
175+
error(err)
176+
end
164177
end
165178

166179
-- Full scan iteration is complete, yield
@@ -253,6 +266,10 @@ local function create_task(name)
253266
full_scan_time = constants.default_full_scan_time,
254267
vinyl_assumed_space_len = constants.default_vinyl_assumed_space_len,
255268
vinyl_assumed_space_len_factor = constants.default_vinyl_assumed_space_len_factor,
269+
on_full_scan_error = constants.default_on_full_scan,
270+
on_full_scan_success = constants.default_on_full_scan,
271+
on_full_scan_start = constants.default_on_full_scan,
272+
on_full_scan_complete = constants.default_on_full_scan
256273
}, { __index = Task_methods })
257274
return task
258275
end
@@ -291,6 +308,10 @@ end
291308
-- options = { -- (table with named options)
292309
-- * process_expired_tuple -- applied to expired tuples, receives
293310
-- (space_id, args, tuple) as arguments
311+
-- * on_full_scan_start -- call function on starting full scan iteration
312+
-- * on_full_scan_complete -- call function on complete full scan iteration
313+
-- * on_full_scan_success -- call function on success full scan iteration
314+
-- * on_full_scan_error -- call function on error full scan iteration
294315
-- * args -- passed to is_tuple_expired and
295316
-- process_expired_tuple() as additional context
296317
-- * tuples_per_iteration -- number of tuples will be checked by one iteration
@@ -398,6 +419,34 @@ local function expirationd_run_task(name, space_id, is_tuple_expired, options)
398419
task.full_scan_delay = options.full_scan_delay
399420
end
400421

422+
if options.on_full_scan_start ~= nil then
423+
if type(options.on_full_scan_start) ~= 'function' then
424+
error("invalid type of on_full_scan_start is not function")
425+
end
426+
task.on_full_scan_start = options.on_full_scan_start
427+
end
428+
429+
if options.on_full_scan_success ~= nil then
430+
if type(options.on_full_scan_success) ~= 'function' then
431+
error("invalid type of on_full_scan_success is not function")
432+
end
433+
task.on_full_scan_success = options.on_full_scan_success
434+
end
435+
436+
if options.on_full_scan_complete ~= nil then
437+
if type(options.on_full_scan_complete) ~= 'function' then
438+
error("invalid type of on_full_scan_complete is not function")
439+
end
440+
task.on_full_scan_complete = options.on_full_scan_complete
441+
end
442+
443+
if options.on_full_scan_error ~= nil then
444+
if type(options.on_full_scan_error) ~= 'function' then
445+
error("invalid type of on_full_scan_error is not function")
446+
end
447+
task.on_full_scan_error = options.on_full_scan_error
448+
end
449+
401450
-- put the task to table
402451
task_list[name] = task
403452
-- run

0 commit comments

Comments
 (0)