Skip to content

Commit

Permalink
replicaset: support ipv6 uri
Browse files Browse the repository at this point in the history
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
  • Loading branch information
AntiFrizz1 authored and Gerold103 committed Jan 12, 2024
1 parent 48e6e9d commit 18e0f39
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/replicaset-luatest/replicaset_3_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,13 @@ test_group.test_named_replicaset = function(g)
t.assert_equals(ret, nil)
vtest.storage_start(g.replica_1_b, global_cfg)
end

test_group.test_ipv6_uri = function(g)
local new_cfg = table.deepcopy(global_cfg)
local rs_uuid = g.replica_1_a:replicaset_uuid()
local uuid = g.replica_1_a:instance_uuid()
new_cfg.sharding[rs_uuid].replicas[uuid].uri = 'storage:storage@[::1]:3301'
local _, rs = next(vreplicaset.buildall(new_cfg))
local replica_string = 'replica_1_a(storage@[::1]:3301)'
t.assert_equals(tostring(rs.master), replica_string)
end
2 changes: 1 addition & 1 deletion vshard/replicaset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1204,7 +1204,7 @@ local replica_mt = {
safe_uri = function(replica)
local uri = luri.parse(replica.uri)
uri.password = nil
return luri.format(uri)
return util.uri_format(uri)
end,
detach_conn = replica_detach_conn,
},
Expand Down
17 changes: 17 additions & 0 deletions vshard/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@ else
end
end

local uri_v6_str = "[::1]:80"
local uri_format
-- URI module format() function doesn't behave correctly for IPv6 addresses on
-- some Tarantool versions (all <= 3.0). In fact, at the time of writing none of
-- the versions have this bug fixed.
if luri.format(luri.parse(uri_v6_str)) ~= uri_v6_str then
uri_format = function(u)
if u.ipv6 then
u.host = '[' .. u.host .. ']'
end
return luri.format(u)
end
else
uri_format = luri.format
end

return {
core_version = tnt_version,
uri_eq = uri_eq,
Expand All @@ -439,4 +455,5 @@ return {
feature = feature,
schema_version = schema_version,
replicaset_uuid = replicaset_uuid,
uri_format = uri_format,
}

0 comments on commit 18e0f39

Please sign in to comment.