Skip to content

Commit 6ce04a5

Browse files
committed
Support reset of cache with sharding keys
Part of #166
1 parent fec0de8 commit 6ce04a5

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

crud/common/sharding_key.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ function sharding_key_module.fetch_on_router(space_name)
116116
return cache.sharding_key_def
117117
end
118118

119+
function sharding_key_module.update_sharding_keys_cache(space_name)
120+
cache.drop_caches()
121+
return sharding_key_module.fetch_on_router(space_name)
122+
end
123+
119124
-- Make sure sharding key definition is a part of primary key.
120125
function sharding_key_module.is_part_of_pk(space_name, space_format,
121126
primary_index, sharding_key_def)

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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,3 +547,43 @@ pgroup.test_delete_secondary_idx = function(g)
547547
"Sharding key for space \"customers_secondary_idx_name_key\" is missed in primary index, specify bucket_id")
548548
t.assert_equals(result, nil)
549549
end
550+
551+
pgroup.test_update_sharding_keys_cache = function(g)
552+
local space_name = 'customers_name_key'
553+
local sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
554+
t.assert_equals(sharding_key, {'name'})
555+
556+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
557+
server.net_box:call('set_sharding_key', {space_name, {'age'}})
558+
end)
559+
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
560+
t.assert_equals(sharding_key, {'age'})
561+
562+
-- Recover sharding key.
563+
helpers.call_on_servers(g.cluster, {'s1-master', 's2-master'}, function(server)
564+
server.net_box:call('set_sharding_key', {space_name, {'name'}})
565+
end)
566+
sharding_key = helpers.update_sharding_keys_cache(g.cluster, space_name)
567+
t.assert_equals(sharding_key, {'name'})
568+
end
569+
570+
pgroup.test_non_unique_index = function(g)
571+
local space_name = 'customers_name_key_non_uniq_index'
572+
local tuple = {6, box.NULL, 'Victor', 58}
573+
574+
-- insert tuple
575+
local result, err = g.cluster.main_server.net_box:call('crud.insert', {
576+
space_name, tuple
577+
})
578+
579+
t.assert_equals(err, nil)
580+
t.assert_not_equals(result, nil)
581+
t.assert_equals(#result.rows, 1)
582+
583+
local result, err = g.cluster.main_server.net_box:call('crud.select', {
584+
space_name, {{'==', 'name', 'Victor'}}
585+
})
586+
t.assert_equals(err, nil)
587+
t.assert_not_equals(result, nil)
588+
t.assert_equals(#result.rows, 1)
589+
end

0 commit comments

Comments
 (0)