Skip to content

Commit 4a8e4d2

Browse files
committed
Minor changes according to review comments
1 parent a8352f2 commit 4a8e4d2

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

crud/common/call.lua

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,13 @@ local CRUD_CALL_FUNC_NAME = utils.get_storage_call(CALL_FUNC_NAME)
1919

2020
-- Methods that can continue execution in fast mode when rebalance starts
2121
local safe_mode_allowed_fast_methods = {
22-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('readview_open_on_storage'),
23-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('readview_close_on_storage'),
24-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('select_readview_on_storage'),
25-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('truncate_on_storage'),
26-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('len_on_storage'),
27-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('count_on_storage'),
28-
CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('get_border_on_storage'),
22+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('readview_open_on_storage')] = true,
23+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('readview_close_on_storage')] = true,
24+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('select_readview_on_storage')] = true,
25+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('truncate_on_storage')] = true,
26+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('len_on_storage')] = true,
27+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('count_on_storage')] = true,
28+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('get_border_on_storage')] = true,
2929
}
3030

3131
local call = {}
@@ -46,17 +46,8 @@ local function safe_mode_enable()
4646
call_on_storage = call_on_storage_safe
4747

4848
for fb_id, fb in pairs(fiber.info()) do
49-
if string.find(fb.name, CRUD_CALL_FUNC_NAME .. '/fast/') then
50-
local do_kill = true
51-
for _, allowed_method in ipairs(safe_mode_allowed_fast_methods) do
52-
if fb.name == allowed_method then
53-
do_kill = false
54-
break
55-
end
56-
end
57-
if do_kill then
58-
fiber.kill(fb_id)
59-
end
49+
if fb.name:startswith(CRUD_CALL_FUNC_NAME .. '/fast/') and not safe_mode_allowed_fast_methods[fb.name] then
50+
fiber.kill(fb_id)
6051
end
6152
end
6253
end

crud/common/rebalance.lua

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ local function safe_mode_trigger(_, new, space, op)
3131
if space ~= '_bucket' then
3232
return
3333
end
34+
-- We are interested only in two operations that indicate the beginning of bucket migration:
35+
-- * We are receiving a bucket (new bucket with status RECEIVING)
36+
-- * We are sending a bucket to another node (existing bucket status changes to SENDING)
3437
if (op == 'INSERT' and new.status == vshard_consts.BUCKET.RECEIVING) or
3538
(op == 'REPLACE' and new.status == vshard_consts.BUCKET.SENDING) then
3639
box.broadcast(SAFE_MOD_ENABLE_EVENT, true)
@@ -60,6 +63,8 @@ end
6063
local function safe_mode_enable()
6164
if not box.info.ro then
6265
box.space[SETTINGS_SPACE_NAME]:replace{ 'safe_mode', true }
66+
-- The trigger is needed to detect the beginning of rebalance process to enable safe mode.
67+
-- If safe mode is enabled we don't need the trigger anymore.
6368
for _, trig in pairs(box.space._bucket:on_replace()) do
6469
if trig == safe_mode_trigger then
6570
box.space._bucket:on_replace(nil, safe_mode_trigger)
@@ -78,6 +83,8 @@ end
7883
local function safe_mode_disable()
7984
if not box.info.ro then
8085
box.space[SETTINGS_SPACE_NAME]:replace{ 'safe_mode', false }
86+
-- We have disabled safe mode so we need to add the trigger to detect the beginning
87+
-- of rebalance process to enable safe mode again.
8188
box.space._bucket:on_replace(safe_mode_trigger)
8289
end
8390
M.safe_mode = false

0 commit comments

Comments
 (0)