From 80abe08f177413e2c0dfc771d99f25182b14647b Mon Sep 17 00:00:00 2001 From: Sergey Bronnikov Date: Thu, 16 Sep 2021 11:25:27 +0300 Subject: [PATCH] Support reset of cache with sharding keys Part of #166 --- crud/common/sharding_key.lua | 5 +++++ test/helper.lua | 9 +++++++++ test/integration/ddl_sharding_key_test.lua | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/crud/common/sharding_key.lua b/crud/common/sharding_key.lua index 145e8b1b9..d7e5068a8 100644 --- a/crud/common/sharding_key.lua +++ b/crud/common/sharding_key.lua @@ -121,6 +121,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. 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 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 06ff85f9d..ed0b42335 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_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