Skip to content

Commit 8343c8f

Browse files
committed
Support reset of cache with sharding keys
Part of #166
1 parent 6c60c0d commit 8343c8f

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
@@ -136,6 +136,11 @@ function sharding_key_module.fetch_on_router(space_name)
136136
return cache.sharding_key_as_index_obj_map[space_name]
137137
end
138138

139+
function sharding_key_module.update_cache(space_name)
140+
cache.drop_caches()
141+
return sharding_key_module.fetch_on_router(space_name)
142+
end
143+
139144
-- Make sure sharding key definition is a part of primary key.
140145
local function is_part_of_pk(space_name, primary_index_parts, sharding_key_as_index_obj)
141146
dev_checks('string', 'table', 'table')

test/helper.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,4 +323,13 @@ function helpers.tarantool_version_at_least(wanted_major, wanted_minor,
323323
return true
324324
end
325325

326+
function helpers.update_cache(cluster, space_name)
327+
return cluster.main_server.net_box:eval([[
328+
local sharding_key = require('crud.common.sharding_key')
329+
330+
local space_name = ...
331+
return sharding_key.update_cache(space_name)
332+
]], {space_name})
333+
end
334+
326335
return helpers

test/integration/ddl_sharding_key_test.lua

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

0 commit comments

Comments
 (0)