Mercurial > hg
view tests/test-narrow-exchange.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 | 95c4cca641f6 |
children | 6fc57680cfd6 |
line wrap: on
line source
#testcases lfs-on lfs-off #if lfs-on $ cat >> $HGRCPATH <<EOF > [extensions] > lfs = > EOF #endif $ . "$TESTDIR/narrow-library.sh" create full repo $ hg init master $ cd master $ cat >> .hg/hgrc <<EOF > [narrow] > serveellipses=True > EOF $ mkdir inside $ echo 1 > inside/f $ mkdir inside2 $ echo 1 > inside2/f $ mkdir outside $ echo 1 > outside/f $ hg ci -Aqm 'initial' $ echo 2 > inside/f $ hg ci -qm 'inside 2' $ echo 2 > inside2/f $ hg ci -qm 'inside2 2' $ echo 2 > outside/f $ hg ci -qm 'outside 2' $ cd .. $ hg clone --narrow ssh://user@dummy/master narrow --include inside requesting all changes adding changesets adding manifests adding file changes added 3 changesets with 2 changes to 1 files new changesets *:* (glob) updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg clone --narrow ssh://user@dummy/master narrow2 --include inside --include inside2 requesting all changes adding changesets adding manifests adding file changes added 4 changesets with 4 changes to 2 files new changesets *:* (glob) updating to branch default 2 files updated, 0 files merged, 0 files removed, 0 files unresolved Can push to wider repo if change does not affect paths in wider repo that are not also in narrower repo $ cd narrow $ echo 3 > inside/f $ hg ci -m 'inside 3' $ hg push ssh://user@dummy/narrow2 pushing to ssh://user@dummy/narrow2 searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files Can push to narrower repo if change affects only paths within remote's narrow spec $ cd ../narrow2 $ cat >> .hg/hgrc <<EOF > [narrow] > serveellipses=True > EOF $ hg co -r 'desc("inside 3")' 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo 4 > inside/f $ hg ci -m 'inside 4' $ hg push ssh://user@dummy/narrow pushing to ssh://user@dummy/narrow searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 1 changes to 1 files Can push to narrow repo if change affects only paths outside remote's narrow spec $ echo 3 > inside2/f $ hg ci -m 'inside2 3' TODO: this should be successful $ hg push ssh://user@dummy/narrow pushing to ssh://user@dummy/narrow searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: transaction abort! remote: rollback completed remote: abort: data/inside2/f.i@4a1aa07735e6: unknown parent (reporevlogstore !) remote: abort: data/inside2/f/index@4a1aa07735e6: no node (reposimplestore !) abort: stream ended unexpectedly (got 0 bytes, expected 4) [255] Can pull from wider repo if change affects only paths outside remote's narrow spec $ echo 4 > inside2/f $ hg ci -m 'inside2 4' $ hg log -G -T '{rev} {node|short} {files}\n' @ 7 d78a96df731d inside2/f | o 6 8c26f5218962 inside2/f | o 5 ba3480e2f9de inside/f | o 4 4e5edd526618 inside/f | o 3 81e7e07b7ab0 outside/f | o 2 f3993b8c0c2b inside2/f | o 1 8cd66ca966b4 inside/f | o 0 c8057d6f53ab inside/f inside2/f outside/f $ cd ../narrow $ hg log -G -T '{rev} {node|short} {files}\n' o 4 ba3480e2f9de inside/f | @ 3 4e5edd526618 inside/f | o 2 81e7e07b7ab0 outside/f | o 1 8cd66ca966b4 inside/f | o 0 c8057d6f53ab inside/f inside2/f outside/f $ hg pull ssh://user@dummy/narrow2 pulling from ssh://user@dummy/narrow2 searching for changes adding changesets adding manifests adding file changes added 1 changesets with 0 changes to 0 files new changesets d78a96df731d (run 'hg update' to get a working copy) Check that the resulting history is valid in the full repo $ cd ../narrow2 $ hg push ssh://user@dummy/master pushing to ssh://user@dummy/master searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 4 changesets with 4 changes to 2 files $ cd ../master $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 8 changesets with 10 changes to 3 files Can not push to wider repo if change affects paths in wider repo that are not also in narrower repo $ cd ../master $ hg co -r 'desc("inside2 4")' 2 files updated, 0 files merged, 0 files removed, 0 files unresolved $ echo 5 > inside2/f $ hg ci -m 'inside2 5' $ hg log -G -T '{rev} {node|short} {files}\n' @ 8 5970befb64ba inside2/f | o 7 d78a96df731d inside2/f | o 6 8c26f5218962 inside2/f | o 5 ba3480e2f9de inside/f | o 4 4e5edd526618 inside/f | o 3 81e7e07b7ab0 outside/f | o 2 f3993b8c0c2b inside2/f | o 1 8cd66ca966b4 inside/f | o 0 c8057d6f53ab inside/f inside2/f outside/f $ cd ../narrow $ hg pull pulling from ssh://user@dummy/master searching for changes adding changesets adding manifests adding file changes added 1 changesets with 0 changes to 0 files new changesets * (glob) (run 'hg update' to get a working copy) TODO: this should tell the user that their narrow clone does not have the necessary content to be able to push to the target TODO: lfs shouldn't abort like this $ hg push ssh://user@dummy/narrow2 || true pushing to ssh://user@dummy/narrow2 searching for changes remote: adding changesets remote: adding manifests remote: adding file changes remote: added 1 changesets with 0 changes to 0 files (no-lfs-on !) remote: error: pretxnchangegroup.lfs hook raised an exception: data/inside2/f.i@f59b4e021835: no match found (lfs-on !) remote: transaction abort! (lfs-on !) remote: rollback completed (lfs-on !) remote: abort: data/inside2/f.i@f59b4e021835: no match found (lfs-on !) abort: stream ended unexpectedly (got 0 bytes, expected 4) (lfs-on !)