Skip to content

Commit 18e0f39

Browse files
AntiFrizz1Gerold103
authored andcommitted
replicaset: support ipv6 uri
cartridge tool doesn't work with ipv6 addrs. Without this changes operation `cartridge replicasets setup --bootstrap-vshard` failed because `replicaset.master.uri` contains ipv6 addr without brackets. Changes add brackets to replica uri if it is ipv6 address. Needed for tarantool/cartridge#2166 NO_DOC=minor
1 parent 48e6e9d commit 18e0f39

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

test/replicaset-luatest/replicaset_3_test.lua

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,13 @@ test_group.test_named_replicaset = function(g)
300300
t.assert_equals(ret, nil)
301301
vtest.storage_start(g.replica_1_b, global_cfg)
302302
end
303+
304+
test_group.test_ipv6_uri = function(g)
305+
local new_cfg = table.deepcopy(global_cfg)
306+
local rs_uuid = g.replica_1_a:replicaset_uuid()
307+
local uuid = g.replica_1_a:instance_uuid()
308+
new_cfg.sharding[rs_uuid].replicas[uuid].uri = 'storage:storage@[::1]:3301'
309+
local _, rs = next(vreplicaset.buildall(new_cfg))
310+
local replica_string = 'replica_1_a(storage@[::1]:3301)'
311+
t.assert_equals(tostring(rs.master), replica_string)
312+
end

vshard/replicaset.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ local replica_mt = {
12041204
safe_uri = function(replica)
12051205
local uri = luri.parse(replica.uri)
12061206
uri.password = nil
1207-
return luri.format(uri)
1207+
return util.uri_format(uri)
12081208
end,
12091209
detach_conn = replica_detach_conn,
12101210
},

vshard/util.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,22 @@ else
418418
end
419419
end
420420

421+
local uri_v6_str = "[::1]:80"
422+
local uri_format
423+
-- URI module format() function doesn't behave correctly for IPv6 addresses on
424+
-- some Tarantool versions (all <= 3.0). In fact, at the time of writing none of
425+
-- the versions have this bug fixed.
426+
if luri.format(luri.parse(uri_v6_str)) ~= uri_v6_str then
427+
uri_format = function(u)
428+
if u.ipv6 then
429+
u.host = '[' .. u.host .. ']'
430+
end
431+
return luri.format(u)
432+
end
433+
else
434+
uri_format = luri.format
435+
end
436+
421437
return {
422438
core_version = tnt_version,
423439
uri_eq = uri_eq,
@@ -439,4 +455,5 @@ return {
439455
feature = feature,
440456
schema_version = schema_version,
441457
replicaset_uuid = replicaset_uuid,
458+
uri_format = uri_format,
442459
}

0 commit comments

Comments
 (0)