diff --git a/crud/common/sharding_key.lua b/crud/common/sharding_key.lua index 01f4ad86c..39b3cbd3a 100644 --- a/crud/common/sharding_key.lua +++ b/crud/common/sharding_key.lua @@ -122,6 +122,11 @@ function sharding_key_module.fetch_on_router(space_name) return cache.sharding_key_def[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. diff --git a/test/helper.lua b/test/helper.lua index 4c56385bb..80e5649a4 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -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 diff --git a/test/integration/ddl_sharding_key_test.lua b/test/integration/ddl_sharding_key_test.lua index 4de975846..66d189214 100644 --- a/test/integration/ddl_sharding_key_test.lua +++ b/test/integration/ddl_sharding_key_test.lua @@ -546,3 +546,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