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 tarantool#426

@TarantoolBot document
Title: vshard: vshard.router.buckets_info shows name

When `identification_mode` is `name_as_key`, buckets_info()
also returns name of the replicas, where buckets are stored:

```
tarantool> vshard.router.buckets_info()
---
- - uuid: aaaaaaaa-0000-4000-a000-000000000000
    status: available_rw
    name: replica_1_a
```
  • Loading branch information
Serpentian committed Dec 4, 2023
1 parent 78ebb5e commit b9c9897
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 96 deletions.
44 changes: 44 additions & 0 deletions test/router-luatest/router_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -649,3 +649,47 @@ g.test_router_service_info = function(g)
-- Restore everything back.
vtest.router_cfg(g.router, global_cfg)
end

g.test_named_config_identification = function(g)
t.run_only_if(vutil.version_is_at_least(3, 0, 0, 'entrypoint', 0, 0))
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.cfg{instance_name = 'replica_1_a', replicaset_name = 'replicaset_1'}
end)
g.replica_1_b:exec(function()
box.cfg{instance_name = 'replica_1_b', replicaset_name = 'replicaset_1'}
end)
g.replica_2_a:exec(function()
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', replicaset_name = 'replicaset_2'}
end)

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()
-- buckets_info shows name, when name identification is used.
local _, err = ivshard.router.bucket_discovery(1)
ilt.assert_equals(err, nil)
ilt.assert_not_equals(ivshard.router.buckets_info()[1].name, nil)
-- just 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
48 changes: 24 additions & 24 deletions test/router/router.result
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ _ = vshard.router.bucket_discovery(3)
vshard.router.buckets_info(0, 3)
---
- - status: unknown
- uuid: <replicaset_2>
status: available_rw
- uuid: <replicaset_2>
status: available_rw
- status: available_rw
uuid: <replicaset_2>
- status: available_rw
uuid: <replicaset_2>
...
_ = test_run:cmd('stop server storage_2_a')
---
Expand All @@ -422,10 +422,10 @@ util.check_error(vshard.router.call, 1, 'read', 'echo', {123})
vshard.router.buckets_info(0, 3)
---
- - status: unknown
- uuid: <replicaset_2>
status: available_ro
- uuid: <replicaset_2>
status: available_ro
- status: available_ro
uuid: <replicaset_2>
- status: available_ro
uuid: <replicaset_2>
...
_ = test_run:cmd('start server storage_2_a')
---
Expand Down Expand Up @@ -1164,46 +1164,46 @@ buckets_info = vshard.router.buckets_info()
...
buckets_info[1]
---
- uuid: <replicaset_2>
status: available_rw
- status: available_rw
uuid: <replicaset_2>
...
buckets_info[1501]
---
- uuid: <replicaset_1>
status: available_rw
- status: available_rw
uuid: <replicaset_1>
...
vshard.router.buckets_info(0, 3)
---
- - uuid: <replicaset_2>
status: available_rw
- uuid: <replicaset_2>
status: available_rw
- uuid: <replicaset_2>
status: available_rw
- - status: available_rw
uuid: <replicaset_2>
- status: available_rw
uuid: <replicaset_2>
- status: available_rw
uuid: <replicaset_2>
...
vshard.router.buckets_info(1500, 3)
---
- 1502:
uuid: <replicaset_1>
status: available_rw
1503:
uuid: <replicaset_1>
1503:
status: available_rw
1501:
uuid: <replicaset_1>
1501:
status: available_rw
uuid: <replicaset_1>
...
vshard.router.buckets_info(vshard.consts.DEFAULT_BUCKET_COUNT - 3)
---
- 3000:
uuid: <replicaset_1>
status: available_rw
2998:
uuid: <replicaset_1>
2998:
status: available_rw
2999:
uuid: <replicaset_1>
2999:
status: available_rw
uuid: <replicaset_1>
...
util.check_error(vshard.router.buckets_info, '123')
---
Expand Down
Loading

0 comments on commit b9c9897

Please sign in to comment.