From 16044878ac60d634f6cadd7c7ddaa19ca3f1cdc0 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 acdcad98e..6f35af6a3 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 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