Skip to content

Commit aa87ac9

Browse files
SerpentianGerold103
authored andcommitted
replicaset: soften name validation
During upgrade to Tarantool 3.0.0 there's a time, when instance name have not been set yet. If vshard strictly validates names on connection, it leads to the cluster unavailability by the time, when all names are configured. This commit softens the check and allows name to be nil, when instance UUID is specified in configuration, only UUID is validated in such case. In conclusion we have the following checks on connection: 1. UUID is validated in the following cases: a. When `identification_mode` is `uuid_as_key` b. When `identification_mode` is `name_as_key` and replica.uuid is specified 2. Instance name is validated only when `identification_mode` is `name_as_key` and can work in the following modes: a. Strict validation (nil instance name is not allowed), when replica.uuid is not specified. b. Soft validation (nil instance name is allowed), when replica.uuid is specified. Follow-up #426 NO_DOC=internal
1 parent 6364056 commit aa87ac9

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

test/replicaset-luatest/replicaset_3_test.lua

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,14 +269,24 @@ test_group.test_named_replicaset = function(g)
269269
t.assert_equals(rs.id, rs.name)
270270
t.assert_equals(replica_1_a.id, replica_1_a.name)
271271

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

277+
local uuid_a = g.replica_1_a:instance_uuid()
278+
-- Test, that NAME_MISMATCH error is skipped, when uuid is specified.
279+
-- Before the name configuration, as a name cannot be dropped. New
280+
-- replicaset in order not to rebuild it for the name configuration.
281+
new_global_cfg.sharding['replicaset'].replicas['replica_1_a'].uuid =
282+
g.replica_1_a:instance_uuid()
283+
local rs_2 = vreplicaset.buildall(new_global_cfg).replicaset
284+
ret, err = rs_2:callrw('get_uuid', {}, timeout_opts)
285+
t.assert_equals(err, nil)
286+
t.assert_equals(ret, uuid_a)
287+
277288
-- Set name, everything works from now on.
278289
g.replica_1_a:exec(function() box.cfg{instance_name = 'replica_1_a'} end)
279-
local uuid_a = g.replica_1_a:instance_uuid()
280290
ret, err = rs:callrw('get_uuid', {}, timeout_opts)
281291
t.assert_equals(err, nil)
282292
t.assert_equals(ret, uuid_a)

vshard/replicaset.lua

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ end
137137
--
138138
local function conn_vconnect_check(conn)
139139
local vconn = conn.vconnect
140+
local replica = conn.replica
140141
-- conn.vconnect may be nil, if connection was created on old version
141142
-- and the storage was reloaded to a new one. It's also nil, when
142143
-- all checks were already done.
@@ -146,17 +147,20 @@ local function conn_vconnect_check(conn)
146147
-- Nothing to do, but wait in such case.
147148
if not vconn.future or not vconn.future:is_ready() then
148149
return nil, lerror.vshard(lerror.code.VHANDSHAKE_NOT_COMPLETE,
149-
conn.replica.id)
150+
replica.id)
150151
end
151152
-- Critical errors. Connection should be closed after these ones.
152153
local result, err = vconn.future:result()
153154
if not result then
154155
-- Failed to get response. E.g. access error.
155156
return nil, lerror.make(err)
156157
end
157-
if vconn.is_named and result[1].name ~= conn.replica.name then
158+
-- If name is nil, it means, name was not set yet. If uuid is specified,
159+
-- then we allow mismatch between config name and nil.
160+
local is_name_set = result[1].name ~= nil or replica.uuid == nil
161+
if vconn.is_named and is_name_set and result[1].name ~= replica.name then
158162
return nil, lerror.vshard(lerror.code.INSTANCE_NAME_MISMATCH,
159-
conn.replica.name, result[1].name)
163+
replica.name, result[1].name)
160164
end
161165
-- Don't validate until reconnect happens.
162166
conn.vconnect = nil

0 commit comments

Comments
 (0)