Skip to content

Commit

Permalink
replicaset: validate name in replicaset_locate_master
Browse files Browse the repository at this point in the history
Currently, the name validation is not used, when locate_master()
is called. It makes an explicit call via the connection to obtain a
future object in order to figure out, whether the node is a master.

We should not make any calls to a replica until the time, we definitely
know, that its name and uuid was validated. Let's use replica_call
instead of conn.call.

Follow-up tarantool#426

NO_DOC=bugfix
  • Loading branch information
Serpentian committed Dec 26, 2023
1 parent bc84c65 commit 16afd10
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
12 changes: 11 additions & 1 deletion test/replicaset-luatest/replicaset_3_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ test_group.test_locate_master_when_no_conn_object = function(g)
--
local is_all_done, is_all_nop, last_err =
vreplicaset.locate_masters(replicasets)
t.assert_equals(last_err, nil)
t.assert_str_contains(last_err.message, 'Connection is not established')
t.assert(not is_all_done)
t.assert(not is_all_nop)
for _, r in pairs(rs.replicas) do
Expand Down Expand Up @@ -269,6 +269,16 @@ 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)

-- Check, that name is checked, when master search is used.
rs.master = nil
rs.is_master_auto = true
local ok, is_noop, err = rs:locate_master()
t.assert_equals(err.name, 'VHANDSHAKE_NOT_COMPLETE')
t.assert_equals(ok, false)
t.assert_equals(is_noop, false)
rs.master = rs.replicas.replica_1_a
rs.is_master_auto = false

-- 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')
Expand Down
14 changes: 6 additions & 8 deletions vshard/replicaset.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1091,17 +1091,15 @@ local function replicaset_locate_master(replicaset)
local futures = {}
local timeout = const_timeout
local deadline = fiber_clock() + timeout
local async_opts = {is_async = true}
local async_opts = {is_async = true, timeout = timeout}
local replicaset_id = replicaset.id
for replica_id, replica in pairs(replicaset.replicas) do
local conn = replicaset_connect_to_replica(replicaset, replica)
if conn:is_connected() then
ok, f = pcall(conn.call, conn, func, args, async_opts)
if not ok then
last_err = lerror.make(f)
else
futures[replica_id] = f
end
local ok, res, err = replica_call(replica, func, args, async_opts)
if not ok then
last_err = err
else
futures[replica_id] = res
end
end
local master_id
Expand Down

0 comments on commit 16afd10

Please sign in to comment.