sapling/tests/test-fncache.t

437 lines
12 KiB
Perl
Raw Normal View History

2010-08-12 19:30:12 +04:00
Init repo1:
$ hg init repo1
$ cd repo1
$ echo "some text" > a
$ hg add
adding a
$ hg ci -m first
2011-01-28 15:54:38 +03:00
$ cat .hg/store/fncache | sort
2010-08-12 19:30:12 +04:00
data/a.i
Testing a.i/b:
$ mkdir a.i
$ echo "some other text" > a.i/b
$ hg add
adding a.i/b (glob)
2010-08-12 19:30:12 +04:00
$ hg ci -m second
2011-01-28 15:54:38 +03:00
$ cat .hg/store/fncache | sort
2010-08-12 19:30:12 +04:00
data/a.i
data/a.i.hg/b.i
Testing a.i.hg/c:
$ mkdir a.i.hg
$ echo "yet another text" > a.i.hg/c
$ hg add
adding a.i.hg/c (glob)
2010-08-12 19:30:12 +04:00
$ hg ci -m third
2011-01-28 15:54:38 +03:00
$ cat .hg/store/fncache | sort
2010-08-12 19:30:12 +04:00
data/a.i
data/a.i.hg.hg/c.i
2011-01-28 15:54:38 +03:00
data/a.i.hg/b.i
2010-08-12 19:30:12 +04:00
Testing verify:
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
3 files, 3 changesets, 3 total revisions
$ rm .hg/store/fncache
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
warning: revlog 'data/a.i' not in fncache!
warning: revlog 'data/a.i.hg/c.i' not in fncache!
warning: revlog 'data/a.i/b.i' not in fncache!
2010-08-12 19:30:12 +04:00
3 files, 3 changesets, 3 total revisions
3 warnings encountered!
hint: run "hg debugrebuildfncache" to recover from corrupt fncache
Follow the hint to make sure it works
$ hg debugrebuildfncache
adding data/a.i
adding data/a.i.hg/c.i
adding data/a.i/b.i
3 items added, 0 removed from fncache
$ hg verify
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
3 files, 3 changesets, 3 total revisions
2010-08-12 19:30:12 +04:00
$ cd ..
Non store repo:
$ hg --config format.usestore=False init foo
$ cd foo
$ mkdir tst.d
$ echo foo > tst.d/foo
$ hg ci -Amfoo
adding tst.d/foo
$ find .hg | sort
.hg
.hg/00changelog.i
.hg/00manifest.i
.hg/cache
.hg/cache/branch2-served
branchmap: use revbranchcache when updating branch map The revbranchcache is read on demand before it will be used for updating the branch map. It is written back when the branchmap is written and it will thus use the same locking as branchmap. The revbranchcache instance is short-lived; it is only stored in the branchmap from .update() is invoked and until .write() is invoked. Branchmap already assume that the repo is locked in that case. The use of revbranchcache for branch map updates will make sure that the revbranchcache "always" is kept up-to-date. The perfbranchmap benchmark is somewhat bogus, especially when we can see that the caching makes a significant difference between the realistic case of a first run and the rare case of rerunning it with a full cache. Here are some 'base' numbers on mozilla-central: Before: ! wall 6.912745 comb 6.910000 user 6.840000 sys 0.070000 (best of 3) After - initial, cache is empty: ! wall 7.792569 comb 7.790000 user 7.720000 sys 0.070000 (best of 3) After - cache is full: ! wall 0.879688 comb 0.880000 user 0.870000 sys 0.010000 (best of 4) The overhead when running with empty cache comes from checking, missing and updating it every time. Most of the performance improvement comes from not having to extract the branch info from the changelog. The last doubling of performance comes from no longer having to convert all branch names to local encoding but reuse the few already converted branch names. On the hg repo: Before: ! wall 0.715703 comb 0.710000 user 0.710000 sys 0.000000 (best of 14) After: ! wall 0.105489 comb 0.110000 user 0.110000 sys 0.000000 (best of 87)
2015-01-08 02:01:03 +03:00
.hg/cache/rbc-names-v1
.hg/cache/rbc-revs-v1
2010-08-12 19:30:12 +04:00
.hg/data
.hg/data/tst.d.hg
.hg/data/tst.d.hg/foo.i
.hg/dirstate
.hg/fsmonitor.state (fsmonitor !)
2010-08-12 19:30:12 +04:00
.hg/last-message.txt
2011-11-11 03:15:22 +04:00
.hg/phaseroots
2010-08-12 19:30:12 +04:00
.hg/requires
.hg/undo
.hg/undo.backup.dirstate
.hg/undo.backupfiles
.hg/undo.bookmarks
2010-08-12 19:30:12 +04:00
.hg/undo.branch
.hg/undo.desc
.hg/undo.dirstate
2011-11-07 15:27:25 +04:00
.hg/undo.phaseroots
2010-08-12 19:30:12 +04:00
$ cd ..
Non fncache repo:
$ hg --config format.usefncache=False init bar
$ cd bar
$ mkdir tst.d
$ echo foo > tst.d/Foo
$ hg ci -Amfoo
adding tst.d/Foo
$ find .hg | sort
.hg
.hg/00changelog.i
.hg/cache
.hg/cache/branch2-served
branchmap: use revbranchcache when updating branch map The revbranchcache is read on demand before it will be used for updating the branch map. It is written back when the branchmap is written and it will thus use the same locking as branchmap. The revbranchcache instance is short-lived; it is only stored in the branchmap from .update() is invoked and until .write() is invoked. Branchmap already assume that the repo is locked in that case. The use of revbranchcache for branch map updates will make sure that the revbranchcache "always" is kept up-to-date. The perfbranchmap benchmark is somewhat bogus, especially when we can see that the caching makes a significant difference between the realistic case of a first run and the rare case of rerunning it with a full cache. Here are some 'base' numbers on mozilla-central: Before: ! wall 6.912745 comb 6.910000 user 6.840000 sys 0.070000 (best of 3) After - initial, cache is empty: ! wall 7.792569 comb 7.790000 user 7.720000 sys 0.070000 (best of 3) After - cache is full: ! wall 0.879688 comb 0.880000 user 0.870000 sys 0.010000 (best of 4) The overhead when running with empty cache comes from checking, missing and updating it every time. Most of the performance improvement comes from not having to extract the branch info from the changelog. The last doubling of performance comes from no longer having to convert all branch names to local encoding but reuse the few already converted branch names. On the hg repo: Before: ! wall 0.715703 comb 0.710000 user 0.710000 sys 0.000000 (best of 14) After: ! wall 0.105489 comb 0.110000 user 0.110000 sys 0.000000 (best of 87)
2015-01-08 02:01:03 +03:00
.hg/cache/rbc-names-v1
.hg/cache/rbc-revs-v1
2010-08-12 19:30:12 +04:00
.hg/dirstate
.hg/fsmonitor.state (fsmonitor !)
2010-08-12 19:30:12 +04:00
.hg/last-message.txt
.hg/requires
.hg/store
.hg/store/00changelog.i
.hg/store/00manifest.i
.hg/store/data
.hg/store/data/tst.d.hg
.hg/store/data/tst.d.hg/_foo.i
2011-11-11 03:15:22 +04:00
.hg/store/phaseroots
2010-08-12 19:30:12 +04:00
.hg/store/undo
.hg/store/undo.backupfiles
2011-11-07 15:27:25 +04:00
.hg/store/undo.phaseroots
.hg/undo.backup.dirstate
.hg/undo.bookmarks
2010-08-12 19:30:12 +04:00
.hg/undo.branch
.hg/undo.desc
.hg/undo.dirstate
$ cd ..
Encoding of reserved / long paths in the store
$ hg init r2
$ cd r2
$ cat <<EOF > .hg/hgrc
> [ui]
> portablefilenames = ignore
> EOF
$ hg import -q --bypass - <<EOF
> # HG changeset patch
> # User test
> # Date 0 0
> # Node ID 1c7a2f7cb77be1a0def34e4c7cabc562ad98fbd7
> # Parent 0000000000000000000000000000000000000000
> 1
>
> diff --git a/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-123456789-12.3456789-12345-ABCDEFGHIJKLMNOPRSTUVWXYZ-abcdefghjiklmnopqrstuvwxyz b/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-123456789-12.3456789-12345-ABCDEFGHIJKLMNOPRSTUVWXYZ-abcdefghjiklmnopqrstuvwxyz
> new file mode 100644
> --- /dev/null
> +++ b/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxxxxx-xxxxxxxxx-xxxxxxxxx-123456789-12.3456789-12345-ABCDEFGHIJKLMNOPRSTUVWXYZ-abcdefghjiklmnopqrstuvwxyz
> @@ -0,0 +1,1 @@
> +foo
> diff --git a/AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT b/AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT
> new file mode 100644
> --- /dev/null
> +++ b/AUX/SECOND/X.PRN/FOURTH/FI:FTH/SIXTH/SEVENTH/EIGHTH/NINETH/TENTH/ELEVENTH/LOREMIPSUM.TXT
> @@ -0,0 +1,1 @@
> +foo
> diff --git a/Project Planning/Resources/AnotherLongDirectoryName/Followedbyanother/AndAnother/AndThenAnExtremelyLongFileName.txt b/Project Planning/Resources/AnotherLongDirectoryName/Followedbyanother/AndAnother/AndThenAnExtremelyLongFileName.txt
> new file mode 100644
> --- /dev/null
> +++ b/Project Planning/Resources/AnotherLongDirectoryName/Followedbyanother/AndAnother/AndThenAnExtremelyLongFileName.txt
> @@ -0,0 +1,1 @@
> +foo
> diff --git a/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c b/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c
> new file mode 100644
> --- /dev/null
> +++ b/bla.aux/prn/PRN/lpt/com3/nul/coma/foo.NUL/normal.c
> @@ -0,0 +1,1 @@
> +foo
> diff --git a/enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider b/enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider
> new file mode 100644
> --- /dev/null
> +++ b/enterprise/openesbaddons/contrib-imola/corba-bc/netbeansplugin/wsdlExtension/src/main/java/META-INF/services/org.netbeans.modules.xml.wsdl.bindingsupport.spi.ExtensibilityElementTemplateProvider
> @@ -0,0 +1,1 @@
> +foo
> EOF
$ find .hg/store -name *.i | sort
.hg/store/00changelog.i
.hg/store/00manifest.i
.hg/store/data/bla.aux/pr~6e/_p_r_n/lpt/co~6d3/nu~6c/coma/foo._n_u_l/normal.c.i
.hg/store/dh/12345678/12345678/12345678/12345678/12345678/12345678/12345678/12345/xxxxxx168e07b38e65eff86ab579afaaa8e30bfbe0f35f.i
.hg/store/dh/au~78/second/x.prn/fourth/fi~3afth/sixth/seventh/eighth/nineth/tenth/loremia20419e358ddff1bf8751e38288aff1d7c32ec05.i
.hg/store/dh/enterpri/openesba/contrib-/corba-bc/netbeans/wsdlexte/src/main/java/org.net7018f27961fdf338a598a40c4683429e7ffb9743.i
.hg/store/dh/project_/resource/anotherl/followed/andanoth/andthenanextremelylongfilename0d8e1f4187c650e2f1fdca9fd90f786bc0976b6b.i
$ cd ..
Aborting lock does not prevent fncache writes
$ cat > exceptionext.py <<EOF
> from __future__ import absolute_import
> import os
> from mercurial import commands, error, extensions
>
> def lockexception(orig, vfs, lockname, wait, releasefn, *args, **kwargs):
> def releasewrap():
> l.held = False # ensure __del__ is a noop
> raise error.Abort("forced lock failure")
> l = orig(vfs, lockname, wait, releasewrap, *args, **kwargs)
> return l
>
> def reposetup(ui, repo):
> extensions.wrapfunction(repo, '_lock', lockexception)
>
> cmdtable = {}
>
commands: make commit acquire locks before processing (issue4368) Before this patch, "hg commit" (process A) executes steps below: 1. get current branch heads via 'repo.branchheads()' - cache 'repo.changelog' 2. invoke 'repo.commit()' 3. acquire wlock - invalidate 'repo.dirstate' 4. access 'repo.dirstate' - re-read '.hg/dirstate' - check validity of parent revisions with 'repo.changelog' 5. invoke 'repo.commitctx()' 6. acquire store lock (slock) - invalidate 'repo.changelog' 7. do committing 8. release slock 9. release wlock 10. check new branch head (via 'cmdutil.commitstatus()') If acquisition of wlock at (3) above waits for another "hg commit" (process B) or so running parallelly to release wlock, process A causes creating orphan revision, because: - '.hg/dirstate' refers the revision, which is newly added by process B, as its parent - but already cached 'repo.changelog' doesn't contain such revision - therefore, validating parents of '.hg/dirstate' at (4) above replaces such revision with 'nullid' Then, process A creates "orphan" revision, of which parent is "null" revision. In addition to it, "created new head" may be shown at the end of process A unintentionally, if store is updated parallelly, because both getting branch heads (1) and checking new branch head (10) are executed outside slock scope. To avoid this issue, this patch makes "hg commit" acquire wlock and slock before processing. This patch resolves the issue between "hg commit" processes, but not one between "hg commit" and other commands. Subsequent patches resolve the latter. Even after this patch, there are still corner case problems below: - filecache may overlook changes of '.hg/dirstate', and it causes similar issue (see below for detail) https://bz.mercurial-scm.org/show_bug.cgi?id=4368#c10 - 3rd party extension may cause similar issue, if it directly uses 'repo.commit()' without acquisition of wlock and slock This can be fixed by acquisition of slock at the beginning of 'repo.commit()', but it seems suitable for "default" branch In fact, acquisition of slock itself is already introduced at "default" branch by ec227b188932, but acquisition is not at the beginning of 'repo.commit()'. This patch also changes some tests: - test-fncache.t needs this tricky wrapping, to release (= forced failure of) wlock certainly - order of "hg commit" output is changed by widening scope of locks, because some hooks are fired after releasing wlock
2015-12-01 21:12:07 +03:00
> # wrap "commit" command to prevent wlock from being '__del__()'-ed
> # at the end of dispatching (for intentional "forced lcok failure")
> def commitwrap(orig, ui, repo, *pats, **opts):
> repo = repo.unfiltered() # to use replaced repo._lock certainly
> wlock = repo.wlock()
> try:
> return orig(ui, repo, *pats, **opts)
> finally:
> # multiple 'relase()' is needed for complete releasing wlock,
> # because "forced" abort at last releasing store lock
> # prevents wlock from being released at same 'lockmod.release()'
> for i in range(wlock.held):
> wlock.release()
>
> def extsetup(ui):
> extensions.wrapcommand(commands.table, "commit", commitwrap)
> EOF
$ extpath=`pwd`/exceptionext.py
$ hg init fncachetxn
$ cd fncachetxn
$ printf "[extensions]\nexceptionext=$extpath\n" >> .hg/hgrc
$ touch y
$ hg ci -qAm y
abort: forced lock failure
[255]
$ cat .hg/store/fncache
data/y.i
Aborting transaction prevents fncache change
$ cat > ../exceptionext.py <<EOF
> from __future__ import absolute_import
> import os
> from mercurial import commands, error, extensions, localrepo
>
> def wrapper(orig, self, *args, **kwargs):
> tr = orig(self, *args, **kwargs)
> def fail(tr):
> raise error.Abort("forced transaction failure")
> # zzz prefix to ensure it sorted after store.write
> tr.addfinalize('zzz-forcefails', fail)
> return tr
>
> def uisetup(ui):
> extensions.wrapfunction(
> localrepo.localrepository, 'transaction', wrapper)
>
> cmdtable = {}
>
> EOF
Clean cached version
$ rm -f "${extpath}c"
$ rm -Rf "`dirname $extpath`/__pycache__"
$ touch z
$ hg ci -qAm z
transaction abort!
rollback completed
abort: forced transaction failure
[255]
$ cat .hg/store/fncache
data/y.i
Aborted transactions can be recovered later
$ cat > ../exceptionext.py <<EOF
> from __future__ import absolute_import
> import os
> from mercurial import (
> commands,
> error,
> extensions,
> localrepo,
> transaction,
> )
>
> def trwrapper(orig, self, *args, **kwargs):
> tr = orig(self, *args, **kwargs)
> def fail(tr):
> raise error.Abort("forced transaction failure")
> # zzz prefix to ensure it sorted after store.write
> tr.addfinalize('zzz-forcefails', fail)
> return tr
>
> def abortwrapper(orig, self, *args, **kwargs):
> raise error.Abort("forced transaction failure")
>
> def uisetup(ui):
> extensions.wrapfunction(localrepo.localrepository, 'transaction',
> trwrapper)
> extensions.wrapfunction(transaction.transaction, '_abort',
> abortwrapper)
>
> cmdtable = {}
>
> EOF
Clean cached versions
$ rm -f "${extpath}c"
$ rm -Rf "`dirname $extpath`/__pycache__"
$ hg up -q 1
$ touch z
$ hg ci -qAm z 2>/dev/null
[255]
$ cat .hg/store/fncache | sort
data/y.i
data/z.i
$ hg recover
rolling back interrupted transaction
checking changesets
checking manifests
crosschecking files in changesets and manifests
checking files
1 files, 1 changesets, 1 total revisions
$ cat .hg/store/fncache
data/y.i
$ cd ..
debugrebuildfncache does nothing unless repo has fncache requirement
$ hg --config format.usefncache=false init nofncache
$ cd nofncache
$ hg debugrebuildfncache
2015-07-26 15:28:52 +03:00
(not rebuilding fncache because repository does not support fncache)
$ cd ..
debugrebuildfncache works on empty repository
$ hg init empty
$ cd empty
$ hg debugrebuildfncache
fncache already up to date
$ cd ..
debugrebuildfncache on an up to date repository no-ops
$ hg init repo
$ cd repo
$ echo initial > foo
$ echo initial > .bar
$ hg commit -A -m initial
adding .bar
adding foo
$ cat .hg/store/fncache | sort
data/.bar.i
data/foo.i
$ hg debugrebuildfncache
fncache already up to date
debugrebuildfncache restores deleted fncache file
$ rm -f .hg/store/fncache
$ hg debugrebuildfncache
adding data/.bar.i
adding data/foo.i
2 items added, 0 removed from fncache
$ cat .hg/store/fncache | sort
data/.bar.i
data/foo.i
Rebuild after rebuild should no-op
$ hg debugrebuildfncache
fncache already up to date
A single missing file should get restored, an extra file should be removed
$ cat > .hg/store/fncache << EOF
> data/foo.i
> data/bad-entry.i
> EOF
$ hg debugrebuildfncache
removing data/bad-entry.i
adding data/.bar.i
1 items added, 1 removed from fncache
$ cat .hg/store/fncache | sort
data/.bar.i
data/foo.i
$ cd ..
Try a simple variation without dotencode to ensure fncache is ignorant of encoding
$ hg --config format.dotencode=false init nodotencode
$ cd nodotencode
$ echo initial > foo
$ echo initial > .bar
$ hg commit -A -m initial
adding .bar
adding foo
$ cat .hg/store/fncache | sort
data/.bar.i
data/foo.i
$ rm .hg/store/fncache
$ hg debugrebuildfncache
adding data/.bar.i
adding data/foo.i
2 items added, 0 removed from fncache
$ cat .hg/store/fncache | sort
data/.bar.i
data/foo.i