Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerold103 committed Sep 18, 2024
1 parent e48b75d commit 93ff41b
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 168 deletions.
15 changes: 5 additions & 10 deletions test/router-luatest/router_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -288,21 +288,16 @@ end

g.test_group_buckets = function(g)
local bids = vtest.storage_get_n_buckets(g.replica_1_a, 2)

local res = g.router:exec(function(bid1, bid2)
local val, err = ivshard.router._buckets_group({bid2, bid1, bid1})
return {
val = val,
err = err,
}
local val, err = g.router:exec(function(bid1, bid2)
return ivshard.router._buckets_group({bid2, bid1, bid1, bid2},
ivtest.wait_timeout)
end, {bids[1], bids[2]})
assert(res.err == nil)
assert(err == nil)
local rs1_uuid = g.replica_1_a:replicaset_uuid()
local expected = {
[rs1_uuid] = {bids[1], bids[2]},
}
table.sort(expected[rs1_uuid])
t.assert_equals(res.val, expected)
t.assert_equals(val, expected)
end

g.test_uri_compare_and_reuse = function(g)
Expand Down
96 changes: 41 additions & 55 deletions test/storage-luatest/storage_1_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -228,92 +228,80 @@ end

test_group.test_ref_with_lookup = function(g)
g.replica_1_a:exec(function()
local lref = require('vshard.storage.ref')
local res, err
local timeout = 0.1
local rid = 42
local bids = _G.get_n_buckets(2)
local bid_extra = 3001
local bucket_count = ivshard.storage.internal.total_bucket_count

-- Check for a single bucket.
-- No buckets.
res, err = ivshard.storage._call(
'storage_ref_with_lookup',
rid,
timeout,
{bids[1]}
)
'storage_ref_with_lookup', rid, iwait_timeout, {})
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {moved = {}})
ilt.assert_equals(lref.count, 0)

-- Check for a single ok bucket.
res, err = ivshard.storage._call(
'storage_ref_with_lookup', rid, iwait_timeout, {bids[1]})
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {rid = rid, moved = {}})
ilt.assert_equals(lref.count, 1)
res, err = ivshard.storage._call('storage_unref', rid)
ilt.assert_equals(err, nil)
ilt.assert_equals(lref.count, 0)

-- Check for multiple buckets.
-- Check for multiple ok buckets.
res, err = ivshard.storage._call(
'storage_ref_with_lookup',
rid,
timeout,
{bids[1], bids[2]}
)
'storage_ref_with_lookup', rid, iwait_timeout, {bids[1], bids[2]})
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {rid = rid, moved = {}})
res, err = ivshard.storage._call('storage_unref', rid)
ilt.assert_equals(err, nil)

-- Check for double referencing.
res, err = ivshard.storage._call(
'storage_ref_with_lookup',
rid,
timeout,
{bids[1], bids[1]}
)
'storage_ref_with_lookup', rid, iwait_timeout, {bids[1], bids[1]})
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {rid = rid, moved = {}})
ilt.assert_equals(lref.count, 1)
res, err = ivshard.storage._call('storage_unref', rid)
ilt.assert_equals(err, nil)
res, err = ivshard.storage._call('storage_unref', rid)
t.assert_str_contains(err.message, 'Can not delete a storage ref: no ref')
ilt.assert_equals(lref.count, 0)

-- Check for an absent bucket.
-- Bucket mix.
res, err = ivshard.storage._call(
'storage_ref_with_lookup',
rid,
timeout,
{bids[1], bids[2], bid_extra}
)
'storage_ref_with_lookup', rid, iwait_timeout,
{bucket_count + 1, bids[1], bucket_count + 2, bids[2],
bucket_count + 3})
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {rid = rid, moved = {bid_extra}})
ilt.assert_equals(res, {
rid = rid,
moved = {bucket_count + 1, bucket_count + 2, bucket_count + 3}
})
res, err = ivshard.storage._call('storage_unref', rid)
ilt.assert_equals(err, nil)

-- Check that we do not create a reference if there are no buckets.
-- No ref when all buckets are missing.
res, err = ivshard.storage._call(
'storage_ref_with_lookup',
rid,
timeout,
{bid_extra}
iwait_timeout,
{bucket_count + 1, bucket_count + 2}
)
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {rid = nil, moved = {bid_extra}})
res, err = vshard.storage._call('storage_unref', rid)
t.assert_str_contains(err.message, 'Can not delete a storage ref: no ref')
ilt.assert_equals(res, nil)
ilt.assert_equals(res, {moved = {bucket_count + 1, bucket_count + 2}})
ilt.assert_equals(lref.count, 0)

-- Check for a timeout.
-- Emulate a case when all buckets are not writable.
local func = ivshard.storage.internal.bucket_are_all_rw
ivshard.storage.internal.bucket_are_all_rw = function() return false end
-- Timeout when some buckets aren't writable. Doesn't have to be the
-- same buckets as for moving.
box.space._bucket:update({bids[1]}, {{'=', 'status', ivconst.BUCKET.SENDING}})
res, err = ivshard.storage._call(
'storage_ref_with_lookup',
rid,
timeout,
{bids[1]}
)
ivshard.storage.internal.bucket_are_all_rw = func
'storage_ref_with_lookup', rid, 0.01, {bids[2]})
box.space._bucket:update({bids[1]}, {{'=', 'status', ivconst.BUCKET.ACTIVE}})
t.assert_str_contains(err.message, 'Timeout exceeded')
ilt.assert_equals(res, nil)
-- Check that the reference was not created.
res, err = ivshard.storage._call('storage_unref', rid)
t.assert_str_contains(err.message, 'Can not delete a storage ref: no ref')
ilt.assert_equals(res, nil)
ilt.assert_equals(lref.count, 0)
end)
end

Expand All @@ -325,15 +313,13 @@ test_group.test_absent_buckets = function(g)
)
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {moved = {}})
end)

g.replica_1_a:exec(function()
local bid_extra = 3001
local res, err = ivshard.storage._call(
local bucket_count = ivshard.storage.internal.total_bucket_count
res, err = ivshard.storage._call(
'storage_absent_buckets',
{_G.get_first_bucket(), bid_extra}
{_G.get_first_bucket(), bucket_count + 1, bucket_count + 2}
)
ilt.assert_equals(err, nil)
ilt.assert_equals(res, {moved = {bid_extra}})
ilt.assert_equals(res, {moved = {bucket_count + 1, bucket_count + 2}})
end)
end
Loading

0 comments on commit 93ff41b

Please sign in to comment.