| 
 | 1 | +local fio = require('fio')  | 
 | 2 | + | 
 | 3 | +local t = require('luatest')  | 
 | 4 | + | 
 | 5 | +local helpers = require('test.helper')  | 
 | 6 | + | 
 | 7 | +local pgroup = t.group('migration', {  | 
 | 8 | +    {engine = 'memtx'},  | 
 | 9 | +    {engine = 'vinyl'},  | 
 | 10 | +})  | 
 | 11 | + | 
 | 12 | +pgroup.before_all(function(g)  | 
 | 13 | +    g.cluster = helpers.Cluster:new({  | 
 | 14 | +        datadir = fio.tempdir(),  | 
 | 15 | +        server_command = helpers.entrypoint('srv_migration'),  | 
 | 16 | +        use_vshard = true,  | 
 | 17 | +        replicasets = helpers.get_test_replicasets(),  | 
 | 18 | +        env = {  | 
 | 19 | +            ['ENGINE'] = g.params.engine,  | 
 | 20 | +        },  | 
 | 21 | +    })  | 
 | 22 | +    g.cluster:start()  | 
 | 23 | +end)  | 
 | 24 | + | 
 | 25 | +pgroup.after_all(function(g) helpers.stop_cluster(g.cluster) end)  | 
 | 26 | + | 
 | 27 | +pgroup.test_gh_308_select_after_improper_ddl_space_drop = function(g)  | 
 | 28 | +    -- Create a space sharded by key with ddl tools.  | 
 | 29 | +    helpers.call_on_storages(g.cluster, function(server)  | 
 | 30 | +        server.net_box:eval([[  | 
 | 31 | +            local migrator_utils = require('migrator.utils')  | 
 | 32 | +
  | 
 | 33 | +            if not box.info.ro then  | 
 | 34 | +                box.schema.space.create('customers_v2')  | 
 | 35 | +
  | 
 | 36 | +                box.space['customers_v2']:format{  | 
 | 37 | +                    {name = 'id_v2',        is_nullable = false, type = 'unsigned'},  | 
 | 38 | +                    {name = 'bucket_id',    is_nullable = false, type = 'unsigned'},  | 
 | 39 | +                    {name = 'sharding_key', is_nullable = false, type = 'unsigned'},  | 
 | 40 | +                }  | 
 | 41 | +
  | 
 | 42 | +                box.space['customers_v2']:create_index('pk',        {parts = { 'id_v2' }})  | 
 | 43 | +                box.space['customers_v2']:create_index('bucket_id', {parts = { 'bucket_id' }})  | 
 | 44 | +
  | 
 | 45 | +                migrator_utils.register_sharding_key('customers_v2', {'sharding_key'})  | 
 | 46 | +            end  | 
 | 47 | +        ]])  | 
 | 48 | +    end)  | 
 | 49 | + | 
 | 50 | +    -- Do not do any requests to refresh sharding metadata.  | 
 | 51 | + | 
 | 52 | +    -- Drop space, but do not clean up ddl sharding data.  | 
 | 53 | +    helpers.call_on_storages(g.cluster, function(server)  | 
 | 54 | +        server.net_box:eval([[  | 
 | 55 | +            if not box.info.ro then  | 
 | 56 | +                box.space['customers_v2']:drop()  | 
 | 57 | +            end  | 
 | 58 | +        ]])  | 
 | 59 | +    end)  | 
 | 60 | + | 
 | 61 | +    -- Ensure that crud request for existing space is ok.  | 
 | 62 | +    local _, err = g.cluster.main_server.net_box:call('crud.select',  | 
 | 63 | +                                                      {'customers', nil, { first = 1 }})  | 
 | 64 | +    t.assert_equals(err, nil)  | 
 | 65 | +end  | 
0 commit comments