| 1 |
===================================================================== |
| 2 |
Check potential race conditions between a status and other operations |
| 3 |
===================================================================== |
| 4 |
|
| 5 |
#testcases dirstate-v1 dirstate-v2-append dirstate-v2-rewrite |
| 6 |
|
| 7 |
The `hg status` command can run without the wlock, however it might end up |
| 8 |
having to update the on-disk dirstate files, for example to mark ambiguous |
| 9 |
files as clean, or to update directory caches information with dirstate-v2. |
| 10 |
|
| 11 |
|
| 12 |
If another process updates the dirstate in the meantime we might run into |
| 13 |
trouble. Especially, commands doing semantic changes like `hg add` or |
| 14 |
`hg commit` should not see their update erased by a concurrent status. |
| 15 |
|
| 16 |
Unlike commands like `add` or `commit`, `status` only writes the dirstate |
| 17 |
to update caches, no actual information is lost if we fail to write to disk. |
| 18 |
|
| 19 |
|
| 20 |
This test file is meant to test various cases where such parallel operations |
| 21 |
between a status with reasons to update the dirstate and another semantic |
| 22 |
changes happen. |
| 23 |
|
| 24 |
|
| 25 |
Setup |
| 26 |
===== |
| 27 |
|
| 28 |
$ cat >> $HGRCPATH << EOF |
| 29 |
> [storage] |
| 30 |
> dirstate-v2.slow-path=allow |
| 31 |
> EOF |
| 32 |
|
| 33 |
#if no-dirstate-v1 |
| 34 |
$ cat >> $HGRCPATH << EOF |
| 35 |
> [format] |
| 36 |
> use-dirstate-v2=yes |
| 37 |
> EOF |
| 38 |
#else |
| 39 |
$ cat >> $HGRCPATH << EOF |
| 40 |
> [format] |
| 41 |
> use-dirstate-v2=no |
| 42 |
> EOF |
| 43 |
#endif |
| 44 |
|
| 45 |
#if dirstate-v2-rewrite |
| 46 |
$ d2args="--config devel.dirstate.v2.data_update_mode=force-new" |
| 47 |
#endif |
| 48 |
#if dirstate-v2-append |
| 49 |
$ d2args="--config devel.dirstate.v2.data_update_mode=force-append" |
| 50 |
#endif |
| 51 |
|
| 52 |
$ directories="dir dir/nested dir2" |
| 53 |
$ first_files="dir/nested/a dir/b dir/c dir/d dir2/e f" |
| 54 |
$ second_files="g dir/nested/h dir/i dir/j dir2/k dir2/l dir/nested/m" |
| 55 |
$ extra_files="dir/n dir/o p q" |
| 56 |
|
| 57 |
$ hg init reference-repo |
| 58 |
$ cd reference-repo |
| 59 |
$ mkdir -p dir/nested dir2 |
| 60 |
$ touch -t 200001010000 $first_files $directories |
| 61 |
$ hg commit -Aqm "recreate a bunch of files to facilitate dirstate-v2 append" |
| 62 |
$ touch -t 200001010010 $second_files $directories |
| 63 |
$ hg commit -Aqm "more files to have two commits" |
| 64 |
$ hg log -G -v |
| 65 |
@ changeset: 1:c349430a1631 |
| 66 |
| tag: tip |
| 67 |
| user: test |
| 68 |
| date: Thu Jan 01 00:00:00 1970 +0000 |
| 69 |
| files: dir/i dir/j dir/nested/h dir/nested/m dir2/k dir2/l g |
| 70 |
| description: |
| 71 |
| more files to have two commits |
| 72 |
| |
| 73 |
| |
| 74 |
o changeset: 0:4f23db756b09 |
| 75 |
user: test |
| 76 |
date: Thu Jan 01 00:00:00 1970 +0000 |
| 77 |
files: dir/b dir/c dir/d dir/nested/a dir2/e f |
| 78 |
description: |
| 79 |
recreate a bunch of files to facilitate dirstate-v2 append |
| 80 |
|
| 81 |
|
| 82 |
$ hg manifest |
| 83 |
dir/b |
| 84 |
dir/c |
| 85 |
dir/d |
| 86 |
dir/i |
| 87 |
dir/j |
| 88 |
dir/nested/a |
| 89 |
dir/nested/h |
| 90 |
dir/nested/m |
| 91 |
dir2/e |
| 92 |
dir2/k |
| 93 |
dir2/l |
| 94 |
f |
| 95 |
g |
| 96 |
|
| 97 |
Add some unknown files and refresh the dirstate |
| 98 |
|
| 99 |
$ touch -t 200001010020 $extra_files |
| 100 |
$ hg add dir/o |
| 101 |
$ hg remove dir/nested/m |
| 102 |
|
| 103 |
$ hg st --config devel.dirstate.v2.data_update_mode=force-new |
| 104 |
A dir/o |
| 105 |
R dir/nested/m |
| 106 |
? dir/n |
| 107 |
? p |
| 108 |
? q |
| 109 |
$ hg debugstate |
| 110 |
n 644 0 2000-01-01 00:00:00 dir/b |
| 111 |
n 644 0 2000-01-01 00:00:00 dir/c |
| 112 |
n 644 0 2000-01-01 00:00:00 dir/d |
| 113 |
n 644 0 2000-01-01 00:10:00 dir/i |
| 114 |
n 644 0 2000-01-01 00:10:00 dir/j |
| 115 |
n 644 0 2000-01-01 00:00:00 dir/nested/a |
| 116 |
n 644 0 2000-01-01 00:10:00 dir/nested/h |
| 117 |
r ?????????????????????????????????? dir/nested/m (glob) |
| 118 |
a ?????????????????????????????????? dir/o (glob) |
| 119 |
n 644 0 2000-01-01 00:00:00 dir2/e |
| 120 |
n 644 0 2000-01-01 00:10:00 dir2/k |
| 121 |
n 644 0 2000-01-01 00:10:00 dir2/l |
| 122 |
n 644 0 2000-01-01 00:00:00 f |
| 123 |
n 644 0 2000-01-01 00:10:00 g |
| 124 |
$ hg debugstate > ../reference |
| 125 |
$ cd .. |
| 126 |
|
| 127 |
Explain / verify the test principles |
| 128 |
------------------------------------ |
| 129 |
|
| 130 |
First, we can properly copy the reference |
| 131 |
|
| 132 |
$ cp -a reference-repo sanity-check |
| 133 |
$ cd sanity-check |
| 134 |
$ hg debugstate |
| 135 |
n 644 0 2000-01-01 00:00:00 dir/b |
| 136 |
n 644 0 2000-01-01 00:00:00 dir/c |
| 137 |
n 644 0 2000-01-01 00:00:00 dir/d |
| 138 |
n 644 0 2000-01-01 00:10:00 dir/i |
| 139 |
n 644 0 2000-01-01 00:10:00 dir/j |
| 140 |
n 644 0 2000-01-01 00:00:00 dir/nested/a |
| 141 |
n 644 0 2000-01-01 00:10:00 dir/nested/h |
| 142 |
r ?????????????????????????????????? dir/nested/m (glob) |
| 143 |
a ?????????????????????????????????? dir/o (glob) |
| 144 |
n 644 0 2000-01-01 00:00:00 dir2/e |
| 145 |
n 644 0 2000-01-01 00:10:00 dir2/k |
| 146 |
n 644 0 2000-01-01 00:10:00 dir2/l |
| 147 |
n 644 0 2000-01-01 00:00:00 f |
| 148 |
n 644 0 2000-01-01 00:10:00 g |
| 149 |
$ hg debugstate > ../post-copy |
| 150 |
$ diff ../reference ../post-copy |
| 151 |
|
| 152 |
And status thinks the cache is in a proper state |
| 153 |
|
| 154 |
$ hg st |
| 155 |
A dir/o |
| 156 |
R dir/nested/m |
| 157 |
? dir/n |
| 158 |
? p |
| 159 |
? q |
| 160 |
$ hg debugstate |
| 161 |
n 644 0 2000-01-01 00:00:00 dir/b |
| 162 |
n 644 0 2000-01-01 00:00:00 dir/c |
| 163 |
n 644 0 2000-01-01 00:00:00 dir/d |
| 164 |
n 644 0 2000-01-01 00:10:00 dir/i |
| 165 |
n 644 0 2000-01-01 00:10:00 dir/j |
| 166 |
n 644 0 2000-01-01 00:00:00 dir/nested/a |
| 167 |
n 644 0 2000-01-01 00:10:00 dir/nested/h |
| 168 |
r ?????????????????????????????????? dir/nested/m (glob) |
| 169 |
a ?????????????????????????????????? dir/o (glob) |
| 170 |
n 644 0 2000-01-01 00:00:00 dir2/e |
| 171 |
n 644 0 2000-01-01 00:10:00 dir2/k |
| 172 |
n 644 0 2000-01-01 00:10:00 dir2/l |
| 173 |
n 644 0 2000-01-01 00:00:00 f |
| 174 |
n 644 0 2000-01-01 00:10:00 g |
| 175 |
$ hg debugstate > ../post-status |
| 176 |
$ diff ../reference ../post-status |
| 177 |
|
| 178 |
Then we can start a status that: |
| 179 |
- has some update to do (the touch call) |
| 180 |
- will wait AFTER running status, but before updating the cache on disk |
| 181 |
|
| 182 |
$ touch -t 200001010001 dir/c |
| 183 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 184 |
> --config rhg.on-unsupported=abort \ |
| 185 |
> --config devel.sync.status.pre-dirstate-write-file=$TESTTMP/status-race-lock \ |
| 186 |
> & |
| 187 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 188 |
|
| 189 |
We check it runs the status first by modifying a file and updating another timestamp |
| 190 |
|
| 191 |
$ touch -t 200001010003 dir/i |
| 192 |
$ echo babar > dir/j |
| 193 |
$ touch $TESTTMP/status-race-lock |
| 194 |
$ wait |
| 195 |
|
| 196 |
The test process should have reported a status before the change we made, |
| 197 |
and should have missed the timestamp update |
| 198 |
|
| 199 |
$ cat $TESTTMP/status-race-lock.out |
| 200 |
A dir/o |
| 201 |
R dir/nested/m |
| 202 |
? dir/n |
| 203 |
? p |
| 204 |
? q |
| 205 |
$ cat $TESTTMP/status-race-lock.log |
| 206 |
$ hg debugstate | grep dir/c |
| 207 |
n 644 0 2000-01-01 00:01:00 dir/c |
| 208 |
$ hg debugstate | grep dir/i |
| 209 |
n 644 0 2000-01-01 00:10:00 dir/i |
| 210 |
$ hg debugstate | grep dir/j |
| 211 |
n 644 0 2000-01-01 00:10:00 dir/j |
| 212 |
|
| 213 |
final cleanup |
| 214 |
|
| 215 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 216 |
$ cd .. |
| 217 |
|
| 218 |
Actual Testing |
| 219 |
============== |
| 220 |
|
| 221 |
Race with a `hg add` |
| 222 |
------------------- |
| 223 |
|
| 224 |
$ cp -a reference-repo race-with-add |
| 225 |
$ cd race-with-add |
| 226 |
|
| 227 |
spin a `hg status` with some caches to update |
| 228 |
|
| 229 |
$ touch -t 200001020001 f |
| 230 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 231 |
> --config rhg.on-unsupported=abort \ |
| 232 |
> --config devel.sync.status.pre-dirstate-write-file=$TESTTMP/status-race-lock \ |
| 233 |
> & |
| 234 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 235 |
|
| 236 |
Add a file |
| 237 |
|
| 238 |
$ hg $d2args add dir/n |
| 239 |
$ touch $TESTTMP/status-race-lock |
| 240 |
$ wait |
| 241 |
|
| 242 |
The file should in a "added" state |
| 243 |
|
| 244 |
$ hg status |
| 245 |
A dir/n |
| 246 |
A dir/o |
| 247 |
R dir/nested/m |
| 248 |
? p |
| 249 |
? q |
| 250 |
|
| 251 |
The status process should return a consistent result and not crash. |
| 252 |
|
| 253 |
$ cat $TESTTMP/status-race-lock.out |
| 254 |
A dir/o |
| 255 |
R dir/nested/m |
| 256 |
? dir/n |
| 257 |
? p |
| 258 |
? q |
| 259 |
$ cat $TESTTMP/status-race-lock.log |
| 260 |
|
| 261 |
final cleanup |
| 262 |
|
| 263 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 264 |
$ cd .. |
| 265 |
|
| 266 |
Race with a `hg commit` |
| 267 |
---------------------- |
| 268 |
|
| 269 |
$ cp -a reference-repo race-with-commit |
| 270 |
$ cd race-with-commit |
| 271 |
|
| 272 |
spin a `hg status` with some caches to update |
| 273 |
|
| 274 |
$ touch -t 200001020001 dir/j |
| 275 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 276 |
> --config rhg.on-unsupported=abort \ |
| 277 |
> --config devel.sync.status.pre-dirstate-write-file=$TESTTMP/status-race-lock \ |
| 278 |
> & |
| 279 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 280 |
|
| 281 |
Add a file and force the data file rewrite |
| 282 |
|
| 283 |
$ hg $d2args commit -m created-during-status dir/o |
| 284 |
$ touch $TESTTMP/status-race-lock |
| 285 |
$ wait |
| 286 |
|
| 287 |
The parent must change and the status should be clean |
| 288 |
|
| 289 |
$ hg summary |
| 290 |
parent: 2:2e3b442a2fd4 tip |
| 291 |
created-during-status |
| 292 |
branch: default |
| 293 |
commit: 1 removed, 3 unknown |
| 294 |
update: (current) |
| 295 |
phases: 3 draft |
| 296 |
$ hg status |
| 297 |
R dir/nested/m |
| 298 |
? dir/n |
| 299 |
? p |
| 300 |
? q |
| 301 |
|
| 302 |
The status process should return a consistent result and not crash. |
| 303 |
|
| 304 |
$ cat $TESTTMP/status-race-lock.out |
| 305 |
A dir/o |
| 306 |
R dir/nested/m |
| 307 |
? dir/n |
| 308 |
? p |
| 309 |
? q |
| 310 |
$ cat $TESTTMP/status-race-lock.log |
| 311 |
|
| 312 |
final cleanup |
| 313 |
|
| 314 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 315 |
$ cd .. |
| 316 |
|
| 317 |
Race with a `hg update` |
| 318 |
---------------------- |
| 319 |
|
| 320 |
$ cp -a reference-repo race-with-update |
| 321 |
$ cd race-with-update |
| 322 |
|
| 323 |
spin a `hg status` with some caches to update |
| 324 |
|
| 325 |
$ touch -t 200001020001 dir2/k |
| 326 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 327 |
> --config rhg.on-unsupported=abort \ |
| 328 |
> --config devel.sync.status.pre-dirstate-write-file=$TESTTMP/status-race-lock \ |
| 329 |
> & |
| 330 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 331 |
|
| 332 |
Add a file and force the data file rewrite |
| 333 |
|
| 334 |
$ hg $d2args update ".~1" |
| 335 |
0 files updated, 0 files merged, 6 files removed, 0 files unresolved |
| 336 |
$ touch $TESTTMP/status-race-lock |
| 337 |
$ wait |
| 338 |
|
| 339 |
The parent must change and the status should be clean |
| 340 |
|
| 341 |
$ hg summary |
| 342 |
parent: 0:4f23db756b09 |
| 343 |
recreate a bunch of files to facilitate dirstate-v2 append |
| 344 |
branch: default |
| 345 |
commit: 1 added, 3 unknown (new branch head) |
| 346 |
update: 1 new changesets (update) |
| 347 |
phases: 2 draft |
| 348 |
$ hg status |
| 349 |
A dir/o |
| 350 |
? dir/n |
| 351 |
? p |
| 352 |
? q |
| 353 |
|
| 354 |
The status process should return a consistent result and not crash. |
| 355 |
|
| 356 |
$ cat $TESTTMP/status-race-lock.out |
| 357 |
A dir/o |
| 358 |
R dir/nested/m |
| 359 |
? dir/n |
| 360 |
? p |
| 361 |
? q |
| 362 |
$ cat $TESTTMP/status-race-lock.log |
| 363 |
|
| 364 |
final cleanup |
| 365 |
|
| 366 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 367 |
$ cd .. |
| 368 |
|
| 369 |
Race with another status |
| 370 |
------------------------ |
| 371 |
|
| 372 |
$ cp -a reference-repo race-with-status |
| 373 |
$ cd race-with-status |
| 374 |
|
| 375 |
spin a `hg status` with some caches to update |
| 376 |
|
| 377 |
$ touch -t 200001010030 dir/nested/h |
| 378 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 379 |
> --config rhg.on-unsupported=abort \ |
| 380 |
> --config devel.sync.status.pre-dirstate-write-file=$TESTTMP/status-race-lock \ |
| 381 |
> & |
| 382 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 383 |
|
| 384 |
touch g |
| 385 |
|
| 386 |
$ touch -t 200001010025 g |
| 387 |
$ hg $d2args status |
| 388 |
A dir/o |
| 389 |
R dir/nested/m |
| 390 |
? dir/n |
| 391 |
? p |
| 392 |
? q |
| 393 |
$ touch $TESTTMP/status-race-lock |
| 394 |
$ wait |
| 395 |
|
| 396 |
the first update should be on disk |
| 397 |
|
| 398 |
$ hg debugstate --all | grep "g" |
| 399 |
n 644 0 2000-01-01 00:25:00 g |
| 400 |
|
| 401 |
The status process should return a consistent result and not crash. |
| 402 |
|
| 403 |
$ cat $TESTTMP/status-race-lock.out |
| 404 |
A dir/o |
| 405 |
R dir/nested/m |
| 406 |
? dir/n |
| 407 |
? p |
| 408 |
? q |
| 409 |
$ cat $TESTTMP/status-race-lock.log |
| 410 |
|
| 411 |
final cleanup |
| 412 |
|
| 413 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 414 |
$ cd .. |
| 415 |
|
| 416 |
Race with the removal of an ambiguous file |
| 417 |
----------------------รจ------------------- |
| 418 |
|
| 419 |
$ cp -a reference-repo race-with-remove |
| 420 |
$ cd race-with-remove |
| 421 |
|
| 422 |
spin a `hg status` with some caches to update |
| 423 |
|
| 424 |
$ touch -t 200001010035 dir2/l |
| 425 |
$ hg st >$TESTTMP/status-race-lock.out 2>$TESTTMP/status-race-lock.log \ |
| 426 |
> --config rhg.on-unsupported=abort \ |
| 427 |
> --config devel.sync.status.pre-dirstate-write-file=$TESTTMP/status-race-lock \ |
| 428 |
> & |
| 429 |
$ $RUNTESTDIR/testlib/wait-on-file 5 $TESTTMP/status-race-lock.waiting |
| 430 |
|
| 431 |
remove that same file |
| 432 |
|
| 433 |
$ hg $d2args remove dir2/l |
| 434 |
$ touch $TESTTMP/status-race-lock |
| 435 |
$ wait |
| 436 |
|
| 437 |
file should be marked as removed |
| 438 |
|
| 439 |
$ hg status |
| 440 |
A dir/o |
| 441 |
R dir/nested/m |
| 442 |
R dir2/l |
| 443 |
? dir/n |
| 444 |
? p |
| 445 |
? q |
| 446 |
|
| 447 |
The status process should return a consistent result and not crash. |
| 448 |
|
| 449 |
$ cat $TESTTMP/status-race-lock.out |
| 450 |
A dir/o |
| 451 |
R dir/nested/m |
| 452 |
? dir/n |
| 453 |
? p |
| 454 |
? q |
| 455 |
$ cat $TESTTMP/status-race-lock.log |
| 456 |
|
| 457 |
final cleanup |
| 458 |
|
| 459 |
$ rm $TESTTMP/status-race-lock $TESTTMP/status-race-lock.waiting |
| 460 |
$ cd .. |