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 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232
|
fio = require 'fio'
---
...
errno = require 'errno'
---
...
fiber = require 'fiber'
---
...
env = require('test_run')
---
...
test_run = env.new()
---
...
PERIOD = 0.03
---
...
if jit.os ~= 'Linux' then PERIOD = 1.5 end
---
...
space = box.schema.space.create('snapshot_daemon')
---
...
index = space:create_index('pk', { type = 'tree', parts = { 1, 'unsigned' }})
---
...
box.cfg{snapshot_period = PERIOD, snapshot_count = 2 }
---
...
no = 1
---
...
-- first xlog
for i = 1, box.cfg.rows_per_wal + 10 do space:insert { no } no = no + 1 end
---
...
-- second xlog
for i = 1, box.cfg.rows_per_wal + 10 do space:insert { no } no = no + 1 end
---
...
-- wait for last snapshot
fiber.sleep(1.5 * PERIOD)
---
...
-- third xlog
for i = 1, box.cfg.rows_per_wal + 10 do space:insert { no } no = no + 1 end
---
...
-- fourth xlog
for i = 1, box.cfg.rows_per_wal + 10 do space:insert { no } no = no + 1 end
---
...
-- wait for last snapshot
test_run:cmd("setopt delimiter ';'")
---
- true
...
for i = 1, 100 do
fiber.sleep(PERIOD)
snaps = fio.glob(fio.pathjoin(box.cfg.snap_dir, '*.snap'))
xlogs = fio.glob(fio.pathjoin(box.cfg.wal_dir, '*.xlog'))
if #snaps == 2 then
break
end
end;
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
#snaps == 2 or snaps
---
- true
...
#xlogs > 0
---
- true
...
fio.basename(snaps[1], '.snap') >= fio.basename(xlogs[1], '.xlog')
---
- true
...
-- restore default options
box.cfg{snapshot_period = 3600 * 4, snapshot_count = 4 }
---
...
space:drop()
---
...
box.cfg{ snapshot_count = .2 }
---
- error: 'Incorrect value for option ''snapshot_count'': must be an integer'
...
daemon = box.internal.snapshot_daemon
---
...
-- stop daemon
box.cfg{ snapshot_period = 0 }
---
...
-- wait daemon to stop
while daemon.fiber ~= nil do fiber.sleep(0) end
---
...
daemon.fiber == nil
---
- true
...
-- start daemon
box.cfg{ snapshot_period = 10 }
---
...
daemon.fiber ~= nil
---
- true
...
-- reload configuration
box.cfg{ snapshot_period = 15, snapshot_count = 20 }
---
...
daemon.snapshot_period == 15
---
- true
...
daemon.snapshot_count = 20
---
...
-- stop daemon
box.cfg{ snapshot_count = 0 }
---
...
-- Start
PERIOD = 3600
---
...
box.cfg{ snapshot_count = 2, snapshot_period = PERIOD}
---
...
snapshot_time, time = daemon.next_snapshot_time, fiber.time()
---
...
snapshot_time + 1 >= time + PERIOD or {snapshot_time, time, PERIOD}
---
- true
...
snapshot_time - 1 <= time + 2 * PERIOD or {snapshot_time, time, PERIOD}
---
- true
...
daemon_fiber = daemon.fiber
---
...
daemon_control = daemon.control
---
...
-- Reload #1
PERIOD = 100
---
...
box.cfg{ snapshot_count = 2, snapshot_period = PERIOD}
---
...
snapshot_time, time = daemon.next_snapshot_time, fiber.time()
---
...
snapshot_time + 1 >= time + PERIOD or {snapshot_time, time, PERIOD}
---
- true
...
snapshot_time - 1 <= time + 2 * PERIOD or {snapshot_time, time, PERIOD}
---
- true
...
daemon.fiber == daemon_fiber
---
- true
...
daemon.control == daemon_control
---
- true
...
-- Reload #2
PERIOD = 1000
---
...
box.cfg{ snapshot_count = 2, snapshot_period = PERIOD}
---
...
snapshot_time, time = daemon.next_snapshot_time, fiber.time()
---
...
snapshot_time + 1 >= time + PERIOD or {snapshot_time, time, PERIOD}
---
- true
...
snapshot_time - 1 <= time + 2 * PERIOD or {snapshot_time, time, PERIOD}
---
- true
...
daemon.fiber == daemon_fiber
---
- true
...
daemon.control == daemon_control
---
- true
...
daemon_control = nil
---
...
daemin_fiber = nil
---
...
-- Shutdown
box.cfg{ snapshot_count = 2, snapshot_period = 0}
---
...
daemon.next_snapshot_time
---
- null
...
daemon.fiber == nil
---
- true
...
daemon.control == nil
---
- true
...
|