Skip to content

Commit

Permalink
Move rebalancer field on replicaset/instance level
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson committed Feb 9, 2024
1 parent 2ef7f9d commit cf4a5db
Show file tree
Hide file tree
Showing 13 changed files with 259 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Added
- New VShard configuration options: ``rebalancer`` and
``rebalancer_mode``.

- ``rebalancer_enabled`` field to boxinfo GraphQL API.

-------------------------------------------------------------------------------
[2.8.6] - 2024-02-01
-------------------------------------------------------------------------------
Expand Down
4 changes: 3 additions & 1 deletion cartridge/lua-api/boxinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ local function get_info(uri)
local rs_uuid = box_info.cluster.uuid
local vshard_group = topology_cfg.replicasets[rs_uuid].vshard_group or 'default'
local ok, storage_info = pcall(vshard and vshard.storage.info)

local rebalancer_enabled = vshard and vshard.storage and
vshard.storage.internal.rebalancer_fiber ~= nil
if ok then
storage_info = {
vshard_group = vshard_group,
Expand All @@ -89,6 +90,7 @@ local function get_info(uri)
buckets_garbage = storage_info.bucket.garbage,
buckets_pinned = storage_info.bucket.pinned,
buckets_sending = storage_info.bucket.sending,
rebalancer_enabled = rebalancer_enabled,
}
else
storage_info = box.NULL
Expand Down
6 changes: 6 additions & 0 deletions cartridge/lua-api/edit-topology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ local function __join_server(topology_cfg, params)
uuid = 'string',
zone = '?string',
labels = '?table',
rebalancer = '?boolean',
replicaset_uuid = 'string',
})

Expand Down Expand Up @@ -59,6 +60,7 @@ local function __join_server(topology_cfg, params)
labels = params.labels,
disabled = false,
electable = true,
rebalancer = params.rebalancer,
replicaset_uuid = params.replicaset_uuid,
}

Expand All @@ -74,6 +76,7 @@ local function __edit_server(topology_cfg, params)
labels = '?table',
disabled = '?boolean',
electable = '?boolean',
rebalancer = '?boolean',
expelled = '?boolean',
})

Expand Down Expand Up @@ -122,6 +125,7 @@ local function __edit_replicaset(topology_cfg, params)
all_rw = '?boolean',
roles = '?table',
weight = '?number',
rebalancer = '?boolean',
failover_priority = '?table',
vshard_group = '?string',
join_servers = '?table',
Expand Down Expand Up @@ -254,6 +258,7 @@ end
-- @tfield ?{string,...} roles
-- @tfield ?boolean all_rw
-- @tfield ?number weight
-- @tfield ?boolean rebalancer
-- @tfield ?{string,...} failover_priority
-- array of uuids specifying servers failover priority
-- @tfield ?string vshard_group
Expand All @@ -276,6 +281,7 @@ end
-- @tfield ?table labels
-- @tfield ?boolean disabled
-- @tfield ?boolean electable
-- @tfield ?boolean rebalancer
-- @tfield ?boolean expelled
-- Expelling an instance is permanent and can't be undone.
-- It's suitable for situations when the hardware is destroyed,
Expand Down
5 changes: 5 additions & 0 deletions cartridge/lua-api/get-topology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ local lua_api_proxy = require('cartridge.lua-api.proxy')
-- @tfield number weight
-- Vshard replicaset weight.
-- Matters only if vshard-storage role is enabled.
-- @tfield boolean rebalancer
-- Is rebalancer enabled on this replicaset.
-- Matters only if vshard-storage role is enabled.
-- @tfield string vshard_group
-- Name of vshard group the replicaset belongs to.
-- @tfield boolean all_rw
Expand All @@ -45,6 +48,7 @@ local lua_api_proxy = require('cartridge.lua-api.proxy')
-- @tfield string uuid
-- @tfield boolean disabled
-- @tfield boolean electable
-- @tfield boolean rebalancer
-- @tfield string status
-- Instance health.
-- @tfield string message
Expand Down Expand Up @@ -152,6 +156,7 @@ local function get_topology()
disabled = not topology.not_disabled(instance_uuid, server),
electable = topology.electable(instance_uuid, server),
zone = server.zone,
rebalancer = server.rebalancer,
alias = nil,
status = nil,
message = nil,
Expand Down
1 change: 1 addition & 0 deletions cartridge/roles/vshard-storage.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ local function apply_config(conf, opts)
end

log.info('Reconfiguring vshard.storage...')
log.info(vshard_cfg)
vshard.storage.cfg(vshard_cfg, vars.instance_uuid)
vars.vshard_cfg = vshard_cfg
end
Expand Down
3 changes: 3 additions & 0 deletions cartridge/test-helpers/cluster.lua
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ function Cluster:new(object)
-- @tparam {string} roles List of roles for servers in the replicaset.
-- @tparam ?string vshard_group Name of vshard group.
-- @tparam ?number weight Vshard group weight.
-- @tparam ?boolean rebalancer Is rebalancer enabled.
-- @tparam ?boolean all_rw Make all replicas writable.
-- @tparam table|number servers List of objects to build `Server`s with or
-- number of servers in replicaset.
Expand All @@ -76,6 +77,7 @@ function Cluster:new(object)
roles = 'table',
vshard_group = '?string',
weight = '?number',
rebalancer = '?boolean',
servers = 'table|number',
all_rw = '?boolean',
}) end)(replicaset)
Expand Down Expand Up @@ -205,6 +207,7 @@ function Cluster:apply_topology()
uuid = server.instance_uuid,
labels = server.labels,
zone = server.zone,
rebalancer = server.rebalancer,
})
end

Expand Down
5 changes: 5 additions & 0 deletions cartridge/test-helpers/server.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ local checks = require('checks')
-- @string[opt] object.instance_uuid Server identifier.
-- @string[opt] object.replicaset_uuid Replicaset identifier.
-- @string[opt] object.zone Vshard zone.
-- @bool[opt] object.rebalancer Is vshard rebalancer enabled.
-- @number[opt] object.swim_period SWIM protocol period in seconds.
-- @return input object
local Server = luatest.Server:inherit({})
Expand All @@ -42,6 +43,7 @@ Server.constructor_checks = fun.chain(Server.constructor_checks, {
labels = '?table',
zone = '?string',
swim_period = '?number',
rebalancer = '?boolean',

transport = '?string',
ssl_ciphers = '?string',
Expand Down Expand Up @@ -294,6 +296,7 @@ function Server:setup_replicaset(config)
$roles: [String!],
$master: [String!],
$weight: Float,
$rebalancer: Boolean,
$vshard_group: String
) {
edit_replicaset(
Expand All @@ -302,6 +305,7 @@ function Server:setup_replicaset(config)
roles: $roles,
master: $master,
weight: $weight,
rebalancer: $rebalancer,
vshard_group: $vshard_group
)
}
Expand All @@ -312,6 +316,7 @@ function Server:setup_replicaset(config)
roles = config.roles,
master = config.master,
weight = config.weight,
rebalancer = config.rebalancer,
vshard_group = config.vshard_group,
}
})
Expand Down
15 changes: 15 additions & 0 deletions cartridge/topology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ local e_config = errors.new_class('Invalid cluster topology config')
-- electable = true,
-- replicaset_uuid = 'replicaset-uuid-2',
-- zone = nil | string,
-- rebalancer = nil | true,
-- },
},
replicasets = {
Expand All @@ -60,6 +61,7 @@ local e_config = errors.new_class('Invalid cluster topology config')
-- master = {'instance-uuid-2', 'instance-uuid-1'} -- new format
-- weight = 1.0,
-- vshard_group = 'group_name',
-- rebalancer = nil | true,
-- }
},
}]]
Expand Down Expand Up @@ -258,6 +260,12 @@ local function validate_schema(field, topology)
'%s.zone must be a string, got %s', field, type(server.zone)
)

e_config:assert(
server.rebalancer == nil or
type(server.rebalancer) == 'boolean',
'%s.rebalancer must be a string, got %s', field, type(server.rebalancer)
)

if rawget(_G, '__cartridge_log_invalid_labels') == true then
local ok, err = label_utils.validate_labels(field, server)
if not ok then
Expand All @@ -270,6 +278,7 @@ local function validate_schema(field, topology)
['disabled'] = true,
['electable'] = true,
['replicaset_uuid'] = true,
['rebalancer'] = true,
['labels'] = true,
['zone'] = true,
}
Expand Down Expand Up @@ -345,6 +354,11 @@ local function validate_schema(field, topology)
'%s.vshard_group must be a string, got %s', field, type(replicaset.vshard_group)
)

e_config:assert(
(replicaset.rebalancer == nil) or (type(replicaset.rebalancer) == 'boolean'),
'%s.rebalancer must be a boolean, got %s', field, type(replicaset.rebalancer)
)

for k, v in pairs(replicaset.roles) do
e_config:assert(
type(k) == 'string',
Expand All @@ -368,6 +382,7 @@ local function validate_schema(field, topology)
['roles'] = true,
['master'] = true,
['weight'] = true,
['rebalancer'] = true,
['vshard_group'] = true,
['all_rw'] = true,
['alias'] = true,
Expand Down
18 changes: 2 additions & 16 deletions cartridge/vshard-utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ vars:new('known_groups', nil
-- rebalancer_disbalance_threshold = number,
-- sched_ref_quota = number,
-- sched_move_quota = number,
-- rebalancer = boolean,
-- rebalancer_mode = string,
-- }
--}
Expand Down Expand Up @@ -231,13 +230,6 @@ local function validate_vshard_group(field, vsgroup_new, vsgroup_old)
)
end

if vsgroup_new.rebalancer ~= nil then
ValidateConfigError:assert(
type(vsgroup_new.rebalancer) == 'boolean',
'%s.rebalancer must be a boolean', field
)
end

if vsgroup_new.rebalancer_mode ~= nil then
ValidateConfigError:assert(
type(vsgroup_new.rebalancer_mode) == 'string'
Expand Down Expand Up @@ -289,7 +281,6 @@ local function validate_vshard_group(field, vsgroup_new, vsgroup_old)
['sync_timeout'] = true,
['collect_bucket_garbage_interval'] = true,
['rebalancer_disbalance_threshold'] = true,
['rebalancer'] = true,
['rebalancer_mode'] = true,
['sched_ref_quota'] = true,
['sched_move_quota'] = true,
Expand Down Expand Up @@ -462,11 +453,6 @@ local function get_known_groups()
g.rebalancer_disbalance_threshold = vshard_consts.DEFAULT_REBALANCER_DISBALANCE_THRESHOLD
end

-- just for the code consistancy
if g.rebalancer == nil then
g.rebalancer = nil
end

if g.rebalancer_mode == nil then
g.rebalancer_mode = 'auto'
end
Expand Down Expand Up @@ -507,6 +493,7 @@ local function get_vshard_config(group_name, conf)
sharding[replicaset_uuid] = {
replicas = {},
weight = replicaset.weight or 0.0,
rebalancer = replicaset.rebalancer ~= nil and replicaset.rebalancer or nil,
}
end

Expand Down Expand Up @@ -544,6 +531,7 @@ local function get_vshard_config(group_name, conf)
name = server.uri,
zone = server.zone,
listen = listen_uri,
rebalancer = server.rebalancer ~= nil and server.rebalancer or nil,
uri = client_uri,
master = (active_leaders[replicaset_uuid] == instance_uuid),
}
Expand Down Expand Up @@ -588,7 +576,6 @@ local function get_vshard_config(group_name, conf)
sync_timeout = vshard_groups[group_name].sync_timeout,
collect_bucket_garbage_interval = vshard_groups[group_name].collect_bucket_garbage_interval,
rebalancer_disbalance_threshold = vshard_groups[group_name].rebalancer_disbalance_threshold,
rebalancer = vshard_groups[group_name].rebalancer,
rebalancer_mode = vshard_groups[group_name].rebalancer_mode,
sharding = sharding,
read_only = not failover.is_rw(),
Expand Down Expand Up @@ -649,7 +636,6 @@ local function edit_vshard_options(group_name, vshard_options)
sync_timeout = '?number',
collect_bucket_garbage_interval = '?number',
rebalancer_disbalance_threshold = '?number',
rebalancer = '?boolean',
rebalancer_mode = '?string',
sched_ref_quota = '?number',
sched_move_quota = '?number',
Expand Down
11 changes: 11 additions & 0 deletions cartridge/webui/api-topology.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ local gql_type_replicaset = gql_types.object {
description = 'Vshard replica set weight.' ..
' Null for replica sets with vshard-storage role disabled.'
},
rebalancer = {
kind = gql_types.boolean,
description = 'Is the rebalancer enabled for the replica set.',
},
vshard_group = {
kind = gql_types.string,
description = 'Vshard storage group name.' ..
Expand Down Expand Up @@ -91,6 +95,10 @@ local gql_type_server = gql_types.object {
kind = gql_types.boolean,
description = 'Is allowed to elect this instance as leader',
},
rebalancer = {
kind = gql_types.boolean,
description = 'Is rebalancer enabled for this instance',
},
disabled = gql_types.boolean,
priority = {
kind = gql_types.int,
Expand Down Expand Up @@ -120,6 +128,7 @@ local gql_type_edit_server_input = gql_types.inputObject {
zone = gql_types.string,
labels = gql_types.list(gql_type_label_input),
electable = gql_types.boolean,
rebalancer = gql_types.boolean,
disabled = gql_types.boolean,
expelled = gql_types.boolean,
}
Expand All @@ -140,13 +149,15 @@ local gql_type_edit_replicaset_input = gql_types.inputObject {
uri = gql_types.string.nonNull,
uuid = gql_types.string,
zone = gql_types.string,
rebalancer = gql_types.boolean,
labels = gql_types.list(gql_type_label_input),
}
})
),
failover_priority = gql_types.list(gql_types.string.nonNull),
all_rw = gql_types.boolean,
weight = gql_types.float,
rebalancer = gql_types.boolean,
vshard_group = gql_types.string,
}
}
Expand Down
5 changes: 0 additions & 5 deletions cartridge/webui/api-vshard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ local gql_type_vsgroup = gql_types.object({
kind = gql_types.float.nonNull,
description = 'A maximum bucket disbalance threshold, in percent'
},
rebalancer = {
kind = gql_types.boolean,
description = 'Run rebalancer on a specific replicaset'
},
rebalancer_mode = {
kind = gql_types.string.nonNull,
description = 'Rebalancer mode'
Expand Down Expand Up @@ -179,7 +175,6 @@ local function init(graphql)
sync_timeout = gql_types.float,
collect_bucket_garbage_interval = gql_types.float,
rebalancer_disbalance_threshold = gql_types.float,
rebalancer = gql_types.boolean,
rebalancer_mode = gql_types.string,
sched_ref_quota = gql_types.long,
sched_move_quota = gql_types.long,
Expand Down
4 changes: 4 additions & 0 deletions cartridge/webui/gql-boxinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ local boxinfo_schema = {
kind = gql_types.int,
description = 'The number of buckets that are sending at this time',
},
rebalancer_enabled = {
kind = gql_types.boolean,
description = 'Whether the rebalancer is enabled',
}
}
}),
}
Expand Down
Loading

0 comments on commit cf4a5db

Please sign in to comment.