-
Notifications
You must be signed in to change notification settings - Fork 375
/
gc.result
580 lines (580 loc) · 10.2 KB
/
gc.result
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
test_run = require('test_run').new()
---
...
engine = test_run:get_cfg('engine')
---
...
replica_set = require('fast_replica')
---
...
fiber = require('fiber')
---
...
fio = require('fio')
---
...
test_run:cleanup_cluster()
---
...
test_run:cmd("create server replica with rpl_master=default, script='replication/replica.lua'")
---
- true
...
-- Make each snapshot trigger garbage collection.
default_checkpoint_count = box.cfg.checkpoint_count
---
...
box.cfg{checkpoint_count = 1}
---
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
function wait_gc(n)
return test_run:wait_cond(function()
return #box.info.gc().checkpoints == n
end, 10)
end;
---
...
function wait_xlog(n, timeout)
return test_run:wait_cond(function()
return #fio.glob('./master/*.xlog') == n
end, 10)
end;
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
-- Grant permissions needed for replication.
box.schema.user.grant('guest', 'replication')
---
...
-- By default, relay thread reports status to tx once a second.
-- To reduce the test execute time, let's set it to 50 ms.
box.error.injection.set("ERRINJ_RELAY_REPORT_INTERVAL", 0.05)
---
- ok
...
-- Create and populate the space we will replicate.
s = box.schema.space.create('test', {engine = engine});
---
...
_ = s:create_index('pk', {run_count_per_level = 1})
---
...
for i = 1, 50 do s:auto_increment{} end
---
...
box.snapshot()
---
- ok
...
for i = 1, 50 do s:auto_increment{} end
---
...
box.snapshot()
---
- ok
...
for i = 1, 100 do s:auto_increment{} end
---
...
-- Make sure replica join will take long enough for us to
-- invoke garbage collection.
box.error.injection.set("ERRINJ_RELAY_SEND_DELAY", true)
---
- ok
...
-- While the replica is receiving the initial data set,
-- make a snapshot and invoke garbage collection, then
-- remove delay to allow replica to start.
test_run:cmd("setopt delimiter ';'")
---
- true
...
fiber.create(function()
fiber.sleep(0.1)
box.snapshot()
box.error.injection.set("ERRINJ_RELAY_SEND_DELAY", false)
end)
test_run:cmd("setopt delimiter ''");
---
...
-- Start the replica.
test_run:cmd("start server replica")
---
- true
...
-- Despite the fact that we invoked garbage collection that
-- would have normally removed the snapshot the replica was
-- bootstrapped from, the replica should still receive all
-- data from the master. Check it.
test_run:cmd("switch replica")
---
- true
...
test_run:wait_cond(function() return box.space.test:count() == 200 end, 10)
---
- true
...
box.space.test:count()
---
- 200
...
test_run:cmd("switch default")
---
- true
...
-- Check that garbage collection removed the snapshot once
-- the replica released the corresponding checkpoint.
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(1) or fio.listdir('./master') -- Make sure the replica will not receive data until
---
- true
...
-- we test garbage collection.
box.error.injection.set("ERRINJ_RELAY_SEND_DELAY", true)
---
- ok
...
-- Send more data to the replica.
-- Need to do 2 snapshots here, otherwise the replica would
-- only require 1 xlog and that case would be
-- indistinguishable from wrong operation.
for i = 1, 50 do s:auto_increment{} end
---
...
box.snapshot()
---
- ok
...
for i = 1, 50 do s:auto_increment{} end
---
...
box.snapshot()
---
- ok
...
-- Invoke garbage collection. Check that it doesn't remove
-- xlogs needed by the replica.
box.snapshot()
---
- ok
...
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(2) or fio.listdir('./master')
---
- true
...
-- Resume replication so that the replica catches
-- up quickly.
box.error.injection.set("ERRINJ_RELAY_SEND_DELAY", false)
---
- ok
...
-- Check that the replica received all data from the master.
test_run:cmd("switch replica")
---
- true
...
test_run:wait_cond(function() return box.space.test:count() == 300 end, 10)
---
- true
...
box.space.test:count()
---
- 300
...
test_run:cmd("switch default")
---
- true
...
-- Now garbage collection should resume and delete files left
-- from the old checkpoint.
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(0) or fio.listdir('./master')
---
- true
...
--
-- Check that the master doesn't delete xlog files sent to the
-- replica until it receives a confirmation that the data has
-- been applied (gh-2825).
--
test_run:cmd("switch replica")
---
- true
...
-- Prevent the replica from applying any rows.
box.error.injection.set("ERRINJ_WAL_DELAY", true)
---
- ok
...
test_run:cmd("switch default")
---
- true
...
-- Generate some data on the master.
for i = 1, 5 do s:auto_increment{} end
---
...
box.snapshot() -- rotate xlog
---
- ok
...
for i = 1, 5 do s:auto_increment{} end
---
...
fiber.sleep(0.1) -- wait for master to relay data
---
...
-- Garbage collection must not delete the old xlog file
-- because it is still needed by the replica, but remove
-- the old snapshot.
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(2) or fio.listdir('./master')
---
- true
...
-- Imitate the replica crash and, then, wake up.
-- Just 'stop server replica' (SIGTERM) is not sufficient to stop
-- a tarantool instance when ERRINJ_WAL_DELAY is set, because
-- "tarantool" thread wait for paused "wal" thread infinitely.
test_run:cmd("stop server replica with signal=KILL")
---
- true
...
test_run:cmd("start server replica")
---
- true
...
-- Wait for the replica to catch up.
test_run:cmd("switch replica")
---
- true
...
test_run:wait_cond(function() return box.space.test:count() == 310 end, 10)
---
- true
...
box.space.test:count()
---
- 310
...
test_run:cmd("switch default")
---
- true
...
-- Now it's safe to drop the old xlog.
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(1) or fio.listdir('./master')
---
- true
...
-- Stop the replica.
test_run:cmd("stop server replica")
---
- true
...
test_run:cmd("cleanup server replica")
---
- true
...
-- Invoke garbage collection. Check that it removes the old
-- checkpoint, but keeps the xlog last used by the replica.
-- once again, need 2 snapshots because after 1 snapshot
-- with no insertions after it the replica would need only
-- 1 xlog, which is stored anyways.
_ = s:auto_increment{}
---
...
box.snapshot()
---
- ok
...
_ = s:auto_increment{}
---
...
box.snapshot()
---
- ok
...
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(2) or fio.listdir('./master')
---
- true
...
-- The xlog should only be deleted after the replica
-- is unregistered.
test_run:cleanup_cluster()
---
...
wait_gc(1) or box.info.gc()
---
- true
...
wait_xlog(1) or fio.listdir('./master')
---
- true
...
--
-- Test that concurrent invocation of the garbage collector works fine.
--
s:truncate()
---
...
for i = 1, 10 do s:replace{i} end
---
...
box.snapshot()
---
- ok
...
replica_set.join(test_run, 3)
---
...
replica_set.stop_all(test_run)
---
...
for i = 11, 50 do s:replace{i} if i % 10 == 0 then box.snapshot() end end
---
...
replica_set.start_all(test_run)
---
...
replica_set.wait_all(test_run)
---
...
replica_set.drop_all(test_run)
---
...
--
-- Check that once a replica is removed from the cluster table,
-- all xlogs kept for it are removed even if it is configured as
-- a replication master (gh-3546).
--
fio = require('fio')
---
...
-- Start a replica and set it up as a master for this instance.
test_run:cmd("start server replica")
---
- true
...
replica_port = test_run:eval('replica', 'return box.cfg.listen')[1]
---
...
replica_port ~= nil
---
- true
...
box.cfg{replication = replica_port}
---
...
-- Stop the replica and write a few WALs.
test_run:cmd("stop server replica")
---
- true
...
test_run:cmd("cleanup server replica")
---
- true
...
_ = s:auto_increment{}
---
...
box.snapshot()
---
- ok
...
_ = s:auto_increment{}
---
...
box.snapshot()
---
- ok
...
_ = s:auto_increment{}
---
...
box.snapshot()
---
- ok
...
wait_xlog(3) or fio.listdir('./master')
---
- true
...
-- Delete the replica from the cluster table and check that
-- all xlog files are removed.
test_run:cleanup_cluster()
---
...
box.snapshot()
---
- ok
...
wait_xlog(0, 10) or fio.listdir('./master')
---
- true
...
-- Restore the config.
box.cfg{replication = {}}
---
...
s:truncate()
---
...
--
-- Check that a master doesn't remove WAL files needed by a replica
-- in case the replica has local changes due to which its vclock has
-- greater signature than the master's (gh-4106).
--
test_run:cmd("start server replica")
---
- true
...
-- Temporarily disable replication.
test_run:cmd("switch replica")
---
- true
...
replication = box.cfg.replication
---
...
box.cfg{replication = {}}
---
...
-- Generate some WALs on the master.
test_run:cmd("switch default")
---
- true
...
test_run:cmd("setopt delimiter ';'")
---
- true
...
for i = 1, 4 do
for j = 1, 100 do
s:replace{1, i, j}
end
box.snapshot()
end;
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
-- Stall WAL writes on the replica and reestablish replication,
-- then bump local LSN and break replication on WAL error so that
-- the master sends all rows and receives ack with the replica's
-- vclock, but not all rows are actually applied on the replica.
-- The master must not delete unconfirmed WALs even though the
-- replica's vclock has a greater signature (checked later on).
test_run:cmd("switch replica")
---
- true
...
box.error.injection.set('ERRINJ_WAL_DELAY', true)
---
- ok
...
box.cfg{replication_connect_quorum = 0} -- disable sync
---
...
box.cfg{replication = replication}
---
...
fiber = require('fiber')
---
...
test_run:cmd("setopt delimiter ';'");
---
- true
...
_ = fiber.create(function()
box.begin()
for i = 1, 1000 do
box.space.test:replace{1, i}
end
box.commit()
box.error.injection.set('ERRINJ_WAL_WRITE_DISK', true)
end);
---
...
test_run:cmd("setopt delimiter ''");
---
- true
...
box.error.injection.set('ERRINJ_WAL_DELAY', false)
---
- ok
...
-- Restart the replica and wait for it to sync.
test_run:cmd("switch default")
---
- true
...
test_run:cmd("stop server replica")
---
- true
...
test_run:cmd("start server replica")
---
- true
...
test_run:wait_lsn('replica', 'default')
---
...
-- Cleanup.
test_run:cmd("stop server replica")
---
- true
...
test_run:cmd("cleanup server replica")
---
- true
...
test_run:cmd("delete server replica")
---
- true
...
test_run:cleanup_cluster()
---
...
s:drop()
---
...
box.error.injection.set("ERRINJ_RELAY_REPORT_INTERVAL", 0)
---
- ok
...
box.schema.user.revoke('guest', 'replication')
---
...
box.cfg{checkpoint_count = default_checkpoint_count}
---
...