##// END OF EJS Templates
revlog: fix a bug where transaction can be aborted partially...
revlog: fix a bug where transaction can be aborted partially Fix a repo corruption bug caused by a partial transaction rollback. Differential Revision: https://phab.mercurial-scm.org/D12009

File last commit:

r49423:ccd9cb73 stable
r49423:ccd9cb73 stable
Show More
test-transaction-rollback-on-revlog-split.t
178 lines | 5.3 KiB | text/troff | Tads3Lexer
/ tests / test-transaction-rollback-on-revlog-split.t
Joerg Sonnenberger
revlog: fix index computation during inline->non-inline transition...
r48064 Test correctness of revlog inline -> non-inline transition
----------------------------------------------------------
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 Helper extension to intercept renames.
$ cat > $TESTTMP/intercept_rename.py << EOF
> import os
> import sys
> from mercurial import extensions, util
>
> def extsetup(ui):
> def close(orig, *args, **kwargs):
Raphaël Gomès
compat: normalise path before comparison in revlog splitting test...
r48361 > path = util.normpath(args[0]._atomictempfile__name)
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 > if path.endswith(b'/.hg/store/data/file.i'):
> os._exit(80)
> return orig(*args, **kwargs)
> extensions.wrapfunction(util.atomictempfile, 'close', close)
> EOF
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 Test offset computation to correctly factor in the index entries themselves.
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 Also test that the new data size has the correct size if the transaction is aborted
after the index has been replaced.
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 Test repo has commits a, b, c, D, where D is large (grows the revlog enough that it
transitions to non-inline storage). The clone initially has changes a, b
and will transition to non-inline storage when adding c, D.
If the transaction adding c, D is rolled back, then we don't undo the revlog split,
but truncate the index and the data to remove both c and D.
Joerg Sonnenberger
revlog: fix index computation during inline->non-inline transition...
r48064
$ hg init troffset-computation --config format.revlog-compression=none
$ cd troffset-computation
Matt Harbison
tests: partially fix test-transaction-rollback-on-revlog-split.t on Windows...
r48095 $ printf '%20d' '1' > file
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 $ hg commit -Aqma
Matt Harbison
tests: partially fix test-transaction-rollback-on-revlog-split.t on Windows...
r48095 $ printf '%1024d' '1' > file
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 $ hg commit -Aqmb
$ printf '%20d' '1' > file
$ hg commit -Aqmc
Joerg Sonnenberger
revlog: fix index computation during inline->non-inline transition...
r48064 $ dd if=/dev/zero of=file bs=1k count=128 > /dev/null 2>&1
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 $ hg commit -AqmD
Joerg Sonnenberger
revlog: fix index computation during inline->non-inline transition...
r48064 $ cd ..
$ hg clone -r 1 troffset-computation troffset-computation-copy --config format.revlog-compression=none -q
$ cd troffset-computation-copy
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065
Reference size:
$ f -s .hg/store/data/file*
.hg/store/data/file.i: size=1174
Joerg Sonnenberger
revlog: fix index computation during inline->non-inline transition...
r48064 $ cat > .hg/hgrc <<EOF
> [hooks]
> pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
> EOF
#if chg
$ hg pull ../troffset-computation
pulling from ../troffset-computation
[255]
#else
$ hg pull ../troffset-computation
pulling from ../troffset-computation
[80]
#endif
$ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file | tail -1
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 data/file.i 128
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 The first file.i entry should match the "Reference size" above.
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 The first file.d entry is the temporary record during the split,
the second entry after the split happened. The sum of the second file.d
and the second file.i entry should match the first file.i entry.
$ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
data/file.i 1174
data/file.d 0
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 data/file.d 1046
data/file.i 128
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 $ hg recover
rolling back interrupted transaction
(verify step skipped, run `hg verify` to check your repository content)
$ f -s .hg/store/data/file*
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 .hg/store/data/file.d: size=1046
.hg/store/data/file.i: size=128
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 $ hg tip
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 changeset: 1:cfa8d6e60429
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 summary: b
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066
Valentin Gatien-Baron
test: reduce noise, so the important bits stand out...
r48688 $ hg verify -q
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 warning: revlog 'data/file.d' not in fncache!
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 1 warnings encountered!
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 hint: run "hg debugrebuildfncache" to recover from corrupt fncache
Valentin Gatien-Baron
debugrebuildfncache: add a cheaper option to rebuild the fncache...
r48689 $ hg debugrebuildfncache --only-data
adding data/file.d
1 items added, 0 removed from fncache
$ hg verify -q
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 $ cd ..
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066
Now retry the procedure but intercept the rename of the index and check that
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 the journal does not contain the new index size. This demonstrates the edge case
where the data file is left as garbage.
$ hg clone -r 1 troffset-computation troffset-computation-copy2 --config format.revlog-compression=none -q
$ cd troffset-computation-copy2
$ cat > .hg/hgrc <<EOF
> [extensions]
> intercept_rename = $TESTTMP/intercept_rename.py
> [hooks]
> pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
> EOF
#if chg
$ hg pull ../troffset-computation
pulling from ../troffset-computation
[255]
#else
$ hg pull ../troffset-computation
pulling from ../troffset-computation
[80]
#endif
$ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
data/file.i 1174
data/file.d 0
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 data/file.d 1046
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066
$ hg recover
rolling back interrupted transaction
(verify step skipped, run `hg verify` to check your repository content)
$ f -s .hg/store/data/file*
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 .hg/store/data/file.d: size=1046
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 .hg/store/data/file.i: size=1174
$ hg tip
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 changeset: 1:cfa8d6e60429
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 summary: b
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066
Valentin Gatien-Baron
test: reduce noise, so the important bits stand out...
r48688 $ hg verify -q
Joerg Sonnenberger
revlog: update data file record before index rename...
r48065 $ cd ..
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066
Repeat the original test but let hg rollback the transaction.
$ hg clone -r 1 troffset-computation troffset-computation-copy-rb --config format.revlog-compression=none -q
$ cd troffset-computation-copy-rb
$ cat > .hg/hgrc <<EOF
> [hooks]
> pretxnchangegroup = false
> EOF
$ hg pull ../troffset-computation
pulling from ../troffset-computation
searching for changes
adding changesets
adding manifests
adding file changes
transaction abort!
rollback completed
abort: pretxnchangegroup hook exited with status 1
[40]
$ f -s .hg/store/data/file*
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 .hg/store/data/file.d: size=1046
.hg/store/data/file.i: size=128
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 $ hg tip
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 changeset: 1:cfa8d6e60429
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 tag: tip
user: test
date: Thu Jan 01 00:00:00 1970 +0000
Arseniy Alekseyev
revlog: demonstrate a bug where transaction can be aborted partially...
r49422 summary: b
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066
Valentin Gatien-Baron
test: reduce noise, so the important bits stand out...
r48688 $ hg verify -q
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 warning: revlog 'data/file.d' not in fncache!
Arseniy Alekseyev
revlog: fix a bug where transaction can be aborted partially...
r49423 1 warnings encountered!
Joerg Sonnenberger
recover: only apply last journal record per file (issue6423)...
r48066 hint: run "hg debugrebuildfncache" to recover from corrupt fncache
$ cd ..