Skip to content

Commit

Permalink
stats: warn for using id with custom router
Browse files Browse the repository at this point in the history
CRUD stats are separated by space name. If space id is passed instead of
name (only `crud.len` allows this), space name is resolved with net_box
schema. Since, after resolving #44, non-default vshard routers and
Cartridge vshard groups are supported, to resolve the name we must know
what vshard router should be used. Since using space id for `crud.len`
is deprecated now, we won't support name resolve for operations with
custom router statistics. Instead of this, a warning will be logged.
`crud.len` statistics will be signed by space name or space id casted to
string depending on is there a default router with space schema or not.

Follows up #44, part of #255
  • Loading branch information
DifferentialOrange committed Aug 26, 2022
1 parent 7853c1f commit 04bd845
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crud/len.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ function len.call(space_name, opts)
if type(space_name) == 'number' then
log.warn('Using space id in crud.len is deprecated and will be removed in future releases.' ..
'Please, use space name instead.')

if opts.vshard_router ~= nil then
log.warn('Using space id in crud.len and custom vshard_router is not supported by statistics.' ..
'Space labels may be inconsistent.')
end
end

local vshard_router, err = utils.get_vshard_router_instance(opts.vshard_router)
Expand Down
1 change: 1 addition & 0 deletions crud/stats/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ function stats.get(space_name)
end

local function resolve_space_name(space_id)
-- Resolving name with custom vshard router is not supported.
local vshard_router = vshard.router.static

if vshard_router == nil then
Expand Down
1 change: 1 addition & 0 deletions test/entrypoint/srv_vshard_custom.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package.preload['customers-storage'] = function()
},
if_not_exists = true,
engine = engine,
id = 542,
})

customers_space:create_index('pk', {
Expand Down
29 changes: 29 additions & 0 deletions test/integration/vshard_custom_test.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
local fio = require('fio')

local t = require('luatest')
local luatest_capture = require('luatest.capture')

local helpers = require('test.helper')

Expand Down Expand Up @@ -1629,3 +1630,31 @@ pgroup.test_call_upsert_object_many_wrong_option = function(g)
t.assert_str_contains(errs[1].err,
"Invalid opts.vshard_router table value, a vshard router instance has been expected")
end

pgroup.before_test('test_call_len_by_space_id_with_stats', function(g)
g.router:eval('crud.cfg{stats = true}')
end)

pgroup.test_call_len_by_space_id_with_stats = function(g)
local capture = luatest_capture:new()
capture:enable()

local result, err = g:call_router_opts2('len', 542, {vshard_router = 'customers'})
t.assert_equals(err, nil)
t.assert_equals(result, 2)

local captured = helpers.fflush_main_server_stdout(g.cluster, capture)
capture:disable()

t.assert_str_contains(captured,
"Using space id in crud.len and custom vshard_router is not supported by statistics.")

local result, err = g.router:call('crud.stats')
t.assert_equals(err, nil)
t.assert_type(result.spaces["542"], 'table')
t.assert_equals(result.spaces["542"]["len"]["ok"]["count"], 1)
end

pgroup.after_test('test_call_len_by_space_id_with_stats', function(g)
g.router:eval('crud.cfg{stats = false}')
end)

0 comments on commit 04bd845

Please sign in to comment.