Skip to content

Commit

Permalink
test: wait for schema bootstrap
Browse files Browse the repository at this point in the history
The approach is similar to crud bootstrap waiting. Cartridge tests
approach remains the same.

Part of #412
Part of #415
  • Loading branch information
DifferentialOrange committed Jan 23, 2024
1 parent ed42abb commit e31a9d5
Show file tree
Hide file tree
Showing 57 changed files with 1,364 additions and 1,199 deletions.
5 changes: 4 additions & 1 deletion test/entrypoint/srv_batch_operations/cartridge_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@
require('strict').on()
_G.is_initialized = function() return false end

local fio = require('fio')
local log = require('log')
local errors = require('errors')
local cartridge = require('cartridge')

if package.setsearchroot ~= nil then
package.setsearchroot()
else
local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir()))))
package.path = package.path .. root .. "/?.lua;"
package.path = package.path .. debug.sourcedir() .. "/?.lua;"
end

package.preload['customers-storage'] = function()
return {
role_name = 'customers-storage',
init = require('storage_init'),
init = require('storage').init,
}
end

Expand Down
52 changes: 52 additions & 0 deletions test/entrypoint/srv_batch_operations/storage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
local helper = require('test.helper')

return {
init = helper.wrap_schema_init(function()
local engine = os.getenv('ENGINE') or 'memtx'
local customers_space = box.schema.space.create('customers', {
format = {
{name = 'id', type = 'unsigned'},
{name = 'bucket_id', type = 'unsigned'},
{name = 'name', type = 'string'},
{name = 'age', type = 'number'},
},
if_not_exists = true,
engine = engine,
})
customers_space:create_index('id', {
parts = { {field = 'id'} },
if_not_exists = true,
})
customers_space:create_index('bucket_id', {
parts = { {field = 'bucket_id'} },
unique = false,
if_not_exists = true,
})

local developers_space = box.schema.space.create('developers', {
format = {
{name = 'id', type = 'unsigned'},
{name = 'bucket_id', type = 'unsigned'},
{name = 'name', type = 'string'},
{name = 'login', type = 'string'},
},
if_not_exists = true,
engine = engine,
})
developers_space:create_index('id', {
parts = { {field = 'id'} },
if_not_exists = true,
})
developers_space:create_index('bucket_id', {
parts = { {field = 'bucket_id'} },
unique = false,
if_not_exists = true,
})
developers_space:create_index('login', {
parts = { {field = 'login'} },
unique = true,
if_not_exists = true,
})
end),
wait_until_ready = helper.wait_schema_init,
}
51 changes: 0 additions & 51 deletions test/entrypoint/srv_batch_operations/storage_init.lua

This file was deleted.

5 changes: 4 additions & 1 deletion test/entrypoint/srv_ddl/cartridge_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
require('strict').on()
_G.is_initialized = function() return false end

local fio = require('fio')
local log = require('log')
local errors = require('errors')
local cartridge = require('cartridge')

if package.setsearchroot ~= nil then
package.setsearchroot()
else
local root = fio.dirname(fio.dirname(fio.dirname(fio.dirname(debug.sourcedir()))))
package.path = package.path .. root .. "/?.lua;"
package.path = package.path .. debug.sourcedir() .. "/?.lua;"
end

Expand All @@ -18,7 +21,7 @@ package.preload['customers-storage'] = function()
-- in _G for sharding func tests
return {
role_name = 'customers-storage',
init = require('storage_init'),
init = require('storage').init,
}
end

Expand Down
13 changes: 13 additions & 0 deletions test/entrypoint/srv_ddl/router.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
return {
init = function()
local some_module = {
sharding_func =
function(key)
if key ~= nil and key[1] ~= nil then
return key[1] % 10
end
end
}
rawset(_G, 'some_module', some_module)
end,
}
11 changes: 0 additions & 11 deletions test/entrypoint/srv_ddl/router_init.lua

This file was deleted.

197 changes: 197 additions & 0 deletions test/entrypoint/srv_ddl/storage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
local ddl = require('ddl')
local helper = require('test.helper')

return {
init = function()
local some_module = {
sharding_func =
function(key)
if key ~= nil and key[1] ~= nil then
return key[1] % 10
end
end
}
rawset(_G, 'some_module', some_module)

local engine = os.getenv('ENGINE') or 'memtx'
local customers_schema = {
engine = engine,
is_local = true,
temporary = false,
format = {
{name = 'id', is_nullable = false, type = 'unsigned'},
{name = 'bucket_id', is_nullable = false, type = 'unsigned'},
{name = 'name', is_nullable = false, type = 'string'},
{name = 'age', is_nullable = false, type = 'number'},
},
indexes = {
-- This table is intentionally blank.
},
}

local primary_index = {
name = 'id',
type = 'TREE',
unique = true,
parts = {
{path = 'id', is_nullable = false, type = 'unsigned'},
{path = 'name', is_nullable = false, type = 'string'},
},
}
local primary_index_id = {
name = 'id',
type = 'TREE',
unique = true,
parts = {
{path = 'id', is_nullable = false, type = 'unsigned'},
},
}
local bucket_id_index = {
name = 'bucket_id',
type = 'TREE',
unique = false,
parts = {
{path = 'bucket_id', is_nullable = false, type = 'unsigned'},
}
}
local name_index = {
name = 'name',
type = 'TREE',
unique = true,
parts = {
{path = 'name', is_nullable = false, type = 'string'},
},
}
local age_index = {
name = 'age',
type = 'TREE',
unique = false,
parts = {
{path = 'age', is_nullable = false, type = 'number'},
},
}
local secondary_index = {
name = 'secondary',
type = 'TREE',
unique = false,
parts = {
{path = 'id', is_nullable = false, type = 'unsigned'},
{path = 'name', is_nullable = false, type = 'string'},
},
}

local three_fields_index = {
name = 'three_fields',
type = 'TREE',
unique = false,
parts = {
{path = 'age', is_nullable = false, type = 'number'},
{path = 'name', is_nullable = false, type = 'string'},
{path = 'id', is_nullable = false, type = 'unsigned'},
},
}

local customers_id_schema = table.deepcopy(customers_schema)
customers_id_schema.sharding_key = {'id'}
table.insert(customers_id_schema.indexes, primary_index_id)
table.insert(customers_id_schema.indexes, bucket_id_index)
table.insert(customers_id_schema.indexes, age_index)

local customers_name_key_schema = table.deepcopy(customers_schema)
customers_name_key_schema.sharding_key = {'name'}
table.insert(customers_name_key_schema.indexes, primary_index)
table.insert(customers_name_key_schema.indexes, bucket_id_index)

local customers_name_key_uniq_index_schema = table.deepcopy(customers_schema)
customers_name_key_uniq_index_schema.sharding_key = {'name'}
table.insert(customers_name_key_uniq_index_schema.indexes, primary_index)
table.insert(customers_name_key_uniq_index_schema.indexes, bucket_id_index)
table.insert(customers_name_key_uniq_index_schema.indexes, name_index)

local customers_name_key_non_uniq_index_schema = table.deepcopy(customers_schema)
customers_name_key_non_uniq_index_schema.sharding_key = {'name'}
name_index.unique = false
table.insert(customers_name_key_non_uniq_index_schema.indexes, primary_index)
table.insert(customers_name_key_non_uniq_index_schema.indexes, bucket_id_index)
table.insert(customers_name_key_non_uniq_index_schema.indexes, name_index)

local customers_secondary_idx_name_key_schema = table.deepcopy(customers_schema)
customers_secondary_idx_name_key_schema.sharding_key = {'name'}
table.insert(customers_secondary_idx_name_key_schema.indexes, primary_index_id)
table.insert(customers_secondary_idx_name_key_schema.indexes, secondary_index)
table.insert(customers_secondary_idx_name_key_schema.indexes, bucket_id_index)

local customers_age_key_schema = table.deepcopy(customers_schema)
customers_age_key_schema.sharding_key = {'age'}
table.insert(customers_age_key_schema.indexes, primary_index)
table.insert(customers_age_key_schema.indexes, bucket_id_index)

local customers_name_age_key_different_indexes_schema = table.deepcopy(customers_schema)
customers_name_age_key_different_indexes_schema.sharding_key = {'name', 'age'}
table.insert(customers_name_age_key_different_indexes_schema.indexes, primary_index)
table.insert(customers_name_age_key_different_indexes_schema.indexes, bucket_id_index)
table.insert(customers_name_age_key_different_indexes_schema.indexes, age_index)

local customers_name_age_key_three_fields_index_schema = table.deepcopy(customers_schema)
customers_name_age_key_three_fields_index_schema.sharding_key = {'name', 'age'}
table.insert(customers_name_age_key_three_fields_index_schema.indexes, primary_index_id)
table.insert(customers_name_age_key_three_fields_index_schema.indexes, bucket_id_index)
table.insert(customers_name_age_key_three_fields_index_schema.indexes, three_fields_index)

local customers_id_key_schema = table.deepcopy(customers_schema)
customers_id_key_schema.sharding_key = {'id'}
table.insert(customers_id_key_schema.indexes, primary_index)
table.insert(customers_id_key_schema.indexes, bucket_id_index)
table.insert(customers_id_key_schema.indexes, name_index)

local customers_body_func_schema = table.deepcopy(customers_id_key_schema)
customers_body_func_schema.sharding_func = { body = 'function(key) return key[1] % 10 end' }

local customers_G_func_schema = table.deepcopy(customers_id_key_schema)
customers_G_func_schema.sharding_func = 'some_module.sharding_func'

local customers_empty_sharding_func_schema = table.deepcopy(customers_id_key_schema)

local customers_vshard_mpcrc32_schema = table.deepcopy(customers_id_key_schema)
customers_vshard_mpcrc32_schema.sharding_func = 'vshard.router.bucket_id_mpcrc32'

local customers_vshard_strcrc32_schema = table.deepcopy(customers_id_key_schema)
customers_vshard_strcrc32_schema.sharding_func = 'vshard.router.bucket_id_strcrc32'

local schema = {
spaces = {
customers = customers_id_schema,
customers_name_key = customers_name_key_schema,
customers_name_key_uniq_index = customers_name_key_uniq_index_schema,
customers_name_key_non_uniq_index = customers_name_key_non_uniq_index_schema,
customers_secondary_idx_name_key = customers_secondary_idx_name_key_schema,
customers_age_key = customers_age_key_schema,
customers_name_age_key_different_indexes = customers_name_age_key_different_indexes_schema,
customers_name_age_key_three_fields_index = customers_name_age_key_three_fields_index_schema,
customers_G_func = customers_G_func_schema,
customers_body_func = customers_body_func_schema,
customers_empty_sharding_func = customers_empty_sharding_func_schema,
customers_vshard_mpcrc32 = customers_vshard_mpcrc32_schema,
customers_vshard_strcrc32 = customers_vshard_strcrc32_schema,
}
}

rawset(_G, 'set_sharding_key', function(space_name, sharding_key_def)
local fieldno_sharding_key = 2
box.space['_ddl_sharding_key']:update(space_name, {{'=', fieldno_sharding_key, sharding_key_def}})
end)
rawset(_G, 'set_sharding_func', function(space_name, fieldno_sharding_func, sharding_func_def)
local record = {space_name, box.NULL, box.NULL}
record[fieldno_sharding_func] = sharding_func_def
box.space['_ddl_sharding_func']:replace(record)
end)

helper.wrap_schema_init(function()
local ok, err = ddl.set_schema(schema)
if not ok then
error(err)
end
end)()
end,
wait_until_ready = helper.wait_schema_init,
}
Loading

0 comments on commit e31a9d5

Please sign in to comment.