Skip to content

Commit 804d4e1

Browse files
committed
Support reset of cache with sharding keys
It's possible to drop cache with structures used for secondary sharding keys support with command "require('crud.sharding_key').update_sharding_keys_cache()". Part of #166 Reviewed-by: Oleg Babin <[email protected]> Reviewed-by: Alexander Turenko <[email protected]>
1 parent b9b1692 commit 804d4e1

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
@@ -152,6 +152,11 @@ function sharding_key_module.fetch_on_router(space_name, timeout)
152152
"Fetching sharding key for space '%s' is failed", space_name)
153153
end
154154

155+
function sharding_key_module.update_cache(space_name)
156+
cache.drop_caches()
157+
return sharding_key_module.fetch_on_router(space_name)
158+
end
159+
155160
-- Make sure sharding key definition is a part of primary key.
156161
local function is_part_of_pk(space_name, primary_index_parts, sharding_key_as_index_obj)
157162
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
@@ -591,3 +591,22 @@ pgroup.test_delete_secondary_idx = function(g)
591591
"Sharding key for space \"customers_secondary_idx_name_key\" is missed in primary index, specify bucket_id")
592592
t.assert_equals(result, nil)
593593
end
594+
595+
pgroup.test_update_cache = function(g)
596+
local space_name = 'customers_name_key'
597+
local sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
598+
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 3}}})
599+
600+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
601+
server.net_box:call('set_sharding_key', {space_name, {'age'}})
602+
end)
603+
sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
604+
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 4}}})
605+
606+
-- Recover sharding key.
607+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
608+
server.net_box:call('set_sharding_key', {space_name, {'name'}})
609+
end)
610+
sharding_key_as_index_obj = helpers.update_cache(g.cluster, space_name)
611+
t.assert_equals(sharding_key_as_index_obj, {parts = {{fieldno = 3}}})
612+
end

0 commit comments

Comments
 (0)