-
Notifications
You must be signed in to change notification settings - Fork 1
/
init-script-demo.lua
67 lines (64 loc) · 2.58 KB
/
init-script-demo.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
cartridge = require('cartridge')
replicasets = { {
alias = 'router1',
roles = { 'router', 'vshard-router', 'failover-coordinator' },
join_servers = { { uri = 'tarantool-server1:3301' } }
}, {
alias = 'router2',
roles = { 'router', 'vshard-router', 'failover-coordinator' },
join_servers = { { uri = 'tarantool-server2:3301' } }
}, {
alias = 'router3',
roles = { 'router', 'vshard-router', 'failover-coordinator' },
join_servers = { { uri = 'tarantool-server3:3301' } }
}, {
alias = 'storage1',
roles = { 'storage', 'vshard-storage' },
join_servers = { { uri = 'tarantool-server4:3301' },
{ uri = 'tarantool-server5:3301' },
{ uri = 'tarantool-server6:3301' } }
}, {
alias = 'storage2',
roles = { 'storage', 'vshard-storage' },
join_servers = { { uri = 'tarantool-server7:3301' },
{ uri = 'tarantool-server8:3301' },
{ uri = 'tarantool-server9:3301' } }
}}
cartridge.admin_edit_topology({ replicasets = replicasets })
cartridge.admin_bootstrap_vshard()
cartridge.failover_set_params({
mode = 'stateful',
state_provider = 'etcd2',
failover_timeout = 10,
etcd2_params = {
prefix = '/',
lock_delay = 10,
endpoints = { '172.20.0.12:2379', '172.20.0.13:2379', '172.20.0.14:2379' }
}
})
-- Наполнение БД тестовыми записями
uuid = require('uuid')
function generate_test_data(user_count)
for i = 1, user_count do
local groups
if i <= user_count / 4 then
groups = { 'group_1' }
elseif i <= user_count / 2 then
groups = { 'group_2' }
elseif i <= user_count / 2 + user_count / 4 then
groups = { 'group_3' }
else
groups = { 'group_4' }
end
create_user(uuid.str(), 'login' .. i, 'c4ca4238a0b923820dcc509a6f75849b', 'ACTIVE', groups)
end
end
generate_test_data(50000);
vshard = require('vshard')
function clean_all_spaces()
local replicaset, _ = vshard.router.routeall()
for _, replica in pairs(replicaset) do
replica:callrw('box.space.users:truncate', {})
replica:callrw('box.space.user_groups:truncate', {})
end
end