@@ -21,6 +21,11 @@ local cache_group = t.group('ddl_sharding_func_cache', {
2121 {engine = ' vinyl' },
2222})
2323
24+ local vshard_group = t .group (' ddl_vshard_sharding_func' , {
25+ {engine = ' memtx' },
26+ {engine = ' vinyl' },
27+ })
28+
2429pgroup .before_all (function (g )
2530 g .cluster = helpers .Cluster :new ({
2631 datadir = fio .tempdir (),
@@ -77,6 +82,35 @@ cache_group.before_each(function(g)
7782 helpers .truncate_space_on_cluster (g .cluster , ' customers_body_func' )
7883end )
7984
85+ vshard_group .before_all (function (g )
86+ g .cluster = helpers .Cluster :new ({
87+ datadir = fio .tempdir (),
88+ server_command = helpers .entrypoint (' srv_ddl' ),
89+ use_vshard = true ,
90+ replicasets = helpers .get_test_replicasets (),
91+ env = {
92+ [' ENGINE' ] = g .params .engine ,
93+ },
94+ })
95+ g .cluster :start ()
96+ local result , err = g .cluster .main_server .net_box :eval ([[
97+ local ddl = require('ddl')
98+
99+ local ok, err = ddl.get_schema()
100+ return ok, err
101+ ]] )
102+ t .assert_equals (type (result ), ' table' )
103+ t .assert_equals (err , nil )
104+ end )
105+
106+ vshard_group .after_all (function (g ) helpers .stop_cluster (g .cluster ) end )
107+
108+ vshard_group .before_each (function (g )
109+ helpers .truncate_space_on_cluster (g .cluster , ' customers_vshard_mpcrc32' )
110+ helpers .truncate_space_on_cluster (g .cluster , ' customers_vshard_strcrc32' )
111+ helpers .truncate_space_on_cluster (g .cluster , ' customers_empty_sharding_func' )
112+ end )
113+
80114pgroup .test_insert_object = function (g )
81115 local result , err = g .cluster .main_server .net_box :call (
82116 ' crud.insert_object' , {g .params .space_name , {id = 158 , name = ' Augustus' , age = 48 }})
@@ -703,7 +737,7 @@ cache_group.test_update_cache_with_incorrect_func = function(g)
703737
704738 -- records for all spaces exist
705739 local cache_size = helpers .get_sharding_func_cache_size (g .cluster )
706- t .assert_equals (cache_size , 2 )
740+ t .assert_equals (cache_size , 4 )
707741
708742 -- no error just warning
709743 local space_name = ' customers_G_func'
@@ -719,7 +753,7 @@ cache_group.test_update_cache_with_incorrect_func = function(g)
719753 -- cache['customers_G_func'] == nil (space with incorrect func)
720754 -- other records for correct spaces exist in cache
721755 cache_size = helpers .get_sharding_func_cache_size (g .cluster )
722- t .assert_equals (cache_size , 1 )
756+ t .assert_equals (cache_size , 3 )
723757
724758 -- get data from cache for space with incorrect sharding func
725759 local space_name = ' customers_G_func'
@@ -736,7 +770,7 @@ cache_group.test_update_cache_with_incorrect_func = function(g)
736770 -- cache['customers_G_func'] == nil (space with incorrect func)
737771 -- other records for correct spaces exist in cache
738772 cache_size = helpers .get_sharding_func_cache_size (g .cluster )
739- t .assert_equals (cache_size , 1 )
773+ t .assert_equals (cache_size , 3 )
740774end
741775
742776
@@ -938,3 +972,83 @@ pgroup.test_gh_278_count_with_explicit_bucket_id_and_ddl = function(g)
938972 t .assert_is_not (obj , nil )
939973 t .assert_equals (obj , 1 )
940974end
975+
976+ local vshard_cases = {
977+ mpcrc32_not_depends_on_ddl = {
978+ set_sharding_func_to_ddl_space = true ,
979+ space_name = ' customers_empty_sharding_func' ,
980+ sharding_func_name = ' vshard.router.bucket_id_mpcrc32' ,
981+ bucket_id = 1614 ,
982+ srv_with_data = ' s1-master' ,
983+ srv_without_data = ' s2-master' ,
984+ },
985+ strcrc32_not_depends_on_ddl = {
986+ set_sharding_func_to_ddl_space = true ,
987+ space_name = ' customers_empty_sharding_func' ,
988+ sharding_func_name = ' vshard.router.bucket_id_strcrc32' ,
989+ bucket_id = 477 ,
990+ srv_with_data = ' s2-master' ,
991+ srv_without_data = ' s1-master' ,
992+ },
993+ mpcrc32_depends_on_ddl = {
994+ space_name = ' customers_vshard_mpcrc32' ,
995+ sharding_func_name = ' vshard.router.bucket_id_mpcrc32' ,
996+ bucket_id = 1614 ,
997+ srv_with_data = ' s1-master' ,
998+ srv_without_data = ' s2-master' ,
999+ },
1000+ strcrc32_depends_on_ddl = {
1001+ space_name = ' customers_vshard_strcrc32' ,
1002+ sharding_func_name = ' vshard.router.bucket_id_strcrc32' ,
1003+ bucket_id = 477 ,
1004+ srv_with_data = ' s2-master' ,
1005+ srv_without_data = ' s1-master' ,
1006+ }
1007+ }
1008+
1009+ for name , case in pairs (vshard_cases ) do
1010+ local test_name = (' test_vshard_%s' ):format (name )
1011+
1012+ vshard_group [test_name ] = function (g )
1013+ local space_name = case .space_name
1014+
1015+ if case .set_sharding_func_to_ddl_space then
1016+ local fieldno_sharding_func_name = 2
1017+
1018+ helpers .call_on_servers (g .cluster , {' s1-master' , ' s2-master' }, function (server )
1019+ server .net_box :call (' set_sharding_func' ,
1020+ {space_name , fieldno_sharding_func_name , case .sharding_func_name })
1021+ end )
1022+
1023+ local record_exist , err = helpers .update_sharding_func_cache (g .cluster , space_name )
1024+ t .assert_equals (err , nil )
1025+ t .assert_equals (record_exist , true )
1026+ end
1027+
1028+ -- Insert a tuple.
1029+ local result , err = g .cluster .main_server .net_box :call (
1030+ ' crud.insert' , {space_name , {1 , box .NULL , ' Ivan' , 25 }})
1031+ t .assert_equals (err , nil )
1032+ t .assert_equals (# result .rows , 1 )
1033+ t .assert_equals (result .rows [1 ], {1 , case .bucket_id , ' Ivan' , 25 })
1034+
1035+ -- There is a tuple on server that we inserted with crud.insert().
1036+ local conn_srv_with_data = g .cluster :server (case .srv_with_data ).net_box
1037+ local result = conn_srv_with_data .space [space_name ]:get ({1 })
1038+ t .assert_equals (result , {1 , case .bucket_id , ' Ivan' , 25 })
1039+
1040+ -- There is no tuple on server that we inserted with crud.insert().
1041+ local conn_srv_without_data = g .cluster :server (case .srv_without_data ).net_box
1042+ local result = conn_srv_without_data .space [space_name ]:get ({1 })
1043+ t .assert_equals (result , nil )
1044+
1045+ local conditions = {{' ==' , ' id' , 1 }}
1046+ local result , err = g .cluster .main_server .net_box :call (' crud.select' , {
1047+ space_name , conditions ,
1048+ })
1049+
1050+ t .assert_equals (err , nil )
1051+ t .assert_equals (# result .rows , 1 )
1052+ t .assert_equals (result .rows [1 ], {1 , case .bucket_id , ' Ivan' , 25 })
1053+ end
1054+ end
0 commit comments