Skip to content

Commit af30aff

Browse files
mandeserolocker
authored andcommitted
Fixed a URI lookup with multiple replica sets
This patch fixed an issue where the URI lookup logic would terminate prematurely if the instance was not found in the first replica set when multiple replica sets were present. Closes #427
1 parent f9c2e72 commit af30aff

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
- Added an option to create `Cluster` objects without global hook management,
66
allowing tests to keep clusters alive between test runs (gh-414).
7+
- Fixed a bug where URI search would terminate prematurely when multiple
8+
replicasets existed (gh-427).
79

810
## 1.2.1
911

luatest/server.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ local function find_advertise_uri(config, instance_name, dir)
153153
for _, replicaset in pairs(group.replicasets or {}) do
154154
local instance = (replicaset.instances or {})[instance_name]
155155
if instance == nil then
156-
break
156+
goto continue
157157
end
158158
if instance.iproto ~= nil then
159159
if instance.iproto.advertise ~= nil then
@@ -173,6 +173,7 @@ local function find_advertise_uri(config, instance_name, dir)
173173
end
174174
listen = listen or group.iproto.listen
175175
end
176+
::continue::
176177
end
177178
end
178179

test/server_test.lua

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local fio = require('fio')
22
local json = require('json')
33
local urilib = require('uri')
4+
local yaml = require('yaml')
45

56
local t = require('luatest')
67
local g = t.group()
@@ -492,6 +493,61 @@ g.after_test('test_no_socket_collision_with_duplicate_alias', function()
492493
g.s2:drop()
493494
end)
494495

496+
g.test_net_box_uri_is_taken_from_matching_replicaset = function()
497+
local tempdir = fio.tempdir()
498+
local config_path = fio.pathjoin(tempdir, 'config.yaml')
499+
500+
local config = {
501+
groups = {
502+
['group-001'] = {
503+
replicasets = {
504+
['rs-1'] = {
505+
iproto = {
506+
listen = {{
507+
uri = 'unix/:./{{ instance_name }}.iproto'
508+
}},
509+
},
510+
instances = {
511+
['router-1'] = {},
512+
},
513+
},
514+
['rs-2'] = {
515+
iproto = {
516+
listen = {{
517+
uri = 'unix/:./{{ instance_name }}.iproto'
518+
}},
519+
},
520+
instances = {
521+
['storage-1'] = {},
522+
},
523+
},
524+
},
525+
},
526+
},
527+
}
528+
529+
local fh = fio.open(config_path, {'O_CREAT', 'O_WRONLY', 'O_TRUNC'},
530+
tonumber('644', 8))
531+
fh:write(yaml.encode(config))
532+
fh:close()
533+
534+
local s1 = Server:new({
535+
alias = 'storage-1',
536+
config_file = config_path,
537+
})
538+
local s2 = Server:new({
539+
alias = 'router-1',
540+
config_file = config_path,
541+
})
542+
543+
t.assert_equals(s1.net_box_uri, 'unix/:nil/storage-1.iproto')
544+
t.assert_equals(s2.net_box_uri, 'unix/:nil/router-1.iproto')
545+
s1:drop()
546+
s2:drop()
547+
548+
fio.rmtree(tempdir)
549+
end
550+
495551
g.test_netbox_uri_is_not_overridden = function()
496552
local socket = ('%s/my-custom.sock'):format(Server.vardir)
497553
g.s1 = Server:new({net_box_uri = socket})

0 commit comments

Comments
 (0)