diff --git a/crud/common/sharding_key.lua b/crud/common/sharding_key.lua index 27adf7830..f0b8c0232 100644 --- a/crud/common/sharding_key.lua +++ b/crud/common/sharding_key.lua @@ -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') diff --git a/test/helper.lua b/test/helper.lua index 64f6b48f7..913aa56ca 100644 --- a/test/helper.lua +++ b/test/helper.lua @@ -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 diff --git a/test/integration/ddl_sharding_key_test.lua b/test/integration/ddl_sharding_key_test.lua index 670a775bb..3bdaf67b6 100644 --- a/test/integration/ddl_sharding_key_test.lua +++ b/test/integration/ddl_sharding_key_test.lua @@ -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