Skip to content

Commit

Permalink
router: introduce name identification
Browse files Browse the repository at this point in the history
This commit allows router to use named config identification.

Part of #426

NO_DOC=<no API changed>
  • Loading branch information
Serpentian authored and Gerold103 committed Dec 19, 2023
1 parent 6b4a77c commit 515506f
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
43 changes: 43 additions & 0 deletions test/router-luatest/router_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,46 @@ g.test_router_box_cfg_mode = function(g)
vtest.router_cfg(g.router, global_cfg)
t.assert(g.router:grep_log('Calling box.cfg()'))
end

g.test_named_config_identification = function(g)
t.run_only_if(vutil.feature.persistent_names)
local new_cfg_template = table.deepcopy(cfg_template)
new_cfg_template.identification_mode = 'name_as_key'
new_cfg_template.sharding['replicaset_1'] = new_cfg_template.sharding[1]
new_cfg_template.sharding['replicaset_2'] = new_cfg_template.sharding[2]
new_cfg_template.sharding[1] = nil
new_cfg_template.sharding[2] = nil
local new_global_cfg = vtest.config_new(new_cfg_template)

-- Set names, as they should be verified on connection.
g.replica_1_a:exec(function()
box.ctl.wait_rw()
box.cfg{instance_name = 'replica_1_a', replicaset_name = 'replicaset_1'}
end)
g.replica_1_b:exec(function()
box.cfg{instance_name = 'replica_1_b'}
end)
g.replica_2_a:exec(function()
box.ctl.wait_rw()
box.cfg{instance_name = 'replica_2_a', replicaset_name = 'replicaset_2'}
end)
g.replica_2_b:exec(function()
box.cfg{instance_name = 'replica_2_b'}
end)
g.replica_2_a:wait_vclock_of(g.replica_1_a)
g.replica_2_b:wait_vclock_of(g.replica_2_a)
vtest.cluster_cfg(g, new_global_cfg)
vtest.router_cfg(g.router, new_global_cfg)

local router = g.router
local res, err = router:exec(function()
-- Just a basic test.
return ivshard.router.callrw(1, 'echo', {1}, {timeout = iwait_timeout})
end)
t.assert(not err, 'no error')
t.assert_equals(res, 1, 'good result')

-- Restore everything back.
vtest.cluster_cfg(g, global_cfg)
vtest.router_cfg(g.router, global_cfg)
end
12 changes: 6 additions & 6 deletions vshard/router/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ local function bucket_discovery(router, bucket_id)
local _, err =
replicaset:callrw('vshard.storage.bucket_stat', {bucket_id})
if err == nil then
return bucket_set(router, bucket_id, replicaset.uuid)
return bucket_set(router, bucket_id, replicaset.id)
elseif err.code ~= lerror.code.WRONG_BUCKET and
err.code ~= lerror.code.REPLICASET_IN_BACKOFF then
last_err = err
Expand Down Expand Up @@ -677,7 +677,7 @@ local function router_call_impl(router, bucket_id, mode, prefer_replica,
end
else
replicaset = bucket_set(router, bucket_id,
replicaset.uuid)
replicaset.id)
lfiber.yield()
-- Protect against infinite cycle in a
-- case of broken cluster, when a bucket
Expand Down Expand Up @@ -1318,7 +1318,7 @@ local function router_cfg(router, cfg, is_reload)
local known_bucket_count = 0
router.route_map = table_new(router.total_bucket_count, 0)
for bucket, rs in pairs(old_route_map) do
local new_rs = router.replicasets[rs.uuid]
local new_rs = router.replicasets[rs.id]
if new_rs then
router.route_map[bucket] = new_rs
new_rs.bucket_count = new_rs.bucket_count + 1
Expand Down Expand Up @@ -1482,7 +1482,7 @@ local function router_info(router, opts)
uuid = replicaset.uuid,
bucket = {}
}
state.replicasets[replicaset.uuid] = rs_info
state.replicasets[replicaset.id] = rs_info

-- Build master info.
local info, color =
Expand All @@ -1509,15 +1509,15 @@ local function router_info(router, opts)
-- If the replica is not optimal, then some replicas
-- possibly are down.
local a = lerror.alert(lerror.code.SUBOPTIMAL_REPLICA,
replicaset.uuid)
replicaset.id)
table.insert(state.alerts, a)
state.status = math.max(state.status, consts.STATUS.YELLOW)
end

if rs_info.replica.status ~= 'available' and
rs_info.master.status ~= 'available' then
local a = lerror.alert(lerror.code.UNREACHABLE_REPLICASET,
replicaset.uuid)
replicaset.id)
table.insert(state.alerts, a)
state.status = consts.STATUS.RED
end
Expand Down

0 comments on commit 515506f

Please sign in to comment.