+
Skip to content
Open
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
26 changes: 13 additions & 13 deletions test/failover/failover.result
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ priority_order()
- - 1
- unknown zone
...
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
---
- true
...
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
---
- true
...
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
---
- true
...
Expand Down Expand Up @@ -371,15 +371,15 @@ priority_order()
- - 1
- unknown zone
...
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
---
- true
...
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
---
- true
...
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
---
- true
...
Expand Down Expand Up @@ -409,15 +409,15 @@ priority_order()
- - 1
- unknown zone
...
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
---
- true
...
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
---
- true
...
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
---
- true
...
Expand Down Expand Up @@ -447,15 +447,15 @@ priority_order()
- - unknown zone
- 1
...
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
---
- true
...
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
---
- true
...
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
---
- true
...
Expand All @@ -482,7 +482,7 @@ while not test_run:grep_log('router_1', 'Ping error from', 1000) do fiber.sleep(
t = string.rep('a', 1024 * 1024 * 500)
---
...
rs = vshard.router.route(31)
rs = vshard.router.route(31)._replicaset
---
...
while rs.master ~= rs.replica do fiber.sleep(0.01) end
Expand Down
26 changes: 13 additions & 13 deletions test/failover/failover.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ test_run:switch('router_1')
vshard.router.cfg(cfg)
while not test_run:grep_log('router_1', 'New replica box_1_d%(storage%@') do fiber.sleep(0.1) end
priority_order()
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
vshard.router.call(1, 'read', 'echo', {123})
test_run:switch('box_1_d')
-- Not 0 - 'read' echo was called here.
Expand Down Expand Up @@ -145,27 +145,27 @@ create_router('router_2')
test_run:switch('router_2')
vshard.router.cfg(cfg)
priority_order()
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
test_run:switch('default')

create_router('router_3')
test_run:switch('router_3')
vshard.router.cfg(cfg)
priority_order()
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]
test_run:switch('default')

create_router('router_4')
test_run:switch('router_4')
vshard.router.cfg(cfg)
priority_order()
vshard.router.route(1).uuid == rs_uuid[1]
vshard.router.route(31).uuid == rs_uuid[2]
vshard.router.route(61).uuid == rs_uuid[3]
vshard.router.route(1)._replicaset.uuid == rs_uuid[1]
vshard.router.route(31)._replicaset.uuid == rs_uuid[2]
vshard.router.route(61)._replicaset.uuid == rs_uuid[3]

--
-- gh-169: do not close connections on too long ping when this is
Expand All @@ -178,7 +178,7 @@ vshard.router.cfg(cfg)
while not test_run:grep_log('router_1', 'Ping error from', 1000) do fiber.sleep(0.01) end

t = string.rep('a', 1024 * 1024 * 500)
rs = vshard.router.route(31)
rs = vshard.router.route(31)._replicaset
while rs.master ~= rs.replica do fiber.sleep(0.01) end
future = nil
-- Create strong reference to prevent Lua GC from closing the
Expand Down
2 changes: 1 addition & 1 deletion test/misc/check_uuid_on_connect.result
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ vshard.router.route(1)
bucket_id: 1
...
-- Ok to work with correct replicasets.
vshard.router.route(2).uuid
vshard.router.route(2)._replicaset.uuid
---
- cbf06940-0790-498b-948d-042b62cf3d29
...
Expand Down
2 changes: 1 addition & 1 deletion test/misc/check_uuid_on_connect.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ test_run:switch('bad_uuid_router')
vshard.router.static.route_map[1] = nil
vshard.router.route(1)
-- Ok to work with correct replicasets.
vshard.router.route(2).uuid
vshard.router.route(2)._replicaset.uuid

_ = test_run:cmd("switch default")
test_run:cmd('stop server bad_uuid_router')
Expand Down
5 changes: 0 additions & 5 deletions test/multiple_routers/multiple_routers.result
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@ vshard.router.call(1, 'read', 'do_select', {1})
---
- [[1, 1]]
...
-- Test that static router is just a router object under the hood.
vshard.router.static:route(1) == vshard.router.route(1)
---
- true
...
-- Configure extra router.
router_2 = vshard.router.new('router_2', configs.cfg_2)
---
Expand Down
3 changes: 0 additions & 3 deletions test/multiple_routers/multiple_routers.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ _ = test_run:cmd("switch router_1")
vshard.router.call(1, 'write', 'do_replace', {{1, 1}})
vshard.router.call(1, 'read', 'do_select', {1})

-- Test that static router is just a router object under the hood.
vshard.router.static:route(1) == vshard.router.route(1)

-- Configure extra router.
router_2 = vshard.router.new('router_2', configs.cfg_2)
router_2:bootstrap()
Expand Down
7 changes: 4 additions & 3 deletions test/router-luatest/map_callrw_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ g.test_map_part_double_ref = function(cg)
-- Make sure the location of the bucket is known.
local rs, err = ivshard.router.route(bid)
ilt.assert_equals(err, nil)
rs = rs._replicaset
ilt.assert_equals(rs.uuid, uuid)
end, {bid1, cg.rs1_uuid})
-- Then, move the bucket form rs1 to rs2. Now the router has an outdated
Expand Down Expand Up @@ -251,7 +252,7 @@ g.test_map_part_double_ref = function(cg)
ivshard.router.discovery_wakeup()
local rs, err = ivshard.router.route(bid)
ilt.assert_equals(err, nil)
ilt.assert_equals(rs.uuid, uuid)
ilt.assert_equals(rs._replicaset.uuid, uuid)
end)
end, {bid1, cg.rs1_uuid})
end
Expand All @@ -273,7 +274,7 @@ g.test_map_part_ref_timeout = function(cg)
for _, bid in ipairs(bids) do
local rs, err = ivshard.router.route(bid)
ilt.assert_equals(err, nil)
ilt.assert_equals(rs.uuid, uuid)
ilt.assert_equals(rs._replicaset.uuid, uuid)
end
end
end, {{[cg.rs1_uuid] = {bid1, bid2}, [cg.rs2_uuid] = {bid3, bid4}}})
Expand Down Expand Up @@ -379,7 +380,7 @@ g.test_map_part_ref_timeout = function(cg)
ivshard.router.discovery_wakeup()
local rs, err = ivshard.router.route(bid)
ilt.assert_equals(err, nil)
ilt.assert_equals(rs.uuid, uuid)
ilt.assert_equals(rs._replicaset.uuid, uuid)
end)
end, {bid2, cg.rs1_uuid})
end
Expand Down
61 changes: 60 additions & 1 deletion test/router-luatest/router_2_2_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,65 @@ g.test_msgpack_args = function(g)
t.assert_equals(res, 100, 'good result')
end

local function router_check_replicaset_protection_init()
g.router:exec(function()
rawset(_G, "check_replicaset_protection",
function(rs)
t.assert_not_equals(rs._replicaset, nil)
t.assert_equals(next(rs, next(rs)), nil)
t.assert_not_equals(rs.call, nil)
t.assert_not_equals(rs.callrw, nil)
t.assert_not_equals(rs.callro, nil)
t.assert_not_equals(rs.callbro, nil)
t.assert_not_equals(rs.callre, nil)
t.assert_not_equals(rs.callbre, nil)
local err_msg =
"Modification of replicaset table is not allowed"
-- Adding a field is prohibited.
t.assert_error_msg_contains(
err_msg, function(t) t.new_field = 1 end, rs)
err_msg = "cannot change a protected metatable"
t.assert_error_msg_equals(err_msg, setmetatable, rs, {})
end)
end)
end

local function router_check_replicaset_protection_clear()
g.router:exec(function()
rawset(_G, "check_replicaset_protection", nil)
end)
end

g.test_router_route_return_value_protection = function(g)
router_check_replicaset_protection_init()
g.router:exec(function()
_G.check_replicaset_protection(ivshard.router.route(1))
end)
router_check_replicaset_protection_clear()
end

g.test_router_routeall_return_value_protection = function(g)
router_check_replicaset_protection_init()
g.router:exec(function()
local replicasets = ivshard.router.routeall()
for _, rs in pairs(replicasets) do
_G.check_replicaset_protection(rs)
end
-- Adding a field.
replicasets.new_field = 1
t.assert_equals(replicasets.new_field, 1)
replicasets = ivshard.router.routeall()
t.assert_equals(replicasets.new_field, nil)
-- Deleting a field.
local id, _ = next(replicasets)
replicasets[id] = nil
t.assert_equals(replicasets[id], nil)
replicasets = ivshard.router.routeall()
t.assert_not_equals(replicasets[id], nil)
end)
router_check_replicaset_protection_clear()
end

local function test_return_raw_template(g, mode)
--
-- Normal call.
Expand Down Expand Up @@ -1083,7 +1142,7 @@ g.test_retryable_transfer_in_progress = function(g)
end)
g.router:exec(function(bid, uuid)
local rs = ivshard.router.route(bid)
ilt.assert_equals(rs.uuid, uuid)
ilt.assert_equals(rs._replicaset.uuid, uuid)
end, {bid, g.replica_2_a:replicaset_uuid()})

-- Block bucket receive.
Expand Down
3 changes: 2 additions & 1 deletion test/router-luatest/router_election_auto_master_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ end)
local function router_wait_for_leader(bid, uuid)
ilt.helpers.retrying({timeout = ivtest.wait_timeout}, function()
ivshard.router.master_search_wakeup()
ilt.assert_equals(ivshard.router.route(bid).master.uuid, uuid)
ilt.assert_equals(
ivshard.router.route(bid)._replicaset.master.uuid, uuid)
end)
end

Expand Down
6 changes: 3 additions & 3 deletions test/router/reload.result
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ check_reloaded()
--
-- Outdate old replicaset and replica objects.
--
rs = vshard.router.route(1)
rs = vshard.router.route(1)._replicaset
---
...
rs:callro('echo', {'some_data'})
Expand Down Expand Up @@ -233,7 +233,7 @@ rs.callro(rs, 'echo', {'some_data'})
vshard.router = require('vshard.router')
---
...
rs = vshard.router.route(1)
rs = vshard.router.route(1)._replicaset
---
...
rs:callro('echo', {'some_data'})
Expand All @@ -258,7 +258,7 @@ cfg.connection_outdate_delay = old_connection_delay
vshard.router.static.connection_outdate_delay = nil
---
...
rs_new = vshard.router.route(1)
rs_new = vshard.router.route(1)._replicaset
---
...
rs_old = rs
Expand Down
6 changes: 3 additions & 3 deletions test/router/reload.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -114,23 +114,23 @@ check_reloaded()
--
-- Outdate old replicaset and replica objects.
--
rs = vshard.router.route(1)
rs = vshard.router.route(1)._replicaset
rs:callro('echo', {'some_data'})
package.loaded["vshard.router"] = nil
_ = require('vshard.router')
-- Make sure outdate async task has had cpu time.
while not rs.is_outdated do fiber.sleep(0.001) end
rs.callro(rs, 'echo', {'some_data'})
vshard.router = require('vshard.router')
rs = vshard.router.route(1)
rs = vshard.router.route(1)._replicaset
rs:callro('echo', {'some_data'})
-- Test `connection_outdate_delay`.
old_connection_delay = cfg.connection_outdate_delay
cfg.connection_outdate_delay = 0.3
vshard.router.cfg(cfg)
cfg.connection_outdate_delay = old_connection_delay
vshard.router.static.connection_outdate_delay = nil
rs_new = vshard.router.route(1)
rs_new = vshard.router.route(1)._replicaset
rs_old = rs
_, replica_old = next(rs_old.replicas)
rs_new:callro('echo', {'some_data'})
Expand Down
4 changes: 2 additions & 2 deletions test/router/router.result
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ util.check_error(vshard.router.route)
---
- 'Usage: router.route(bucket_id)'
...
conn = vshard.router.route(1).master.conn
conn = vshard.router.route(1)._replicaset.master.conn
---
...
conn.state
Expand Down Expand Up @@ -482,7 +482,7 @@ rs.master = master
master.conn:close()
---
...
conn = vshard.router.route(1):connect()
conn = vshard.router.route(1)._replicaset:connect()
---
...
conn:wait_connected()
Expand Down
4 changes: 2 additions & 2 deletions test/router/router.test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ _ = test_run:cmd('start server storage_2_a')
vshard.router.route(vshard.consts.DEFAULT_BUCKET_COUNT + 100)
util.check_error(vshard.router.route, 'asdfg')
util.check_error(vshard.router.route)
conn = vshard.router.route(1).master.conn
conn = vshard.router.route(1)._replicaset.master.conn
conn.state
-- Test missing master.
rs = vshard.router.static.replicasets[util.replicasets[2]]
Expand All @@ -179,7 +179,7 @@ vshard.router.route(1).master
rs.master = master
-- Test reconnect on bucker_route().
master.conn:close()
conn = vshard.router.route(1):connect()
conn = vshard.router.route(1)._replicaset:connect()
conn:wait_connected()
conn.state

Expand Down
Loading
Loading
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载