Skip to content

Commit

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

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

The `sharding.weight` option can be set to facilitate rebalancing. The
larger the weight of a replicaset, the more data it can store. This is a
relative value, so a replicaset with a value N times larger than a value
of the another replicaset can store N times more data. The default value
is 1.
  • Loading branch information
ImeevMA committed Mar 7, 2024
1 parent f90f539 commit 4bf3a2f
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelogs/unreleased/gh-9775-option-weight.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## feature/config

* Introduced the `sharding.weight` option (gh-9775).
9 changes: 8 additions & 1 deletion src/box/lua/config/configdata.lua
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ function methods.sharding(self)
for group_name, group in pairs(self._cconfig.groups) do
for replicaset_name, value in pairs(group.replicasets) do
local lock
local weight
-- For replicaset-level options, we need to get them from the any
-- instance of the replicaset.
local is_rs_options_set = false
local replicaset_uuid
local replicaset_cfg = {}
local is_rebalancer = nil
Expand All @@ -160,8 +164,10 @@ function methods.sharding(self)
instance_name)
iconfig = instance_config:apply_default(iconfig)
iconfig = instance_config:apply_vars(iconfig, vars)
if lock == nil then
if not is_rs_options_set then
is_rs_options_set = true
lock = instance_config:get(iconfig, 'sharding.lock')
weight = instance_config:get(iconfig, 'sharding.weight')
end
if is_rebalancer == nil then
local roles = instance_config:get(iconfig, 'sharding.roles')
Expand All @@ -188,6 +194,7 @@ function methods.sharding(self)
uuid = replicaset_uuid,
master = 'auto',
lock = lock,
weight = weight,
}
end
end
Expand Down
14 changes: 14 additions & 0 deletions src/box/lua/config/instance_config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1902,6 +1902,20 @@ return schema.new('instance_config', schema.record({
end
end,
}),
weight = schema.scalar({
type = 'number',
default = 1,
validate = function(data, w)
local scope = w.schema.computed.annotations.scope
if data == nil or scope == nil then
return
end
if scope == 'instance' then
w.error('sharding.weight cannot be defined in the ' ..
'instance scope')
end
end,
}),
-- TODO: Add validate.
roles = schema.set({
'router',
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 @@ -304,6 +304,7 @@ g.test_defaults = function()
sched_ref_quota = 300,
shard_index = "bucket_id",
sync_timeout = 1,
weight = 1,
},
audit_log = is_enterprise and {
file = "var/log/{{ instance_name }}/audit.log",
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 @@ -1583,6 +1583,7 @@ g.test_sharding = function()
roles = {'router', 'storage'},
lock = false,
zone = 1,
weight = 1.5,
sync_timeout = 2,
connection_outdate_delay = 3,
failover_ping_timeout = 4,
Expand Down Expand Up @@ -1623,6 +1624,7 @@ g.test_sharding = function()
sched_ref_quota = 300,
shard_index = "bucket_id",
sync_timeout = 1,
weight = 1,
}
local res = instance_config:apply_default({}).sharding
t.assert_equals(res, exp)
Expand Down
2 changes: 2 additions & 0 deletions test/config-luatest/vars_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ g.test_sharding = helpers.run_as_script(function()
uri = exp_uri('storages', 'storages-a', 'storage-a-003'),
},
},
weight = 1,
},
['storages-b'] = {
master = 'auto',
Expand All @@ -229,6 +230,7 @@ g.test_sharding = helpers.run_as_script(function()
uri = exp_uri('storages', 'storages-b', 'storage-b-003'),
},
},
weight = 1,
},
})
end)
Expand Down
47 changes: 47 additions & 0 deletions test/config-luatest/vshard_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -704,3 +704,50 @@ g.test_rebalancer_mode = function(g)
res = g.server:eval('return vshard.storage.internal.rebalancer_service')
t.assert_equals(res, nil)
end

-- Make sure the shrading.weight configuration parameter is set
-- correctly in vshard.
g.test_weight = 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:
weight: 17
roles: [storage, rebalancer, router]
groups:
group-001:
replicasets:
replicaset-001:
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 weight is set to the same value.
local res = g.server:eval("return vshard.router.static.current_cfg")
t.assert_equals(res.sharding['replicaset-001'].weight, 17)
end

0 comments on commit 4bf3a2f

Please sign in to comment.