Skip to content

Commit bb11b86

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

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

crud/common/call.lua

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
local errors = require('errors')
2+
local log = require('log')
23

34
local call_cache = require('crud.common.call_cache')
45
local dev_checks = require('crud.common.dev_checks')
@@ -19,13 +20,13 @@ local CRUD_CALL_FUNC_NAME = utils.get_storage_call(CALL_FUNC_NAME)
1920

2021
-- Methods that can continue execution in fast mode when rebalance starts
2122
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'),
23+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('readview_open_on_storage')] = true,
24+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('readview_close_on_storage')] = true,
25+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('select_readview_on_storage')] = true,
26+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('truncate_on_storage')] = true,
27+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('len_on_storage')] = true,
28+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('count_on_storage')] = true,
29+
[CRUD_CALL_FUNC_NAME .. '/fast/' .. utils.get_storage_call('get_border_on_storage')] = true,
2930
}
3031

3132
local call = {}
@@ -46,18 +47,12 @@ local function safe_mode_enable()
4647
call_on_storage = call_on_storage_safe
4748

4849
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
50+
local fibers_killed = 0
51+
if fb.name:startswith(CRUD_CALL_FUNC_NAME .. '/fast/') and not safe_mode_allowed_fast_methods[fb.name] then
52+
fiber.kill(fb_id)
53+
fibers_killed = fibers_killed + 1
6054
end
55+
log.debug('Killed %d fibers with fast-mode crud requests.', fibers_killed)
6156
end
6257
end
6358

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)