##// END OF EJS Templates
revlog: demonstrate a bug where transaction can be aborted partially...
Arseniy Alekseyev -
r49422:f38ae2d7 stable
parent child Browse files
Show More
@@ -1,172 +1,194 b''
1 1 Test correctness of revlog inline -> non-inline transition
2 2 ----------------------------------------------------------
3 3
4 4 Helper extension to intercept renames.
5 5
6 6 $ cat > $TESTTMP/intercept_rename.py << EOF
7 7 > import os
8 8 > import sys
9 9 > from mercurial import extensions, util
10 10 >
11 11 > def extsetup(ui):
12 12 > def close(orig, *args, **kwargs):
13 13 > path = util.normpath(args[0]._atomictempfile__name)
14 14 > if path.endswith(b'/.hg/store/data/file.i'):
15 15 > os._exit(80)
16 16 > return orig(*args, **kwargs)
17 17 > extensions.wrapfunction(util.atomictempfile, 'close', close)
18 18 > EOF
19 19
20 Test offset computation to correctly factor in the index entries themselve.
20 Test offset computation to correctly factor in the index entries themselves.
21 21 Also test that the new data size has the correct size if the transaction is aborted
22 22 after the index has been replaced.
23 23
24 Test repo has one small, one moderate and one big change. The clone has
25 the small and moderate change and will transition to non-inline storage when
26 adding the big change.
24 Test repo has commits a, b, c, D, where D is large (grows the revlog enough that it
25 transitions to non-inline storage). The clone initially has changes a, b
26 and will transition to non-inline storage when adding c, D.
27
28 If the transaction adding c, D is rolled back, then we don't undo the revlog split,
29 but truncate the index and the data to remove both c and D.
27 30
28 31 $ hg init troffset-computation --config format.revlog-compression=none
29 32 $ cd troffset-computation
30 33 $ printf '%20d' '1' > file
31 $ hg commit -Aqm_
34 $ hg commit -Aqma
32 35 $ printf '%1024d' '1' > file
33 $ hg commit -Aqm_
36 $ hg commit -Aqmb
37 $ printf '%20d' '1' > file
38 $ hg commit -Aqmc
34 39 $ dd if=/dev/zero of=file bs=1k count=128 > /dev/null 2>&1
35 $ hg commit -Aqm_
40 $ hg commit -AqmD
41
36 42 $ cd ..
37 43
38 44 $ hg clone -r 1 troffset-computation troffset-computation-copy --config format.revlog-compression=none -q
39 45 $ cd troffset-computation-copy
40 46
41 47 Reference size:
42 48
43 49 $ f -s .hg/store/data/file*
44 50 .hg/store/data/file.i: size=1174
45 51
46 52 $ cat > .hg/hgrc <<EOF
47 53 > [hooks]
48 54 > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
49 55 > EOF
50 56 #if chg
51 57 $ hg pull ../troffset-computation
52 58 pulling from ../troffset-computation
53 59 [255]
54 60 #else
55 61 $ hg pull ../troffset-computation
56 62 pulling from ../troffset-computation
57 63 [80]
58 64 #endif
59 65 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file | tail -1
60 data/file.i 128
66 data/file.i 192
61 67
62 The first file.i entry should match the size above.
68 The first file.i entry should match the "Reference size" above.
63 69 The first file.d entry is the temporary record during the split,
64 70 the second entry after the split happened. The sum of the second file.d
65 71 and the second file.i entry should match the first file.i entry.
66 72
67 73 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
68 74 data/file.i 1174
69 75 data/file.d 0
70 data/file.d 1046
71 data/file.i 128
76 data/file.d 1067
77 data/file.i 192
72 78 $ hg recover
73 79 rolling back interrupted transaction
74 80 (verify step skipped, run `hg verify` to check your repository content)
75 81 $ f -s .hg/store/data/file*
76 .hg/store/data/file.d: size=1046
77 .hg/store/data/file.i: size=128
82 .hg/store/data/file.d: size=1067
83 .hg/store/data/file.i: size=192
78 84 $ hg tip
79 changeset: 1:3ce491143aec
85 changeset: 1:cfa8d6e60429
80 86 tag: tip
81 87 user: test
82 88 date: Thu Jan 01 00:00:00 1970 +0000
83 summary: _
89 summary: b
84 90
85 91 $ hg verify -q
86 92 warning: revlog 'data/file.d' not in fncache!
87 1 warnings encountered!
93 file@?: rev 2 points to nonexistent changeset 2
94 (expected )
95 file@?: fa1120531cc1 not in manifests
96 2 warnings encountered!
88 97 hint: run "hg debugrebuildfncache" to recover from corrupt fncache
98 2 integrity errors encountered!
99 [1]
89 100 $ hg debugrebuildfncache --only-data
90 101 adding data/file.d
91 102 1 items added, 0 removed from fncache
92 103 $ hg verify -q
104 file@?: rev 2 points to nonexistent changeset 2
105 (expected )
106 file@?: fa1120531cc1 not in manifests
107 1 warnings encountered!
108 2 integrity errors encountered!
109 [1]
93 110 $ cd ..
94 111
95 112
96 113 Now retry the procedure but intercept the rename of the index and check that
97 114 the journal does not contain the new index size. This demonstrates the edge case
98 115 where the data file is left as garbage.
99 116
100 117 $ hg clone -r 1 troffset-computation troffset-computation-copy2 --config format.revlog-compression=none -q
101 118 $ cd troffset-computation-copy2
102 119 $ cat > .hg/hgrc <<EOF
103 120 > [extensions]
104 121 > intercept_rename = $TESTTMP/intercept_rename.py
105 122 > [hooks]
106 123 > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
107 124 > EOF
108 125 #if chg
109 126 $ hg pull ../troffset-computation
110 127 pulling from ../troffset-computation
111 128 [255]
112 129 #else
113 130 $ hg pull ../troffset-computation
114 131 pulling from ../troffset-computation
115 132 [80]
116 133 #endif
117 134 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
118 135 data/file.i 1174
119 136 data/file.d 0
120 data/file.d 1046
137 data/file.d 1067
121 138
122 139 $ hg recover
123 140 rolling back interrupted transaction
124 141 (verify step skipped, run `hg verify` to check your repository content)
125 142 $ f -s .hg/store/data/file*
126 .hg/store/data/file.d: size=1046
143 .hg/store/data/file.d: size=1067
127 144 .hg/store/data/file.i: size=1174
128 145 $ hg tip
129 changeset: 1:3ce491143aec
146 changeset: 1:cfa8d6e60429
130 147 tag: tip
131 148 user: test
132 149 date: Thu Jan 01 00:00:00 1970 +0000
133 summary: _
150 summary: b
134 151
135 152 $ hg verify -q
136 153 $ cd ..
137 154
138 155
139 156 Repeat the original test but let hg rollback the transaction.
140 157
141 158 $ hg clone -r 1 troffset-computation troffset-computation-copy-rb --config format.revlog-compression=none -q
142 159 $ cd troffset-computation-copy-rb
143 160 $ cat > .hg/hgrc <<EOF
144 161 > [hooks]
145 162 > pretxnchangegroup = false
146 163 > EOF
147 164 $ hg pull ../troffset-computation
148 165 pulling from ../troffset-computation
149 166 searching for changes
150 167 adding changesets
151 168 adding manifests
152 169 adding file changes
153 170 transaction abort!
154 171 rollback completed
155 172 abort: pretxnchangegroup hook exited with status 1
156 173 [40]
157 174 $ f -s .hg/store/data/file*
158 .hg/store/data/file.d: size=1046
159 .hg/store/data/file.i: size=128
175 .hg/store/data/file.d: size=1067
176 .hg/store/data/file.i: size=192
160 177 $ hg tip
161 changeset: 1:3ce491143aec
178 changeset: 1:cfa8d6e60429
162 179 tag: tip
163 180 user: test
164 181 date: Thu Jan 01 00:00:00 1970 +0000
165 summary: _
182 summary: b
166 183
167 184 $ hg verify -q
168 185 warning: revlog 'data/file.d' not in fncache!
169 1 warnings encountered!
186 file@?: rev 2 points to nonexistent changeset 2
187 (expected )
188 file@?: fa1120531cc1 not in manifests
189 2 warnings encountered!
170 190 hint: run "hg debugrebuildfncache" to recover from corrupt fncache
191 2 integrity errors encountered!
192 [1]
171 193 $ cd ..
172 194
General Comments 0
You need to be logged in to leave comments. Login now