-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreprun.lua
executable file
·88 lines (73 loc) · 2.16 KB
/
reprun.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
#!/usr/bin/env ./src/tarantool
local my = require('my')
local txn_proxy = require('txn_proxy')
stfu = true
local filename = 'rep.lua'
if arg[1] then filename = arg[1] end
local skiplines = nil
if arg[2] then skiplines = tonumber(arg[2]) end
local conf = {wal_mode='write', memtx_memory=1024*1024*1024, listen=3301}
local fio = require('fio')
local f = fio.open(filename)
local text = f:read()
local lines = string.split(text, '\n')
if lines[1] and string.startswith(lines[1], '#!') then
table.remove(lines, 1)
end
if lines[1] and string.startswith(lines[1], 'box.cfg') then
conf = loadstring('return ' .. string.sub(lines[1], 8))()
table.remove(lines, 1)
elseif lines[1] and string.startswith(lines[1], '--! box.cfg') then
local overconf = loadstring('return ' .. string.sub(lines[1], 12))()
for k,v in pairs(overconf) do conf[k] = v end
table.remove(lines, 1)
end
local reslines = {}
local add = ''
for _,line in ipairs(lines) do
line = string.rstrip(line)
local line = add .. line
add = ''
if string.endswith(line, '\\') then
line = string.sub(line, 1, string.len(line) - 1)
line = string.rstrip(line)
add = line .. '\n'
elseif line ~= '' then
table.insert(reslines, line)
end
end
if add ~= '' then
table.insert(reslines, add)
add = ''
end
lines = reslines
reprun_current_line_no = 0
if skiplines then
while skiplines > 0 do
table.remove(lines, 1)
skiplines = skiplines - 1
reprun_current_line_no = reprun_current_line_no + 1
end
else
os.execute('rm -rf *.snap *.xlog *.vylog ./512 ./513 ./514 ./515 ./516 ./517 ./518 ./519 ./520 ./521')
end
box.cfg(conf)
for _,line in ipairs(lines) do
reprun_current_line_no = reprun_current_line_no + 1
print('>' .. line)
local ignore,f,err1,err2 = pcall(loadstring, 'return ' .. line)
if f == nil then
ignore,f,err2 = pcall(loadstring, line)
end
if f == nil then
print('fatal error in function parse')
print('(1) ' .. tostring(err1))
print('(2) ' .. tostring(err2))
exit(-1)
end
local res = {pcall(f)}
table.remove(res, 1)
my.print(unpack(res))
collectgarbage('collect')
end
require('console').start()