| 1 |
Test transaction safety |
| 2 |
======================= |
| 3 |
|
| 4 |
#testcases revlogv1 revlogv2 changelogv2 |
| 5 |
|
| 6 |
#if revlogv1 |
| 7 |
|
| 8 |
$ cat << EOF >> $HGRCPATH |
| 9 |
> [experimental] |
| 10 |
> revlogv2=no |
| 11 |
> EOF |
| 12 |
|
| 13 |
#endif |
| 14 |
|
| 15 |
#if revlogv2 |
| 16 |
|
| 17 |
$ cat << EOF >> $HGRCPATH |
| 18 |
> [experimental] |
| 19 |
> revlogv2=enable-unstable-format-and-corrupt-my-data |
| 20 |
> [storage] |
| 21 |
> fileindex.slow-path=allow |
| 22 |
> EOF |
| 23 |
|
| 24 |
#endif |
| 25 |
|
| 26 |
#if changelogv2 |
| 27 |
|
| 28 |
$ cat << EOF >> $HGRCPATH |
| 29 |
> [format] |
| 30 |
> exp-use-changelog-v2=enable-unstable-format-and-corrupt-my-data |
| 31 |
> EOF |
| 32 |
|
| 33 |
#endif |
| 34 |
|
| 35 |
This test basic case to make sure external process do not see transaction |
| 36 |
content until it is committed. |
| 37 |
|
| 38 |
# TODO: also add an external reader accessing revlog files while they are written |
| 39 |
# (instead of during transaction finalisation) |
| 40 |
|
| 41 |
# TODO: also add stream clone and hardlink clone happening during these transaction. |
| 42 |
|
| 43 |
setup |
| 44 |
----- |
| 45 |
|
| 46 |
synchronisation+output script using the following schedule: |
| 47 |
|
| 48 |
[A1] "external" is started |
| 49 |
[A2] "external" waits on EXT_UNLOCK |
| 50 |
[A2] "external" + creates EXT_WAITING → unlocks [C1] |
| 51 |
[B1] "hg commit/pull" is started |
| 52 |
[B2] "hg commit/pull" is ready to be committed |
| 53 |
[B3] "hg commit/pull" spawn "internal" using a pretxnclose hook (need [C4]) |
| 54 |
[C1] "internal" waits on EXT_WAITING (need [A2]) |
| 55 |
[C2] "internal" creates EXT_UNLOCK → unlocks [A2] |
| 56 |
[C3] "internal" show the tipmost revision (inside of the transaction) |
| 57 |
[C4] "internal" waits on EXT_DONE (need [A4]) |
| 58 |
[A3] "external" show the tipmost revision (outside of the transaction) |
| 59 |
[A4] "external" creates EXT_DONE → unlocks [C4] |
| 60 |
[C5] "internal" end of execution -> unlock [B3] |
| 61 |
[B4] "hg commit/pull" transaction is committed on disk |
| 62 |
|
| 63 |
|
| 64 |
$ mkdir sync |
| 65 |
$ mkdir output |
| 66 |
$ mkdir script |
| 67 |
$ HG_TEST_FILE_EXT_WAITING=$TESTTMP/sync/ext_waiting |
| 68 |
$ export HG_TEST_FILE_EXT_WAITING |
| 69 |
$ HG_TEST_FILE_EXT_UNLOCK=$TESTTMP/sync/ext_unlock |
| 70 |
$ export HG_TEST_FILE_EXT_UNLOCK |
| 71 |
$ HG_TEST_FILE_EXT_DONE=$TESTTMP/sync/ext_done |
| 72 |
$ export HG_TEST_FILE_EXT_DONE |
| 73 |
$ cat << EOF > script/external.sh |
| 74 |
> #!/bin/sh |
| 75 |
> "$RUNTESTDIR/testlib/wait-on-file" 5 "$HG_TEST_FILE_EXT_UNLOCK" "$HG_TEST_FILE_EXT_WAITING" |
| 76 |
> hg log --rev 'tip' -T 'external: {rev} {desc}\n' > "$TESTTMP/output/external.out" |
| 77 |
> touch "$HG_TEST_FILE_EXT_DONE" |
| 78 |
> EOF |
| 79 |
$ cat << EOF > script/internal.sh |
| 80 |
> #!/bin/sh |
| 81 |
> "$RUNTESTDIR/testlib/wait-on-file" 5 "$HG_TEST_FILE_EXT_WAITING" |
| 82 |
> touch "$HG_TEST_FILE_EXT_UNLOCK" |
| 83 |
> hg log --rev 'tip' -T 'internal: {rev} {desc}\n' > "$TESTTMP/output/internal.out" |
| 84 |
> "$RUNTESTDIR/testlib/wait-on-file" 5 "$HG_TEST_FILE_EXT_DONE" |
| 85 |
> EOF |
| 86 |
|
| 87 |
|
| 88 |
Automated commands: |
| 89 |
|
| 90 |
$ make_one_commit() { |
| 91 |
> rm -f $TESTTMP/sync/* |
| 92 |
> rm -f $TESTTMP/output/* |
| 93 |
> hg log --rev 'tip' -T 'pre-commit: {rev} {desc}\n' |
| 94 |
> echo x >> of |
| 95 |
> sh $TESTTMP/script/external.sh & hg commit -m "$1" |
| 96 |
> cat $TESTTMP/output/external.out |
| 97 |
> cat $TESTTMP/output/internal.out |
| 98 |
> hg log --rev 'tip' -T 'post-tr: {rev} {desc}\n' |
| 99 |
> } |
| 100 |
|
| 101 |
|
| 102 |
$ make_one_pull() { |
| 103 |
> rm -f $TESTTMP/sync/* |
| 104 |
> rm -f $TESTTMP/output/* |
| 105 |
> hg log --rev 'tip' -T 'pre-commit: {rev} {desc}\n' |
| 106 |
> echo x >> of |
| 107 |
> sh $TESTTMP/script/external.sh & hg pull ../other-repo/ --rev "$1" --force --quiet |
| 108 |
> cat $TESTTMP/output/external.out |
| 109 |
> cat $TESTTMP/output/internal.out |
| 110 |
> hg log --rev 'tip' -T 'post-tr: {rev} {desc}\n' |
| 111 |
> } |
| 112 |
|
| 113 |
prepare a large source to which to pull from: |
| 114 |
|
| 115 |
The source is large to unsure we don't use inline more after the pull |
| 116 |
|
| 117 |
$ hg init other-repo |
| 118 |
$ hg -R other-repo debugbuilddag .+500 --overwritten-file |
| 119 |
|
| 120 |
|
| 121 |
prepare an empty repository where to make test: |
| 122 |
|
| 123 |
$ hg init repo |
| 124 |
$ cd repo |
| 125 |
$ touch of |
| 126 |
$ hg add of |
| 127 |
|
| 128 |
prepare a small extension to controll inline size |
| 129 |
|
| 130 |
$ mkdir $TESTTMP/ext |
| 131 |
$ cat << EOF > $TESTTMP/ext/small_inline.py |
| 132 |
> from mercurial import revlog |
| 133 |
> revlog._maxinline = 3 * 100 |
| 134 |
> EOF |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
$ cat << EOF >> $HGRCPATH |
| 140 |
> [extensions] |
| 141 |
> small_inline=$TESTTMP/ext/small_inline.py |
| 142 |
> [hooks] |
| 143 |
> pretxnclose = sh $TESTTMP/script/internal.sh |
| 144 |
> EOF |
| 145 |
|
| 146 |
check this is true for the initial commit (inline → inline) |
| 147 |
----------------------------------------------------------- |
| 148 |
|
| 149 |
the repository should still be inline (for relevant format) |
| 150 |
|
| 151 |
$ make_one_commit first |
| 152 |
pre-commit: -1 |
| 153 |
external: -1 |
| 154 |
internal: 0 first |
| 155 |
post-tr: 0 first |
| 156 |
|
| 157 |
#if revlogv1 |
| 158 |
|
| 159 |
$ hg debugrevlog of | grep inline |
| 160 |
flags : inline, * (glob) |
| 161 |
|
| 162 |
#endif |
| 163 |
|
| 164 |
check this is true for extra commit (inline → inline) |
| 165 |
----------------------------------------------------- |
| 166 |
|
| 167 |
the repository should still be inline (for relevant format) |
| 168 |
|
| 169 |
#if revlogv1 |
| 170 |
|
| 171 |
$ hg debugrevlog of | grep inline |
| 172 |
flags : inline, * (glob) |
| 173 |
|
| 174 |
#endif |
| 175 |
|
| 176 |
$ make_one_commit second |
| 177 |
pre-commit: 0 first |
| 178 |
external: 0 first |
| 179 |
internal: 1 second |
| 180 |
post-tr: 1 second |
| 181 |
|
| 182 |
#if revlogv1 |
| 183 |
|
| 184 |
$ hg debugrevlog of | grep inline |
| 185 |
flags : inline, * (glob) |
| 186 |
|
| 187 |
#endif |
| 188 |
|
| 189 |
check this is true for a small pull (inline → inline) |
| 190 |
----------------------------------------------------- |
| 191 |
|
| 192 |
the repository should still be inline (for relevant format) |
| 193 |
|
| 194 |
#if revlogv1 |
| 195 |
|
| 196 |
$ hg debugrevlog of | grep inline |
| 197 |
flags : inline, * (glob) |
| 198 |
|
| 199 |
#endif |
| 200 |
|
| 201 |
$ make_one_pull 3 |
| 202 |
pre-commit: 1 second |
| 203 |
warning: repository is unrelated |
| 204 |
external: 1 second |
| 205 |
internal: 5 r3 |
| 206 |
post-tr: 5 r3 |
| 207 |
|
| 208 |
#if revlogv1 |
| 209 |
|
| 210 |
$ hg debugrevlog of | grep inline |
| 211 |
flags : inline, * (glob) |
| 212 |
|
| 213 |
#endif |
| 214 |
|
| 215 |
Make a large pull (inline → no-inline) |
| 216 |
--------------------------------------- |
| 217 |
|
| 218 |
the repository should no longer be inline (for relevant format) |
| 219 |
|
| 220 |
#if revlogv1 |
| 221 |
|
| 222 |
$ hg debugrevlog of | grep inline |
| 223 |
flags : inline, * (glob) |
| 224 |
|
| 225 |
#endif |
| 226 |
|
| 227 |
$ make_one_pull 400 |
| 228 |
pre-commit: 5 r3 |
| 229 |
external: 5 r3 |
| 230 |
internal: 402 r400 |
| 231 |
post-tr: 402 r400 |
| 232 |
|
| 233 |
#if revlogv1 |
| 234 |
|
| 235 |
$ hg debugrevlog of | grep inline |
| 236 |
[1] |
| 237 |
|
| 238 |
#endif |
| 239 |
|
| 240 |
check this is true for extra commit (no-inline → no-inline) |
| 241 |
----------------------------------------------------------- |
| 242 |
|
| 243 |
the repository should no longer be inline (for relevant format) |
| 244 |
|
| 245 |
#if revlogv1 |
| 246 |
|
| 247 |
$ hg debugrevlog of | grep inline |
| 248 |
[1] |
| 249 |
|
| 250 |
#endif |
| 251 |
|
| 252 |
$ make_one_commit third |
| 253 |
pre-commit: 402 r400 |
| 254 |
external: 402 r400 |
| 255 |
internal: 403 third |
| 256 |
post-tr: 403 third |
| 257 |
|
| 258 |
#if revlogv1 |
| 259 |
|
| 260 |
$ hg debugrevlog of | grep inline |
| 261 |
[1] |
| 262 |
|
| 263 |
#endif |
| 264 |
|
| 265 |
|
| 266 |
Make a pull (not-inline → no-inline) |
| 267 |
------------------------------------- |
| 268 |
|
| 269 |
the repository should no longer be inline (for relevant format) |
| 270 |
|
| 271 |
#if revlogv1 |
| 272 |
|
| 273 |
$ hg debugrevlog of | grep inline |
| 274 |
[1] |
| 275 |
|
| 276 |
#endif |
| 277 |
|
| 278 |
$ make_one_pull tip |
| 279 |
pre-commit: 403 third |
| 280 |
external: 403 third |
| 281 |
internal: 503 r500 |
| 282 |
post-tr: 503 r500 |
| 283 |
|
| 284 |
#if revlogv1 |
| 285 |
|
| 286 |
$ hg debugrevlog of | grep inline |
| 287 |
[1] |
| 288 |
|
| 289 |
#endif |