diff --git a/README.md b/README.md index ff37064f..eeb410f0 100644 --- a/README.md +++ b/README.md @@ -1082,6 +1082,9 @@ Returns number or nil with error. Using space id instead of space name is also possible, but deprecated and will be removed in future releases. +Using space id in crud.len and custom vshard_router is not +supported by statistics: space labels may be inconsistent. + **Example:** Using `memtx`: diff --git a/crud/len.lua b/crud/len.lua index 27d387f8..68db4ed9 100644 --- a/crud/len.lua +++ b/crud/len.lua @@ -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) diff --git a/crud/stats/init.lua b/crud/stats/init.lua index 994e4440..a08008b2 100644 --- a/crud/stats/init.lua +++ b/crud/stats/init.lua @@ -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 diff --git a/test/entrypoint/srv_vshard_custom.lua b/test/entrypoint/srv_vshard_custom.lua index 7cbf8168..47426377 100755 --- a/test/entrypoint/srv_vshard_custom.lua +++ b/test/entrypoint/srv_vshard_custom.lua @@ -24,6 +24,7 @@ package.preload['customers-storage'] = function() }, if_not_exists = true, engine = engine, + id = 542, }) customers_space:create_index('pk', { diff --git a/test/integration/vshard_custom_test.lua b/test/integration/vshard_custom_test.lua index c5801b7a..0b194438 100644 --- a/test/integration/vshard_custom_test.lua +++ b/test/integration/vshard_custom_test.lua @@ -1,6 +1,7 @@ local fio = require('fio') local t = require('luatest') +local luatest_capture = require('luatest.capture') local helpers = require('test.helper') @@ -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)