view tests/test-strip-cross.t @ 46607:e9901d01d135

revlog: add a mechanism to verify expected file position before appending If someone uses `hg debuglocks`, or some non-hg process writes to the .hg directory without respecting the locks, or if the repo's on a networked filesystem, it's possible for the revlog code to write out corrupted data. The form of this corruption can vary depending on what data was written and how that happened. We are in the "networked filesystem" case (though I've had users also do this to themselves with the "`hg debuglocks`" scenario), and most often see this with the changelog. What ends up happening is we produce two items (let's call them rev1 and rev2) in the .i file that have the same linkrev, baserev, and offset into the .d file, while the data in the .d file is appended properly. rev2's compressed_size is accurate for rev2, but when we go to decompress the data in the .d file, we use the offset that's recorded in the index file, which is the same as rev1, and attempt to decompress rev2.compressed_size bytes of rev1's data. This usually does not succeed. :) When using inline data, this also fails, though I haven't investigated why too closely. This shows up as a "patch decode" error. I believe what's happening there is that we're basically ignoring the offset field, getting the data properly, but since baserev != rev, it thinks this is a delta based on rev (instead of a full text) and can't actually apply it as such. For now, I'm going to make this an optional component and default it to entirely off. I may increase the default severity of this in the future, once I've enabled it for my users and we gain more experience with it. Luckily, most of my users have a versioned filesystem and can roll back to before the corruption has been written, it's just a hassle to do so and not everyone knows how (so it's a support burden). Users on other filesystems will not have that luxury, and this can cause them to have a corrupted repository that they are unlikely to know how to resolve, and they'll see this as a data-loss event. Refusing to create the corruption is a much better user experience. This mechanism is not perfect. There may be false-negatives (racy writes that are not detected). There should not be any false-positives (non-racy writes that are detected as such). This is not a mechanism that makes putting a repo on a networked filesystem "safe" or "supported", just *less* likely to cause corruption. Differential Revision: https://phab.mercurial-scm.org/D9952
author Kyle Lippincott <spectral@google.com>
date Wed, 03 Feb 2021 16:33:10 -0800
parents a8b249b2f8cc
children ccd76e292be5
line wrap: on
line source

test stripping of filelogs where the linkrev doesn't always increase

  $ echo '[extensions]' >> $HGRCPATH
  $ echo 'strip =' >> $HGRCPATH
  $ commit()
  > {
  >     hg up -qC null
  >     count=1
  >     for i in "$@"; do
  >         for f in $i; do
  >             mkdir -p `dirname $f`
  >             echo $count > $f
  >         done
  >         count=`expr $count + 1`
  >     done
  >     hg commit -qAm "$*"
  > }

2 1 0 2 0 1 2

  $ mkdir files
  $ cd files
  $ hg init orig
  $ cd orig
  $ commit '201 210'
  $ commit '102 120' '210'
  $ commit '021'
  $ commit '201' '021 120'
  $ commit '012 021' '102 201' '120 210'
  $ commit '102 120' '012 210' '021 201'
  $ commit '201 210' '021 120' '012 102'
  $ cd ..
  $ hg clone -q -U -r 4 -r 5 -r 6 orig crossed
  $ cd crossed

  $ for i in 012 021 102 120 201 210; do
  >     echo $i
  >     hg debugindex $i
  >     echo
  > done
  012
     rev linkrev nodeid       p1           p2
       0       0 b8e02f643373 000000000000 000000000000
       1       1 5d9299349fc0 000000000000 000000000000
       2       2 2661d26c6496 000000000000 000000000000
  
  021
     rev linkrev nodeid       p1           p2
       0       0 b8e02f643373 000000000000 000000000000
       1       2 5d9299349fc0 000000000000 000000000000
       2       1 2661d26c6496 000000000000 000000000000
  
  102
     rev linkrev nodeid       p1           p2
       0       1 b8e02f643373 000000000000 000000000000
       1       0 5d9299349fc0 000000000000 000000000000
       2       2 2661d26c6496 000000000000 000000000000
  
  120
     rev linkrev nodeid       p1           p2
       0       1 b8e02f643373 000000000000 000000000000
       1       2 5d9299349fc0 000000000000 000000000000
       2       0 2661d26c6496 000000000000 000000000000
  
  201
     rev linkrev nodeid       p1           p2
       0       2 b8e02f643373 000000000000 000000000000
       1       0 5d9299349fc0 000000000000 000000000000
       2       1 2661d26c6496 000000000000 000000000000
  
  210
     rev linkrev nodeid       p1           p2
       0       2 b8e02f643373 000000000000 000000000000
       1       1 5d9299349fc0 000000000000 000000000000
       2       0 2661d26c6496 000000000000 000000000000
  
  $ cd ..
  $ for i in 0 1 2; do
  >     hg clone -q -U --pull crossed $i
  >     echo "% Trying to strip revision $i"
  >     hg --cwd $i strip $i
  >     echo "% Verifying"
  >     hg --cwd $i verify
  >     echo
  > done
  % Trying to strip revision 0
  saved backup bundle to $TESTTMP/files/0/.hg/strip-backup/cbb8c2f0a2e3-239800b9-backup.hg
  % Verifying
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  checked 2 changesets with 12 changes to 6 files
  
  % Trying to strip revision 1
  saved backup bundle to $TESTTMP/files/1/.hg/strip-backup/124ecc0cbec9-6104543f-backup.hg
  % Verifying
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  checked 2 changesets with 12 changes to 6 files
  
  % Trying to strip revision 2
  saved backup bundle to $TESTTMP/files/2/.hg/strip-backup/f6439b304a1a-c6505a5f-backup.hg
  % Verifying
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  checked 2 changesets with 12 changes to 6 files
  
  $ cd ..

Do a similar test where the manifest revlog has unordered linkrevs
  $ mkdir manifests
  $ cd manifests
  $ hg init orig
  $ cd orig
  $ commit 'file'
  $ commit 'other'
  $ commit '' 'other'
  $ HGUSER=another-user; export HGUSER
  $ commit 'file'
  $ commit 'other' 'file'
  $ cd ..
  $ hg clone -q -U -r 1 -r 2 -r 3 -r 4 orig crossed
  $ cd crossed
  $ hg debugindex --manifest
     rev linkrev nodeid       p1           p2
       0       2 6bbc6fee55c2 000000000000 000000000000
       1       0 1c556153fe54 000000000000 000000000000
       2       1 1f76dba919fd 000000000000 000000000000
       3       3 bbee06ad59d5 000000000000 000000000000

  $ cd ..
  $ for i in 2 3; do
  >     hg clone -q -U --pull crossed $i
  >     echo "% Trying to strip revision $i"
  >     hg --cwd $i strip $i
  >     echo "% Verifying"
  >     hg --cwd $i verify
  >     echo
  > done
  % Trying to strip revision 2
  saved backup bundle to $TESTTMP/manifests/2/.hg/strip-backup/f3015ad03c03-4d98bdc2-backup.hg
  % Verifying
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  checked 3 changesets with 3 changes to 2 files
  
  % Trying to strip revision 3
  saved backup bundle to $TESTTMP/manifests/3/.hg/strip-backup/9632aa303aa4-69192e3f-backup.hg
  % Verifying
  checking changesets
  checking manifests
  crosschecking files in changesets and manifests
  checking files
  checked 3 changesets with 3 changes to 2 files
  
  $ cd ..

Now a similar test for a non-root manifest revlog
  $ cat >> $HGRCPATH <<EOF
  > [experimental]
  > treemanifests = yes
  > EOF
  $ mkdir treemanifests
  $ cd treemanifests
  $ 
  $ hg --config experimental.treemanifest=True init orig
  $ cd orig
  $ commit 'dir/file'
  $ commit 'dir/other'
  $ commit '' 'dir/other'
  $ HGUSER=yet-another-user; export HGUSER
  $ commit 'otherdir dir/file'
  $ commit 'otherdir dir/other' 'otherdir dir/file'
  $ cd ..
  $ hg --config experimental.treemanifest=True clone -q -U -r 1 -r 2 -r 3 -r 4 orig crossed
  $ cd crossed
  $ hg debugindex --dir dir
     rev linkrev nodeid       p1           p2
       0       2 6bbc6fee55c2 000000000000 000000000000
       1       0 1c556153fe54 000000000000 000000000000
       2       1 1f76dba919fd 000000000000 000000000000
       3       3 bbee06ad59d5 000000000000 000000000000

  $ cd ..
  $ for i in 2 3; do
  >     hg --config experimental.treemanifest=True clone -q -U --pull crossed $i
  >     echo "% Trying to strip revision $i"
  >     hg --cwd $i strip $i
  >     echo "% Verifying"
  >     hg --cwd $i verify
  >     echo
  > done
  % Trying to strip revision 2
  saved backup bundle to $TESTTMP/treemanifests/2/.hg/strip-backup/145f5c75f9ac-a105cfbe-backup.hg
  % Verifying
  checking changesets
  checking manifests
  checking directory manifests
  crosschecking files in changesets and manifests
  checking files
  checked 3 changesets with 4 changes to 3 files
  
  % Trying to strip revision 3
  saved backup bundle to $TESTTMP/treemanifests/3/.hg/strip-backup/e4e3de5c3cb2-f4c70376-backup.hg
  % Verifying
  checking changesets
  checking manifests
  checking directory manifests
  crosschecking files in changesets and manifests
  checking files
  checked 3 changesets with 4 changes to 3 files
  
  $ cd ..