Skip to content

Commit

Permalink
Support reset of cache with sharding keys
Browse files Browse the repository at this point in the history
Part of #166
  • Loading branch information
ligurio committed Sep 30, 2021
1 parent 2cb3f32 commit 40cc2ca
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 @@ -122,6 +122,11 @@ function sharding_key_module.fetch_on_router(space_name)
return cache.sharding_key_def_map[space_name]
end

function sharding_key_module.update_sharding_keys_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.
-- sharding_key_as_index_obj is not used in CRUD, it was added to be able to
-- use it in unit tests.
Expand Down
9 changes: 9 additions & 0 deletions test/helper.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,13 @@ function helpers.get_other_storage_bucket_id(cluster, bucket_id)
]], {bucket_id})
end

function helpers.update_sharding_keys_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_sharding_keys_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 @@ -550,3 +550,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_sharding_keys_cache = function(g)
local space_name = 'customers_name_key'
local sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
t.assert_equals(sharding_key, {'name'})

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 = helpers.update_sharding_keys_cache(g.cluster, space_name)
t.assert_equals(sharding_key, {'age'})

-- 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 = helpers.update_sharding_keys_cache(g.cluster, space_name)
t.assert_equals(sharding_key, {'name'})
end

0 comments on commit 40cc2ca

Please sign in to comment.