Skip to content

Commit 80abe08

Browse files
committed
Support reset of cache with sharding keys
Part of #166
1 parent 212b784 commit 80abe08

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

crud/common/sharding_key.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ function sharding_key_module.fetch_on_router(space_name)
121121
return cache.sharding_key_def_map[space_name]
122122
end
123123

124+
function sharding_key_module.update_sharding_keys_cache(space_name)
125+
cache.drop_caches()
126+
return sharding_key_module.fetch_on_router(space_name)
127+
end
128+
124129
-- Make sure sharding key definition is a part of primary key.
125130
local function is_part_of_pk(space_name, primary_index_parts, sharding_key_as_index_obj)
126131
dev_checks('string', 'table', 'table')

test/helper.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,13 @@ function helpers.get_other_storage_bucket_id(cluster, bucket_id)
230230
]], {bucket_id})
231231
end
232232

233+
function helpers.update_sharding_keys_cache(cluster, space_name)
234+
return cluster.main_server.net_box:eval([[
235+
local sharding_key = require('crud.common.sharding_key')
236+
237+
local space_name = ...
238+
return sharding_key.update_sharding_keys_cache(space_name)
239+
]], {space_name})
240+
end
241+
233242
return helpers

test/integration/ddl_sharding_key_test.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,3 +550,22 @@ pgroup.test_delete_secondary_idx = function(g)
550550
"Sharding key for space \"customers_secondary_idx_name_key\" is missed in primary index, specify bucket_id")
551551
t.assert_equals(result, nil)
552552
end
553+
554+
pgroup.test_update_sharding_keys_cache = function(g)
555+
local space_name = 'customers_name_key'
556+
local sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
557+
t.assert_equals(sharding_key, {'name'})
558+
559+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
560+
server.net_box:call('set_sharding_key', {space_name, {'age'}})
561+
end)
562+
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
563+
t.assert_equals(sharding_key, {'age'})
564+
565+
-- Recover sharding key.
566+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
567+
server.net_box:call('set_sharding_key', {space_name, {'name'}})
568+
end)
569+
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
570+
t.assert_equals(sharding_key, {'name'})
571+
end

0 commit comments

Comments
 (0)