forked from fl00r/go-tarantool-1.6
-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathconfig.lua
117 lines (104 loc) · 3.45 KB
/
config.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
-- configure path so that you can run application
-- from outside the root directory
if package.setsearchroot ~= nil then
package.setsearchroot()
else
-- Workaround for rocks loading in tarantool 1.10
-- It can be removed in tarantool > 2.2
-- By default, when you do require('mymodule'), tarantool looks into
-- the current working directory and whatever is specified in
-- package.path and package.cpath. If you run your app while in the
-- root directory of that app, everything goes fine, but if you try to
-- start your app with "tarantool myapp/init.lua", it will fail to load
-- its modules, and modules from myapp/.rocks.
local fio = require('fio')
local app_dir = fio.abspath(fio.dirname(arg[0]))
package.path = app_dir .. '/?.lua;' .. package.path
package.path = app_dir .. '/?/init.lua;' .. package.path
package.path = app_dir .. '/.rocks/share/tarantool/?.lua;' .. package.path
package.path = app_dir .. '/.rocks/share/tarantool/?/init.lua;' .. package.path
package.cpath = app_dir .. '/?.so;' .. package.cpath
package.cpath = app_dir .. '/?.dylib;' .. package.cpath
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.so;' .. package.cpath
package.cpath = app_dir .. '/.rocks/lib/tarantool/?.dylib;' .. package.cpath
end
local crud = require('crud')
local vshard = require('vshard')
-- Do not set listen for now so connector won't be
-- able to send requests until everything is configured.
box.cfg{
work_dir = os.getenv("TEST_TNT_WORK_DIR"),
}
box.schema.user.grant(
'guest',
'read,write,execute',
'universe'
)
local s = box.schema.space.create('test', {
id = 617,
if_not_exists = true,
format = {
{name = 'id', type = 'unsigned'},
{name = 'bucket_id', type = 'unsigned', is_nullable = true},
{name = 'name', type = 'string'},
}
})
s:create_index('primary_index', {
parts = {
{field = 1, type = 'unsigned'},
},
})
s:create_index('bucket_id', {
parts = {
{field = 2, type = 'unsigned'},
},
unique = false,
})
local function is_ready_false()
return false
end
local function is_ready_true()
return true
end
rawset(_G, 'is_ready', is_ready_false)
-- Setup vshard.
_G.vshard = vshard
box.once('guest', function()
box.schema.user.grant('guest', 'super')
end)
local uri = '[email protected]:3013'
local box_info = box.info()
local replicaset_uuid
if box_info.replicaset then
-- Since Tarantool 3.0.
replicaset_uuid = box_info.replicaset.uuid
else
replicaset_uuid = box_info.cluster.uuid
end
local cfg = {
bucket_count = 300,
sharding = {
[replicaset_uuid] = {
replicas = {
[box_info.uuid] = {
uri = uri,
name = 'storage',
master = true,
},
},
},
},
}
vshard.storage.cfg(cfg, box_info.uuid)
vshard.router.cfg(cfg)
vshard.router.bootstrap()
-- Initialize crud.
crud.init_storage()
crud.init_router()
crud.cfg{stats = true}
box.schema.user.create('test', { password = 'test' , if_not_exists = true })
box.schema.user.grant('test', 'execute', 'universe', nil, { if_not_exists = true })
box.schema.user.grant('test', 'create,read,write,drop,alter', 'space', nil, { if_not_exists = true })
box.schema.user.grant('test', 'create', 'sequence', nil, { if_not_exists = true })
-- Set is_ready = is_ready_true only when every other thing is configured.
rawset(_G, 'is_ready', is_ready_true)