Debian Codegraph @

tests/test-transaction-rollback-on-revlog-split.t

raw
1 Test correctness of revlog inline -> non-inline transition
2 ----------------------------------------------------------
3
4 We test various file length and naming pattern as this created issue in the
5 past.
6
7 Helper extension to intercept renames and kill process
8
9 $ cat > $TESTTMP/intercept_before_rename.py << EOF
10 > from mercurial import extensions, util
11 > from mercurial.utils import procutil
12 >
13 > def extsetup(ui):
14 > def rename(orig, src, dest, *args, **kwargs):
15 > path = util.normpath(dest)
16 > if path.endswith(b'data/file.i'):
17 > procutil.kill_self()
18 > return orig(src, dest, *args, **kwargs)
19 > extensions.wrapfunction(util, 'rename', rename)
20 > EOF
21
22 $ cat > $TESTTMP/intercept_after_rename.py << EOF
23 > from mercurial import extensions, util
24 > from mercurial.utils import procutil
25 >
26 > def extsetup(ui):
27 > def close(orig, *args, **kwargs):
28 > path = util.normpath(args[0]._atomictempfile__name)
29 > r = orig(*args, **kwargs)
30 > if path.endswith(b'/.hg/store/data/file.i'):
31 > procutil.kill_self()
32 > return r
33 > extensions.wrapfunction(util.atomictempfile, 'close', close)
34 > def extsetup(ui):
35 > def rename(orig, src, dest, *args, **kwargs):
36 > path = util.normpath(dest)
37 > r = orig(src, dest, *args, **kwargs)
38 > if path.endswith(b'data/file.i'):
39 > procutil.kill_self()
40 > return r
41 > extensions.wrapfunction(util, 'rename', rename)
42 > EOF
43
44 $ cat > $TESTTMP/killme.py << EOF
45 > from mercurial.utils import procutil
46 >
47 > def killme(ui, repo, hooktype, **kwargs):
48 > procutil.kill_self()
49 > EOF
50
51 $ cat > $TESTTMP/reader_wait_split.py << EOF
52 > import os
53 > import signal
54 > from mercurial import extensions, revlog, testing
55 > def _wait_post_load(orig, self, *args, **kwargs):
56 > wait = b'data/file' in self.radix
57 > if wait:
58 > testing.wait_file(b"$TESTTMP_FORWARD_SLASH/writer-revlog-split")
59 > r = orig(self, *args, **kwargs)
60 > if wait:
61 > testing.write_file(b"$TESTTMP_FORWARD_SLASH/reader-index-read")
62 > testing.wait_file(b"$TESTTMP_FORWARD_SLASH/writer-revlog-unsplit")
63 > return r
64 >
65 > def extsetup(ui):
66 > extensions.wrapfunction(revlog.revlog, '_loadindex', _wait_post_load)
67 > EOF
68
69 setup a repository for tests
70 ----------------------------
71
72 $ cat >> $HGRCPATH << EOF
73 > [format]
74 > revlog-compression=none
75 > EOF
76
77 $ hg init troffset-computation
78 $ cd troffset-computation
79 $ files="
80 > file
81 > Directory_With,Special%Char/Complex_File.babar
82 > foo/bar/babar_celeste/foo
83 > 1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/1234567890/f
84 > some_dir/sub_dir/foo_bar
85 > some_dir/sub_dir/foo_bar.i.s/tutu
86 > "
87 $ for f in $files; do
88 > mkdir -p `dirname $f`
89 > done
90 $ for f in $files; do
91 > printf '%20d' '1' > $f
92 > done
93 $ hg commit -Aqma
94 $ for f in $files; do
95 > printf '%1024d' '1' > $f
96 > done
97 $ hg commit -Aqmb
98 $ for f in $files; do
99 > printf '%20d' '1' > $f
100 > done
101 $ hg commit -Aqmc
102 $ for f in $files; do
103 > dd if=/dev/zero of=$f bs=1k count=128 > /dev/null 2>&1
104 > done
105 $ hg commit -AqmD --traceback
106 $ for f in $files; do
107 > dd if=/dev/zero of=$f bs=1k count=132 > /dev/null 2>&1
108 > done
109 $ hg commit -AqmD --traceback
110
111 Reference size:
112 $ f -s file
113 file: size=135168
114 $ f -s .hg/store/data*/file*
115 .hg/store/data/file.d: size=267307
116 .hg/store/data/file.i: size=320
117
118 $ cd ..
119
120 Test a succesful pull
121 =====================
122
123 Make sure everything goes though as expect if we don't do any crash
124
125 $ hg clone --quiet --rev 1 troffset-computation troffset-success
126 $ cd troffset-success
127
128 Reference size:
129 $ f -s file
130 file: size=1024
131 $ f -s .hg/store/data/file*
132 .hg/store/data/file.i: size=1174
133
134 $ hg pull ../troffset-computation
135 pulling from ../troffset-computation
136 searching for changes
137 adding changesets
138 adding manifests
139 adding file changes
140 added 3 changesets with 18 changes to 6 files
141 new changesets c99a94cae9b1:64874a3b0160
142 (run 'hg update' to get a working copy)
143
144
145 The inline revlog has been replaced
146
147 $ f -s .hg/store/data/file*
148 .hg/store/data/file.d: size=267307
149 .hg/store/data/file.i: size=320
150
151
152 $ hg verify -q
153 $ cd ..
154
155
156 Test a hard crash after the file was split but before the transaction was committed
157 ===================================================================================
158
159 Test offset computation to correctly factor in the index entries themselves.
160 Also test that the new data size has the correct size if the transaction is aborted
161 after the index has been replaced.
162
163 Test repo has commits a, b, c, D, where D is large (grows the revlog enough that it
164 transitions to non-inline storage). The clone initially has changes a, b
165 and will transition to non-inline storage when adding c, D.
166
167 If the transaction adding c, D is rolled back, then we don't undo the revlog split,
168 but truncate the index and the data to remove both c and D.
169
170
171 $ hg clone --quiet --rev 1 troffset-computation troffset-computation-copy
172 $ cd troffset-computation-copy
173
174 Reference size:
175 $ f -s file
176 file: size=1024
177 $ f -s .hg/store/data*/file*
178 .hg/store/data/file.i: size=1174
179
180 $ cat > .hg/hgrc <<EOF
181 > [hooks]
182 > pretxnchangegroup = python:$TESTTMP/killme.py:killme
183 > EOF
184 #if chg
185 $ hg pull ../troffset-computation
186 pulling from ../troffset-computation
187 [255]
188 #else
189 $ hg pull ../troffset-computation
190 pulling from ../troffset-computation
191 *Killed* (glob)
192 [137]
193 #endif
194
195
196 The inline revlog still exist, but a split version exist next to it
197
198 $ cat .hg/store/journal | tr '\0' ' ' | grep '\.s'
199 data/some_dir/sub_dir/foo_bar.i.s/tutu.i 1174
200 data/some_dir/sub_dir/foo_bar.i.s/tutu.d 0
201 $ f -s .hg/store/data*/file*
202 .hg/store/data-s/file.i: size=320
203 .hg/store/data/file.d: size=267307
204 .hg/store/data/file.i: size=132395
205 $ f -s .hg/store/data*/foo*/bar*/babar__celeste*/foo*
206 .hg/store/data-s/foo/bar/babar__celeste/foo.i: size=320
207 .hg/store/data/foo/bar/babar__celeste/foo.d: size=267307
208 .hg/store/data/foo/bar/babar__celeste/foo.i: size=132395
209
210
211 The first file.i entry should match the "Reference size" above.
212 The first file.d entry is the temporary record during the split,
213
214 A "temporary file" entry exist for the split index.
215
216 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
217 data/file.i 1174
218 data/file.d 0
219 $ cat .hg/store/journal.backupfiles | tr -s '\000' ' ' | tr -s '\00' ' '| grep 'data.*/file'
220 data/file.i data/journal.backup.file.i.bck 0
221 data-s/file.i 0
222
223 recover is rolling the split back, the fncache is still valid
224
225 $ hg recover
226 rolling back interrupted transaction
227 (verify step skipped, run `hg verify` to check your repository content)
228 $ f -s .hg/store/data*/file*
229 .hg/store/data/file.i: size=1174
230 $ hg tip
231 changeset: 1:64b04c8dc267
232 tag: tip
233 user: test
234 date: Thu Jan 01 00:00:00 1970 +0000
235 summary: b
236
237 $ hg verify -q
238 $ hg debugrebuildfncache --only-data
239 fncache already up to date
240 $ hg verify -q
241 $ cd ..
242
243 Test a hard crash right before the index is move into place
244 ===========================================================
245
246 Now retry the procedure but intercept the rename of the index and check that
247 the journal does not contain the new index size. This demonstrates the edge case
248 where the data file is left as garbage.
249
250 $ hg clone --quiet --rev 1 troffset-computation troffset-computation-copy2
251 $ cd troffset-computation-copy2
252
253 Reference size:
254 $ f -s file
255 file: size=1024
256 $ f -s .hg/store/data*/file*
257 .hg/store/data/file.i: size=1174
258
259 $ cat > .hg/hgrc <<EOF
260 > [extensions]
261 > intercept_rename = $TESTTMP/intercept_before_rename.py
262 > EOF
263 #if chg
264 $ hg pull ../troffset-computation
265 pulling from ../troffset-computation
266 searching for changes
267 adding changesets
268 adding manifests
269 adding file changes
270 [255]
271 #else
272 $ hg pull ../troffset-computation
273 pulling from ../troffset-computation
274 searching for changes
275 adding changesets
276 adding manifests
277 adding file changes
278 *Killed* (glob)
279 [137]
280 #endif
281
282 The inline revlog still exist, but a split version exist next to it
283
284 $ f -s .hg/store/data*/file*
285 .hg/store/data-s/file.i: size=320
286 .hg/store/data/file.d: size=267307
287 .hg/store/data/file.i: size=132395
288
289 $ cat .hg/store/journal | tr -s '\000' ' ' | grep 'data.*/file'
290 data/file.i 1174
291 data/file.d 0
292
293 recover is rolling the split back, the fncache is still valid
294
295 $ hg recover
296 rolling back interrupted transaction
297 (verify step skipped, run `hg verify` to check your repository content)
298 $ f -s .hg/store/data*/file*
299 .hg/store/data/file.i: size=1174
300 $ hg tip
301 changeset: 1:64b04c8dc267
302 tag: tip
303 user: test
304 date: Thu Jan 01 00:00:00 1970 +0000
305 summary: b
306
307 $ hg verify -q
308 $ cd ..
309
310 Test a hard crash right after the index is move into place
311 ===========================================================
312
313 Now retry the procedure but intercept the rename of the index.
314
315 $ hg clone --quiet --rev 1 troffset-computation troffset-computation-crash-after-rename
316 $ cd troffset-computation-crash-after-rename
317
318 Reference size:
319 $ f -s file
320 file: size=1024
321 $ f -s .hg/store/data*/file*
322 .hg/store/data/file.i: size=1174
323
324 $ cat > .hg/hgrc <<EOF
325 > [extensions]
326 > intercept_rename = $TESTTMP/intercept_after_rename.py
327 > EOF
328 #if chg
329 $ hg pull ../troffset-computation
330 pulling from ../troffset-computation
331 searching for changes
332 adding changesets
333 adding manifests
334 adding file changes
335 [255]
336 #else
337 $ hg pull ../troffset-computation
338 pulling from ../troffset-computation
339 searching for changes
340 adding changesets
341 adding manifests
342 adding file changes
343 *Killed* (glob)
344 [137]
345 #endif
346
347 The inline revlog was over written on disk
348
349 $ f -s .hg/store/data*/file*
350 .hg/store/data/file.d: size=267307
351 .hg/store/data/file.i: size=320
352
353 $ cat .hg/store/journal | tr -s '\000' ' ' | grep 'data.*/file'
354 data/file.i 1174
355 data/file.d 0
356
357 recover is rolling the split back, the fncache is still valid
358
359 $ hg recover
360 rolling back interrupted transaction
361 (verify step skipped, run `hg verify` to check your repository content)
362 $ f -s .hg/store/data*/file*
363 .hg/store/data/file.i: size=1174
364 $ hg tip
365 changeset: 1:64b04c8dc267
366 tag: tip
367 user: test
368 date: Thu Jan 01 00:00:00 1970 +0000
369 summary: b
370
371 $ hg verify -q
372 $ cd ..
373
374 Have the transaction rollback itself without any hard crash
375 ===========================================================
376
377
378 Repeat the original test but let hg rollback the transaction.
379
380 $ hg clone --quiet --rev 1 troffset-computation troffset-computation-copy-rb
381 $ cd troffset-computation-copy-rb
382 $ cat > .hg/hgrc <<EOF
383 > [hooks]
384 > pretxnchangegroup = false
385 > EOF
386 $ hg pull ../troffset-computation
387 pulling from ../troffset-computation
388 searching for changes
389 adding changesets
390 adding manifests
391 adding file changes
392 transaction abort!
393 rollback completed
394 abort: pretxnchangegroup hook exited with status 1
395 [40]
396
397 The split was rollback
398
399 $ f -s .hg/store/data*/file*
400 .hg/store/data/file.i: size=1174
401
402 $ hg tip
403 changeset: 1:64b04c8dc267
404 tag: tip
405 user: test
406 date: Thu Jan 01 00:00:00 1970 +0000
407 summary: b
408
409 $ hg verify -q
410
411 $ cat > .hg/hgrc <<EOF
412 > [hooks]
413 > EOF
414 $ hg pull ../troffset-computation
415 pulling from ../troffset-computation
416 searching for changes
417 adding changesets
418 adding manifests
419 adding file changes
420 added 3 changesets with 18 changes to 6 files
421 new changesets c99a94cae9b1:64874a3b0160
422 (run 'hg update' to get a working copy)
423
424 $ f -s .hg/store/data*/file*
425 .hg/store/data/file.d: size=267307
426 .hg/store/data/file.i: size=320
427 $ hg verify -q
428
429 $ cd ..
430
431 Read race
432 =========
433
434 We check that a client that started reading a revlog (its index) after the
435 split and end reading (the data) after the rollback should be fine
436
437 $ hg clone --quiet --rev 1 troffset-computation troffset-computation-race
438 $ cd troffset-computation-race
439 $ cat > .hg/hgrc <<EOF
440 > [hooks]
441 > pretxnchangegroup=sh "$RUNTESTDIR/testlib/wait-on-file" 5 $TESTTMP/reader-index-read $TESTTMP/writer-revlog-split
442 > pretxnclose = false
443 > EOF
444
445 start a reader
446
447 $ hg cat --rev 0 file \
448 > --config "extensions.wait_read=$TESTTMP/reader_wait_split.py" \
449 > 2> $TESTTMP/reader.stderr \
450 > > $TESTTMP/reader.stdout &
451
452 Do a failed pull in //
453
454 $ hg pull ../troffset-computation
455 pulling from ../troffset-computation
456 searching for changes
457 adding changesets
458 adding manifests
459 adding file changes
460 transaction abort!
461 rollback completed
462 abort: pretxnclose hook exited with status 1
463 [40]
464 $ touch $TESTTMP/writer-revlog-unsplit
465 $ wait
466
467 The reader should be fine
468 $ cat $TESTTMP/reader.stderr
469 $ cat $TESTTMP/reader.stdout
470 1 (no-eol)
471
472 $ hg verify -q
473
474 $ cd ..
475
476 pending hooks
477 =============
478
479 We checks that hooks properly see the inside of the transaction, while other process don't.
480
481 $ hg clone --quiet --rev 1 troffset-computation troffset-computation-hooks
482 $ cd troffset-computation-hooks
483 $ cat > .hg/hgrc <<EOF
484 > [hooks]
485 > pretxnclose.01-echo = hg cat -r "max(all())" file | "$PYTHON" "$RUNTESTDIR/f" --size
486 > pretxnclose.02-echo = sh "$RUNTESTDIR/testlib/wait-on-file" 5 $TESTTMP/hook-done $TESTTMP/hook-tr-ready
487 > pretxnclose.03-abort = false
488 > EOF
489
490 $ (
491 > $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/hook-tr-ready;\
492 > hg cat -r 'max(all())' file | f --size;\
493 > touch $TESTTMP/hook-done
494 > ) >stdout 2>stderr &
495
496 $ hg pull ../troffset-computation
497 pulling from ../troffset-computation
498 searching for changes
499 adding changesets
500 adding manifests
501 adding file changes
502 size=135168
503 transaction abort!
504 rollback completed
505 abort: pretxnclose.03-abort hook exited with status 1
506 [40]
507
508 $ cat stdout
509 size=1024
510 $ cat stderr
511
512 $ hg verify -q
513
514
515 $ cd ..