tests/test-pull-pull-corruption.t
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 24 Feb 2016 06:10:46 +0900
changeset 28265 332926212ef8
parent 16913 f2719b387380
child 34661 eb586ed5d8ce
permissions -rw-r--r--
repoview: discard filtered changelog if index isn't shared with unfiltered Before this patch, revisions rollbacked at failure of previous transaction might be visible at subsequent operations unintentionally, if repoview object is reused even after failure of transaction: e.g. command server and HTTP server are typical cases. 'repoview' uses the tuple of values below of unfiltered changelog as "the key" to examine validity of filtered changelog cache. - length - tip node - filtered revisions (as hashed value) - '_delayed' field 'repoview' compares between "the key" of unfiltered changelog at previous caching and now, and reuses filtered changelog cache if no change is detected. But this comparison indicates only that there is no change between unfiltered 'repo.changelog' at last caching and now, but not that filtered changelog cache is valid for current unfiltered one. 'repoview' uses "shallow copy" of unfiltered changelog to create filtered changelog cache. In this case, 'index' buffer of unfiltered changelog is also referred by filtered changelog. At failure of transaction, unfiltered changelog itself is invalidated (= un-referred) on the 'repo' side (see 0a7610758c42 also). But 'index' of it still contains revisions to be rollbacked at this failure, and is referred by filtered changelog. Therefore, even if there is no change between unfiltered 'repo.changelog' at last caching and now, steps below makes rollbacked revisions visible via filtered changelog unintentionally. 1. instantiate unfiltered changelog as 'repo.changelog' (call it CL1) 2. make filtered (= shallow copy of) CL1 (call it FCL1) 3. cache FCL1 with "the key" of CL1 4. revisions are appended to 'index', which is shared by CL1 and FCL1 5. invalidate 'repo.changelog' (= CL1) at failure of transaction 6. instantiate 'repo.changelog' again at next operation (call it CL2) CL2 doesn't have revisions added at (4), because it is instantiated from '00changelog.i', which isn't changed while failed transaction. 7. compare between "the key" of CL1 and CL2 8. FCL1 cached at (3) is reused, because comparison at (7) doesn't detect change between CL1 at (1) and CL2 9. revisions rollbacked at (5) are visible via FCL1 unintentionally, because FCL1 still refers 'index' changed at (4) The root cause of this issue is that there is no examination about validity of filtered changelog cache against current unfiltered one. This patch discards filtered changelog cache, if its 'index' object isn't shared with unfiltered one. BTW, at the time of this patch, redundant truncation of '00changelog.i' at failure of transaction (see 0a7610758c42 for detail) often prevents "hg serve" from making already rollbacked revisions visible, because updating timestamps of '00changelog.i' by truncation makes "hg serve" discard old repoview object with invalid filtered changelog cache. This is reason why this issue is overlooked before this patch, even though test-bundle2-exchange.t has tests in similar situation: failure of "hg push" via HTTP by pretxnclose hook on server side doesn't prevent subsequent commands from looking up outgoing revisions correctly. But timestamp on the filesystem doesn't have enough resolution for recent computation power, and it can't be assumed that this avoidance always works as expected. Therefore, without this patch, this issue might appear occasionally.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     1
Corrupt an hg repo with two pulls.
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     2
create one repo with a long history
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     3
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     4
  $ hg init source1
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     5
  $ cd source1
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     6
  $ touch foo
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     7
  $ hg add foo
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     8
  $ for i in 1 2 3 4 5 6 7 8 9 10; do
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
     9
  >     echo $i >> foo
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    10
  >     hg ci -m $i
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    11
  > done
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    12
  $ cd ..
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    13
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    14
create one repo with a shorter history
1785
81ca1a9bd061 Added test cases for repo corruption fixed in 2e0a288ca93e (issue132)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    15
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    16
  $ hg clone -r 0 source1 source2
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    17
  adding changesets
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    18
  adding manifests
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    19
  adding file changes
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    20
  added 1 changesets with 1 changes to 1 files
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    21
  updating to branch default
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    22
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    23
  $ cd source2
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    24
  $ echo a >> foo
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    25
  $ hg ci -m a
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    26
  $ cd ..
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    27
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    28
create a third repo to pull both other repos into it
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    29
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    30
  $ hg init corrupted
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    31
  $ cd corrupted
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    32
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    33
use a hook to make the second pull start while the first one is still running
1785
81ca1a9bd061 Added test cases for repo corruption fixed in 2e0a288ca93e (issue132)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    34
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    35
  $ echo '[hooks]' >> .hg/hgrc
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    36
  $ echo 'prechangegroup = sleep 5' >> .hg/hgrc
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    37
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    38
start a pull...
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    39
16481
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    40
  $ hg pull ../source1 > pull.out 2>&1 &
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    41
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    42
... and start another pull before the first one has finished
1785
81ca1a9bd061 Added test cases for repo corruption fixed in 2e0a288ca93e (issue132)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    43
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    44
  $ sleep 1
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    45
  $ hg pull ../source2 2>/dev/null
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    46
  pulling from ../source2
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    47
  searching for changes
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    48
  adding changesets
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    49
  adding manifests
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    50
  adding file changes
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    51
  added 1 changesets with 1 changes to 1 files (+1 heads)
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    52
  (run 'hg heads' to see heads, 'hg merge' to merge)
16481
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    53
  $ cat pull.out
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    54
  pulling from ../source1
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    55
  requesting all changes
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    56
  adding changesets
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    57
  adding manifests
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    58
  adding file changes
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    59
  added 10 changesets with 10 changes to 1 files
37e0872b5ced tests: remove race in test-pull-pull-corruption.t
Mads Kiilerich <mads@kiilerich.com>
parents: 13439
diff changeset
    60
  (run 'hg update' to get a working copy)
1785
81ca1a9bd061 Added test cases for repo corruption fixed in 2e0a288ca93e (issue132)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    61
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    62
see the result
1785
81ca1a9bd061 Added test cases for repo corruption fixed in 2e0a288ca93e (issue132)
Thomas Arendsen Hein <thomas@intevation.de>
parents:
diff changeset
    63
12481
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    64
  $ wait
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    65
  $ hg verify
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    66
  checking changesets
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    67
  checking manifests
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    68
  crosschecking files in changesets and manifests
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    69
  checking files
70ef9b470efe tests: unify test-pull-pull-corruption
Matt Mackall <mpm@selenic.com>
parents: 1785
diff changeset
    70
  1 files, 11 changesets, 11 total revisions
16913
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 16481
diff changeset
    71
f2719b387380 tests: add missing trailing 'cd ..'
Mads Kiilerich <mads@kiilerich.com>
parents: 16481
diff changeset
    72
  $ cd ..