Skip to content

Commit

Permalink
Support reset of cache with sharding keys
Browse files Browse the repository at this point in the history
It's possible to drop cache with structures used for secondary sharding
keys support with command "require('crud.sharding_key').update_sharding_keys_cache()".

Part of #166

Reviewed-by: Oleg Babin <[email protected]>
Reviewed-by: Alexander Turenko <[email protected]>
  • Loading branch information
ligurio committed Nov 26, 2021
1 parent 447b81b commit 76439df
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions crud/common/sharding_key.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ function sharding_key_module.fetch_on_router(space_name, timeout)
"Fetching sharding key for space '%s' is failed", space_name)
end

function sharding_key_module.update_cache(space_name)
cache.drop_caches()
return sharding_key_module.fetch_on_router(space_name)
end

-- Make sure sharding key definition is a part of primary key.
local function is_part_of_pk(space_name, primary_index_parts, sharding_key_as_index_obj)
dev_checks('string', 'table', 'table')
Expand Down
9 changes: 9 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,13 @@ function helpers.tarantool_version_at_least(wanted_major, wanted_minor,
return true
end

function helpers.update_cache(cluster, space_name)
return cluster.main_server.net_box:eval([[
local sharding_key = require('crud.common.sharding_key')
local space_name = ...
return sharding_key.update_cache(space_name)
]], {space_name})
end

return helpers
19 changes: 19 additions & 0 deletions test/integration/ddl_sharding_key_test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -591,3 +591,22 @@ pgroup.test_delete_secondary_idx = function(g)
"Sharding key for space \"customers_secondary_idx_name_key\" is missed in primary index, specify bucket_id")
t.assert_equals(result, nil)
end

pgroup.test_update_cache = function(g)
local space_name = 'customers_name_key'
local sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 3}}})

helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
server.net_box:call('set_sharding_key', {space_name, {'age'}})
end)
sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 4}}})

-- Recover sharding key.
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
server.net_box:call('set_sharding_key', {space_name, {'name'}})
end)
sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 3}}})
end

0 comments on commit 76439df

Please sign in to comment.