Skip to content

Commit c3ffcb0

Browse files
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
1 parent 77acc40 commit c3ffcb0

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,6 +1082,9 @@ Returns number or nil with error.
10821082
Using space id instead of space name is also possible, but
10831083
deprecated and will be removed in future releases.
10841084

1085+
Using space id in crud.len and custom vshard_router is not
1086+
supported by statistics: space labels may be inconsistent.
1087+
10851088
**Example:**
10861089

10871090
Using `memtx`:

crud/len.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ function len.call(space_name, opts)
5252
if type(space_name) == 'number' then
5353
log.warn('Using space id in crud.len is deprecated and will be removed in future releases.' ..
5454
'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
5560
end
5661

5762
local vshard_router, err = utils.get_vshard_router_instance(opts.vshard_router)

crud/stats/init.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ function stats.get(space_name)
250250
end
251251

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

255256
if vshard_router == nil then

test/entrypoint/srv_vshard_custom.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package.preload['customers-storage'] = function()
2424
},
2525
if_not_exists = true,
2626
engine = engine,
27+
id = 542,
2728
})
2829

2930
customers_space:create_index('pk', {

test/integration/vshard_custom_test.lua

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local fio = require('fio')
22

33
local t = require('luatest')
4+
local luatest_capture = require('luatest.capture')
45

56
local helpers = require('test.helper')
67

@@ -1629,3 +1630,31 @@ pgroup.test_call_upsert_object_many_wrong_option = function(g)
16291630
t.assert_str_contains(errs[1].err,
16301631
"Invalid opts.vshard_router table value, a vshard router instance has been expected")
16311632
end
1633+
1634+
pgroup.before_test('test_call_len_by_space_id_with_stats', function(g)
1635+
g.router:eval('crud.cfg{stats = true}')
1636+
end)
1637+
1638+
pgroup.test_call_len_by_space_id_with_stats = function(g)
1639+
local capture = luatest_capture:new()
1640+
capture:enable()
1641+
1642+
local result, err = g:call_router_opts2('len', 542, {vshard_router = 'customers'})
1643+
t.assert_equals(err, nil)
1644+
t.assert_equals(result, 2)
1645+
1646+
local captured = helpers.fflush_main_server_stdout(g.cluster, capture)
1647+
capture:disable()
1648+
1649+
t.assert_str_contains(captured,
1650+
"Using space id in crud.len and custom vshard_router is not supported by statistics.")
1651+
1652+
local result, err = g.router:call('crud.stats')
1653+
t.assert_equals(err, nil)
1654+
t.assert_type(result.spaces["542"], 'table')
1655+
t.assert_equals(result.spaces["542"]["len"]["ok"]["count"], 1)
1656+
end
1657+
1658+
pgroup.after_test('test_call_len_by_space_id_with_stats', function(g)
1659+
g.router:eval('crud.cfg{stats = false}')
1660+
end)

0 commit comments

Comments
 (0)