##// END OF EJS Templates
revlog: update data file record before index rename...
Joerg Sonnenberger -
r48065:46b828b8 default
parent child Browse files
Show More
@@ -2190,6 +2190,13 b' class revlog(object):'
2190 fp.write(e)
2190 fp.write(e)
2191 if self._docket is not None:
2191 if self._docket is not None:
2192 self._docket.index_end = fp.tell()
2192 self._docket.index_end = fp.tell()
2193
2194 # There is a small transactional race here. If the rename of
2195 # the index fails, we should remove the datafile. It is more
2196 # important to ensure that the data file is not truncated
2197 # when the index is replaced as otherwise data is lost.
2198 tr.replace(self._datafile, self.start(trindex))
2199
2193 # the temp file replace the real index when we exit the context
2200 # the temp file replace the real index when we exit the context
2194 # manager
2201 # manager
2195
2202
@@ -1,7 +1,27 b''
1 Test correctness of revlog inline -> non-inline transition
1 Test correctness of revlog inline -> non-inline transition
2 ----------------------------------------------------------
2 ----------------------------------------------------------
3
3
4 Helper extension to intercept renames.
5
6 $ cat > $TESTTMP/intercept_rename.py << EOF
7 > import os
8 > import sys
9 > from mercurial import extensions, util
10 >
11 > def extsetup(ui):
12 > def close(orig, *args, **kwargs):
13 > path = args[0]._atomictempfile__name
14 > if path.endswith(b'/.hg/store/data/file.i'):
15 > os._exit(80)
16 > return orig(*args, **kwargs)
17 > extensions.wrapfunction(util.atomictempfile, 'close', close)
18 > EOF
19
20
4 Test offset computation to correctly factor in the index entries themselve.
21 Test offset computation to correctly factor in the index entries themselve.
22 Also test that the new data size has the correct size if the transaction is aborted
23 after the index has been replaced.
24
5 Test repo has one small, one moderate and one big change. The clone has
25 Test repo has one small, one moderate and one big change. The clone has
6 the small and moderate change and will transition to non-inline storage when
26 the small and moderate change and will transition to non-inline storage when
7 adding the big change.
27 adding the big change.
@@ -18,6 +38,12 b' adding the big change.'
18
38
19 $ hg clone -r 1 troffset-computation troffset-computation-copy --config format.revlog-compression=none -q
39 $ hg clone -r 1 troffset-computation troffset-computation-copy --config format.revlog-compression=none -q
20 $ cd troffset-computation-copy
40 $ cd troffset-computation-copy
41
42 Reference size:
43
44 $ f -s .hg/store/data/file*
45 .hg/store/data/file.i: size=1174
46
21 $ cat > .hg/hgrc <<EOF
47 $ cat > .hg/hgrc <<EOF
22 > [hooks]
48 > [hooks]
23 > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
49 > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
@@ -33,3 +59,42 b' adding the big change.'
33 #endif
59 #endif
34 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file | tail -1
60 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file | tail -1
35 data/file.i 128
61 data/file.i 128
62
63 The first file.i entry should match the size above.
64 The first file.d entry is the temporary record during the split,
65 the second entry after the split happened. The sum of the second file.d
66 and the second file.i entry should match the first file.i entry.
67
68 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
69 data/file.i 1174
70 data/file.d 0
71 data/file.d 1046
72 data/file.i 128
73 $ cd ..
74
75 Now retry the same but intercept the rename of the index and check that
76 the journal does not contain the new index size. This demonstrates the edge case
77 where the data file is left as garbage.
78
79 $ hg clone -r 1 troffset-computation troffset-computation-copy2 --config format.revlog-compression=none -q
80 $ cd troffset-computation-copy2
81 $ cat > .hg/hgrc <<EOF
82 > [extensions]
83 > intercept_rename = $TESTTMP/intercept_rename.py
84 > [hooks]
85 > pretxnchangegroup = python:$TESTDIR/helper-killhook.py:killme
86 > EOF
87 #if chg
88 $ hg pull ../troffset-computation
89 pulling from ../troffset-computation
90 [255]
91 #else
92 $ hg pull ../troffset-computation
93 pulling from ../troffset-computation
94 [80]
95 #endif
96 $ cat .hg/store/journal | tr -s '\000' ' ' | grep data/file
97 data/file.i 1174
98 data/file.d 0
99 data/file.d 1046
100 $ cd ..
General Comments 0
You need to be logged in to leave comments. Login now