Skip to content

Commit 3703b24

Browse files
committed
Support reset of cache with sharding keys
Part of #166
1 parent 0f58042 commit 3703b24

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
@@ -122,6 +122,11 @@ function sharding_key_module.fetch_on_router(space_name)
122122
return cache.sharding_key_def[space_name]
123123
end
124124

125+
function sharding_key_module.update_sharding_keys_cache(space_name)
126+
cache.drop_caches()
127+
return sharding_key_module.fetch_on_router(space_name)
128+
end
129+
125130
-- Make sure sharding key definition is a part of primary key.
126131
-- sharding_key_as_index_obj is not used in CRUD, it was added to be able to
127132
-- use it in unit tests.

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
@@ -546,3 +546,22 @@ pgroup.test_delete_secondary_idx = function(g)
546546
"Sharding key for space \"customers_secondary_idx_name_key\" is missed in primary index, specify bucket_id")
547547
t.assert_equals(result, nil)
548548
end
549+
550+
pgroup.test_update_sharding_keys_cache = function(g)
551+
local space_name = 'customers_name_key'
552+
local sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
553+
t.assert_equals(sharding_key, {'name'})
554+
555+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
556+
server.net_box:call('set_sharding_key', {space_name, {'age'}})
557+
end)
558+
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
559+
t.assert_equals(sharding_key, {'age'})
560+
561+
-- Recover sharding key.
562+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
563+
server.net_box:call('set_sharding_key', {space_name, {'name'}})
564+
end)
565+
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
566+
t.assert_equals(sharding_key, {'name'})
567+
end

0 commit comments

Comments
 (0)