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 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153
|
#!/usr/bin/env tarantool
local math = require('math')
local fiber = require('fiber')
local tap = require('tap')
local ffi = require('ffi')
local fio = require('fio')
box.cfg{ log="tarantool.log", memtx_memory=107374182}
local test = tap.test("snapshot")
test:plan(5)
-------------------------------------------------------------------------------
-- gh-695: Avoid overwriting tuple data with information necessary for smfree()
-------------------------------------------------------------------------------
local continue_snapshoting = true
local snap_chan = fiber.channel()
local function noise()
fiber.name('noise-'..fiber.id())
while continue_snapshoting do
if box.space.test:len() < 300000 then
local value = string.rep('a', math.random(255)+1)
box.space.test:auto_increment{fiber.time64(), value}
end
fiber.sleep(0)
end
end
local function purge()
fiber.name('purge-'..fiber.id())
while continue_snapshoting do
local min = box.space.test.index.primary:min()
if min ~= nil then
box.space.test:delete{min[1]}
end
fiber.sleep(0)
end
end
local function snapshot(lsn)
fiber.name('snapshot')
while continue_snapshoting do
local new_lsn = box.info.lsn
if new_lsn ~= lsn then
lsn = new_lsn;
pcall(box.snapshot)
end
fiber.sleep(0.001)
end
snap_chan:put("!")
end
box.once("snapshot.test", function()
box.schema.space.create('test')
box.space.test:create_index('primary')
end)
fiber.create(noise)
fiber.create(purge)
fiber.create(noise)
fiber.create(purge)
fiber.create(noise)
fiber.create(purge)
fiber.create(noise)
fiber.create(purge)
fiber.create(snapshot, box.info.lsn)
fiber.sleep(0.3)
continue_snapshoting = false
snap_chan:get()
test:ok(true, 'gh-695: avoid overwriting tuple data necessary for smfree()')
-------------------------------------------------------------------------------
-- gh-1185: Crash in matras_touch in snapshot_daemon.test
-------------------------------------------------------------------------------
local s1 = box.schema.create_space('test1', { engine = 'memtx'})
local i1 = s1:create_index('test', { type = 'tree', parts = {1, 'unsigned'} })
local s2 = box.schema.create_space('test2', { engine = 'memtx'})
local i2 = s2:create_index('test', { type = 'tree', parts = {1, 'unsigned'} })
for i = 1,1000 do s1:insert{i, i, i} end
local snap_chan = fiber.channel()
fiber.create(function () box.snapshot() snap_chan:put(true) end)
fiber.sleep(0)
s2:insert{1, 2, 3}
s2:update({1}, {{'+', 2, 2}})
s1:drop()
s2:drop()
snap_chan:get()
test:ok(true, "gh-1185: no crash in matras_touch")
-------------------------------------------------------------------------------
-- gh-1084: box.snapshot() aborts if the server is out of file descriptors
-------------------------------------------------------------------------------
local function gh1094()
local msg = "gh-1094: box.snapshot() doesn't abort if out of file descriptors"
local nfile
local ulimit = io.popen('ulimit -n')
if ulimit then
nfile = tonumber(ulimit:read())
ulimit:close()
end
if not nfile or nfile > 1024 then
-- descriptors limit is to high, just skip test
test:ok(true, msg)
return
end
local files = {}
for i = 1,nfile do
files[i] = fio.open('/dev/null')
if files[i] == nil then
break
end
end
local sf, mf = pcall(box.snapshot)
for i, f in pairs(files) do
f:close()
end
local ss, ms = pcall(box.snapshot)
test:ok(not sf and ss, msg)
end
gh1094()
-- gh-2045 - test snapshot if nothing changed
-- we wan't check snapshot update time because it may take long time to wait
box.snapshot()
box.snapshot()
box.snapshot()
test:ok(true, 'No crash for second snapshot w/o any changes')
files = fio.glob(box.cfg.memtx_dir .. '/*.snap')
table.sort(files)
fio.unlink(files[#files])
box.snapshot()
test:ok(fio.stat(files[#files]) ~= nil, "Snapshot was recreated")
box.space.test:drop()
test:check()
os.exit(0)
|