Skip to content

Commit

Permalink
config: introduce sharding.rebalancer_mode
Browse files Browse the repository at this point in the history
Closes tarantool#9657

@TarantoolBot document
Title: The `sharding.rebalancer_mode` option

The `sharding.rebalancer_mode` option can have one of three values:
`manual`, `auto` and `off`. Default value is `auto`.

If the option is set to `manual`, one of the replicasets must have the
`rebalancer` sharding role. The rebalancer will be in this replicaset.

If the option value is `auto` and there are no replicasets with the
sharding role `rebalancer`, the replicaset with rebalancer will
be selected automatically among all replicasets. If the value of the
parameter is `auto` and one of the replicasets has the sharding role
`rebalancer`, then the rebalancer will be in that replicaset.

If the option value is `off`, rebalancing will be disabled regardless of
whether a replicaset with the sharding role `rebalancer` exists or no
such replicaset exists.
  • Loading branch information
ImeevMA committed Feb 8, 2024
1 parent 60d4576 commit 7c3bd6f
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 0 deletions.
3 changes: 3 additions & 0 deletions changelogs/unreleased/gh-9657-option-rebalancer_mode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## feature/config

* Introduced the `sharding.rebalancer_mode` option (gh-9657).
1 change: 1 addition & 0 deletions src/box/lua/config/configdata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ function methods.sharding(self)
'rebalancer_disbalance_threshold',
'rebalancer_max_receiving',
'rebalancer_max_sending',
'rebalancer_mode',
'sync_timeout',
'connection_outdate_delay',
'failover_ping_timeout',
Expand Down
17 changes: 17 additions & 0 deletions src/box/lua/config/instance_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,23 @@ return schema.new('instance_config', schema.record({
end
end,
}),
rebalancer_mode = schema.enum({
'manual',
'auto',
'off',
}, {
default = 'auto',
validate = function(data, w)
local scope = w.schema.computed.annotations.scope
if data == nil or scope == nil then
return
end
if scope ~= 'global' then
w.error('sharding.rebalancer_enabled must be defined in ' ..
'the global scope.')
end
end,
}),
rebalancer_disbalance_threshold = schema.scalar({
type = 'number',
default = 1,
Expand Down
1 change: 1 addition & 0 deletions test/config-luatest/cluster_config_schema_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ g.test_defaults = function()
rebalancer_disbalance_threshold = 1,
rebalancer_max_receiving = 100,
rebalancer_max_sending = 1,
rebalancer_mode = 'auto',
sched_move_quota = 1,
sched_ref_quota = 300,
shard_index = "bucket_id",
Expand Down
2 changes: 2 additions & 0 deletions test/config-luatest/instance_config_schema_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1590,6 +1590,7 @@ g.test_sharding = function()
rebalancer_disbalance_threshold = 7,
rebalancer_max_receiving = 8,
rebalancer_max_sending = 9,
rebalancer_mode = 'manual',
sched_ref_quota = 10,
sched_move_quota = 11,
},
Expand All @@ -1615,6 +1616,7 @@ g.test_sharding = function()
rebalancer_disbalance_threshold = 1,
rebalancer_max_receiving = 100,
rebalancer_max_sending = 1,
rebalancer_mode = 'auto',
sched_move_quota = 1,
sched_ref_quota = 300,
shard_index = "bucket_id",
Expand Down
52 changes: 52 additions & 0 deletions test/config-luatest/vshard_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -652,3 +652,55 @@ g.test_no_suitable_uri = function(g)
local err = 'No suitable URI provided for instance "instance-001"'
t.assert_str_contains(res.stderr, err)
end

-- Make sure that rebalancing will be disabled if rebalancer_mode == 'off', even
-- if rebalancer sharding role is assigned.
g.test_rebalancer_mode = function(g)
t.skip_if(not has_vshard, 'Module "vshard" is not available')
local dir = treegen.prepare_directory(g, {}, {})
local config = [[
credentials:
users:
guest:
roles: [super]
storage:
roles: [sharding]
password: "storage"
iproto:
listen:
- uri: 'unix/:./{{ instance_name }}.iproto'
advertise:
sharding:
login: 'storage'
sharding:
rebalancer_mode: off
groups:
group-001:
replicasets:
replicaset-001:
sharding:
roles: [storage, rebalancer, router]
instances:
instance-001: {}
]]
local config_file = treegen.write_script(dir, 'config.yaml', config)
local opts = {
env = {LUA_PATH = os.environ()['LUA_PATH']},
config_file = config_file,
chdir = dir,
alias = 'instance-001',
}
g.server = server:new(opts)
g.server:start()

-- Check that vshard option rebalancer_mode is set to the same value.
local res = g.server:eval('return vshard.storage.internal.current_cfg')
t.assert_equals(res.rebalancer_mode, 'off')

-- Check that rebalancer is not started.
res = g.server:eval('return vshard.storage.internal.rebalancer_service')
t.assert_equals(res, nil)
end

0 comments on commit 7c3bd6f

Please sign in to comment.