Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replicaset: soften name validation #458

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions test/replicaset-luatest/replicaset_3_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,24 @@ test_group.test_named_replicaset = function(g)
t.assert_equals(rs.id, rs.name)
t.assert_equals(replica_1_a.id, replica_1_a.name)

-- Name is not set, name mismatch error.
-- Name is not set, uuid is not set, name mismatch error.
local ret, err = rs:callrw('get_uuid', {}, {timeout = 5})
t.assert_equals(err.name, 'INSTANCE_NAME_MISMATCH')
t.assert_equals(ret, nil)

local uuid_a = g.replica_1_a:instance_uuid()
-- Test, that NAME_MISMATCH error is skipped, when uuid is specified.
-- Before the name configuration, as a name cannot be dropped. New
-- replicaset in order not to rebuild it for the name configuration.
new_global_cfg.sharding['replicaset'].replicas['replica_1_a'].uuid =
g.replica_1_a:instance_uuid()
local rs_2 = vreplicaset.buildall(new_global_cfg).replicaset
ret, err = rs_2:callrw('get_uuid', {}, timeout_opts)
t.assert_equals(err, nil)
t.assert_equals(ret, uuid_a)

-- Set name, everything works from now on.
g.replica_1_a:exec(function() box.cfg{instance_name = 'replica_1_a'} end)
local uuid_a = g.replica_1_a:instance_uuid()
ret, err = rs:callrw('get_uuid', {}, timeout_opts)
t.assert_equals(err, nil)
t.assert_equals(ret, uuid_a)
Expand Down
10 changes: 7 additions & 3 deletions vshard/replicaset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ end
--
local function conn_vconnect_check(conn)
local vconn = conn.vconnect
local replica = conn.replica
-- conn.vconnect may be nil, if connection was created on old version
-- and the storage was reloaded to a new one. It's also nil, when
-- all checks were already done.
Expand All @@ -146,17 +147,20 @@ local function conn_vconnect_check(conn)
-- Nothing to do, but wait in such case.
if not vconn.future or not vconn.future:is_ready() then
return nil, lerror.vshard(lerror.code.VHANDSHAKE_NOT_COMPLETE,
conn.replica.id)
replica.id)
end
-- Critical errors. Connection should be closed after these ones.
local result, err = vconn.future:result()
if not result then
-- Failed to get response. E.g. access error.
return nil, lerror.make(err)
end
if vconn.is_named and result[1].name ~= conn.replica.name then
-- If name is nil, it means, name was not set yet. If uuid is specified,
-- then we allow mismatch between config name and nil.
local is_name_set = result[1].name ~= nil or replica.uuid == nil
if vconn.is_named and is_name_set and result[1].name ~= replica.name then
return nil, lerror.vshard(lerror.code.INSTANCE_NAME_MISMATCH,
conn.replica.name, result[1].name)
replica.name, result[1].name)
end
-- Don't validate until reconnect happens.
conn.vconnect = nil
Expand Down
Loading