Skip to content

Commit b9fcbff

Browse files
api: forbid using space id in len
Using space id instead of a space name in sharded systems may be dangerous until one sets all space id manually. This is a breaking change. The feature was deprecated since 0.14.0. Closes #255
1 parent 5717e87 commit b9fcbff

File tree

3 files changed

+2
-71
lines changed

3 files changed

+2
-71
lines changed

crud/len.lua

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,23 +42,13 @@ end
4242
-- @treturn[2] table Error description
4343
--
4444
function len.call(space_name, opts)
45-
checks('string|number', {
45+
checks('string', {
4646
timeout = '?number',
4747
vshard_router = '?string|table',
4848
})
4949

5050
opts = opts or {}
5151

52-
if type(space_name) == 'number' then
53-
log.warn('Using space id in crud.len is deprecated and will be removed in future releases.' ..
54-
'Please, use space name instead.')
55-
56-
if opts.vshard_router ~= nil then
57-
log.warn('Using space id in crud.len and custom vshard_router is not supported by statistics.' ..
58-
'Space labels may be inconsistent.')
59-
end
60-
end
61-
6252
local vshard_router, err = utils.get_vshard_router_instance(opts.vshard_router)
6353
if err ~= nil then
6454
return nil, LenError:new(err)

crud/stats/init.lua

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -249,34 +249,6 @@ function stats.get(space_name)
249249
return internal:get_registry().get(space_name)
250250
end
251251

252-
local function resolve_space_name(space_id)
253-
-- Resolving name with custom vshard router is not supported.
254-
local vshard_router = vshard.router.static
255-
256-
if vshard_router == nil then
257-
log.warn('Failed to resolve space name for stats: default vshard router not found')
258-
return nil
259-
end
260-
261-
local replicasets = vshard_router:routeall()
262-
if next(replicasets) == nil then
263-
log.warn('Failed to resolve space name for stats: no replicasets found with default router')
264-
return nil
265-
end
266-
267-
local space, err = utils.get_space(space_id, vshard_router)
268-
if err ~= nil then
269-
log.warn("An error occurred during getting space: %s", err)
270-
return nil
271-
end
272-
if space == nil then
273-
log.warn('Failed to resolve space name for stats: no space found for id %d with default router', space_id)
274-
return nil
275-
end
276-
277-
return space.name
278-
end
279-
280252
-- Hack to set __gc for a table in Lua 5.1
281253
-- See https://stackoverflow.com/questions/27426704/lua-5-1-workaround-for-gc-metamethod-for-tables
282254
-- or https://habr.com/ru/post/346892/
@@ -351,26 +323,13 @@ local function wrap_pairs_gen(build_latency, space_name, op, gen, param, state)
351323
end
352324

353325
local function wrap_tail(space_name, op, pairs, start_time, call_status, ...)
354-
dev_checks('string|number', 'string', 'boolean', 'number', 'boolean')
326+
dev_checks('string', 'string', 'boolean', 'number', 'boolean')
355327

356328
local finish_time = clock.monotonic()
357329
local latency = finish_time - start_time
358330

359331
local registry = internal:get_registry()
360332

361-
-- If space id is provided instead of name, try to resolve name.
362-
-- If resolve have failed, use id as string to observe space.
363-
-- If using space id will be deprecated, remove this code as well,
364-
-- see https://github.com/tarantool/crud/issues/255
365-
if type(space_name) ~= 'string' then
366-
local name = resolve_space_name(space_name)
367-
if name ~= nil then
368-
space_name = name
369-
else
370-
space_name = tostring(space_name)
371-
end
372-
end
373-
374333
if call_status == false then
375334
registry.observe(latency, space_name, op, 'error')
376335
error((...), 2)

test/integration/stats_test.lua

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -752,24 +752,6 @@ for name, case in pairs(select_cases) do
752752
end
753753

754754

755-
pgroup.test_resolve_name_from_id = function(g)
756-
local op = 'len'
757-
g.router:call('crud.len', { space_id })
758-
759-
local stats = get_stats(g, space_name)
760-
t.assert_not_equals(stats[op], nil, "Statistics is filled by name")
761-
end
762-
763-
764-
pgroup.test_resolve_nonexisting_space_from_id = function(g)
765-
local op = 'len'
766-
g.router:call('crud.len', { non_existing_space_id })
767-
768-
local stats = get_stats(g, tostring(non_existing_space_id))
769-
t.assert_not_equals(stats[op], nil, "Statistics is filled by id as string")
770-
end
771-
772-
773755
pgroup.before_test(
774756
'test_role_reload_do_not_reset_observations',
775757
generate_stats)

0 commit comments

Comments
 (0)