diff --git a/crud/common/sharding_key.lua b/crud/common/sharding_key.lua index 7e906c26..c7afd660 100644 --- a/crud/common/sharding_key.lua +++ b/crud/common/sharding_key.lua @@ -135,6 +135,11 @@ function sharding_key_module.fetch_on_router(space_name) return cache.sharding_key_as_index_obj_map[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') diff --git a/test/helper.lua b/test/helper.lua index 4c56385b..417c5bae 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_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 diff --git a/test/integration/ddl_sharding_key_test.lua b/test/integration/ddl_sharding_key_test.lua index 06ff85f9..3e687eae 100644 --- a/test/integration/ddl_sharding_key_test.lua +++ b/test/integration/ddl_sharding_key_test.lua @@ -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_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