From b8465f3b3d9bdc66482c1f47c86f53889cfd05c7 Mon Sep 17 00:00:00 2001 From: Georgy Moiseev Date: Fri, 19 Aug 2022 09:52:55 +0300 Subject: [PATCH] stats: warn for using id with custom router 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 --- README.md | 3 +++ crud/len.lua | 5 +++++ crud/stats/init.lua | 1 + test/entrypoint/srv_vshard_custom.lua | 1 + test/integration/vshard_custom_test.lua | 29 +++++++++++++++++++++++++ 5 files changed, 39 insertions(+) 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)