Mercurial > hg
view tests/test-sparse.t @ 40326:fed697fa1734
sqlitestore: file storage backend using SQLite
This commit provides an extension which uses SQLite to store file
data (as opposed to revlogs).
As the inline documentation describes, there are still several
aspects to the extension that are incomplete. But it's a start.
The extension does support basic clone, checkout, and commit
workflows, which makes it suitable for simple use cases.
One notable missing feature is support for "bundlerepos." This is
probably responsible for the most test failures when the extension
is activated as part of the test suite.
All revision data is stored in SQLite. Data is stored as zstd
compressed chunks (default if zstd is available), zlib compressed
chunks (default if zstd is not available), or raw chunks (if
configured or if a compressed delta is not smaller than the raw
delta). This makes things very similar to revlogs.
Unlike revlogs, the extension doesn't yet enforce a limit on delta
chain length. This is an obvious limitation and should be addressed.
This is somewhat mitigated by the use of zstd, which is much faster
than zlib to decompress.
There is a dedicated table for storing deltas. Deltas are stored
by the SHA-1 hash of their uncompressed content. The "fileindex" table
has columns that reference the delta for each revision and the base
delta that delta should be applied against. A recursive SQL query
is used to resolve the delta chain along with the delta data.
By storing deltas by hash, we are able to de-duplicate delta storage!
With revlogs, the same deltas in different revlogs would result in
duplicate storage of that delta. In this scheme, inserting the
duplicate delta is a no-op and delta chains simply reference the
existing delta.
When initially implementing this extension, I did not have
content-indexed deltas and deltas could be duplicated across files
(just like revlogs). When I implemented content-indexed deltas, the
size of the SQLite database for a full clone of mozilla-unified
dropped:
before: 2,554,261,504 bytes
after: 2,488,754,176 bytes
Surprisingly, this is still larger than the bytes size of revlog
files:
revlog files: 2,104,861,230 bytes
du -b: 2,254,381,614
I would have expected storage to be smaller since we're not limiting
delta chain length and since we're using zstd instead of zlib. I
suspect the SQLite indexes and per-column overhead account for the
bulk of the differences. (Keep in mind that revlog uses a 64-byte
packed struct for revision index data and deltas are stored without
padding. Aside from the 12 unused bytes in the 32 byte node field,
revlogs are pretty efficient.) Another source of overhead is file
name storage. With revlogs, file names are stored in the filesystem.
But with SQLite, we need to store file names in the database. This is
roughly equivalent to the size of the fncache file, which for the
mozilla-unified repository is ~34MB.
Since the SQLite database isn't append-only and since delta chains
can reference any delta, this opens some interesting possibilities.
For example, we could store deltas in reverse, such that fulltexts
are stored for newer revisions and deltas are applied to reconstruct
older revisions. This is likely a more optimal storage strategy for
version control, as new data tends to be more frequently accessed
than old data. We would obviously need wire protocol support for
transferring revision data from newest to oldest. And we would
probably need some kind of mechanism for "re-encoding" stores. But
it should be doable.
This extension is very much experimental quality. There are a handful
of features that don't work. It probably isn't suitable for day-to-day
use. But it could be used in limited cases (e.g. read-only checkouts
like in CI). And it is also a good proving ground for alternate
storage backends. As we continue to define interfaces for all things
storage, it will be useful to have a viable alternate storage backend
to see how things shake out in practice.
test-storage.py passes on Python 2 and introduces no new test failures on
Python 3. Having the storage-level unit tests has proved to be insanely
useful when developing this extension. Those tests caught numerous bugs
during development and I'm convinced this style of testing is the way
forward for ensuring alternate storage backends work as intended. Of
course, test coverage isn't close to what it needs to be. But it is
a start. And what coverage we have gives me confidence that basic store
functionality is implemented properly.
Differential Revision: https://phab.mercurial-scm.org/D4928
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Tue, 09 Oct 2018 08:50:13 -0700 |
parents | 7e99b02768ef |
children | 5c2a4f37eace |
line wrap: on
line source
test sparse $ hg init myrepo $ cd myrepo $ cat > .hg/hgrc <<EOF > [extensions] > sparse= > strip= > EOF $ echo a > show $ echo x > hide $ hg ci -Aqm 'initial' $ echo b > show $ echo y > hide $ echo aa > show2 $ echo xx > hide2 $ hg ci -Aqm 'two' Verify basic --include $ hg up -q 0 $ hg debugsparse --include 'hide' $ ls hide Absolute paths outside the repo should just be rejected #if no-windows $ hg debugsparse --include /foo/bar abort: paths cannot be absolute [255] $ hg debugsparse --include '$TESTTMP/myrepo/hide' $ hg debugsparse --include '/root' abort: paths cannot be absolute [255] #else TODO: See if this can be made to fail the same way as on Unix $ hg debugsparse --include /c/foo/bar abort: paths cannot be absolute [255] $ hg debugsparse --include '$TESTTMP/myrepo/hide' $ hg debugsparse --include '/c/root' abort: paths cannot be absolute [255] #endif Paths should be treated as cwd-relative, not repo-root-relative $ mkdir subdir && cd subdir $ hg debugsparse --include path $ hg debugsparse [include] $TESTTMP/myrepo/hide hide subdir/path $ cd .. $ echo hello > subdir/file2.ext $ cd subdir $ hg debugsparse --include '**.ext' # let us test globs $ hg debugsparse --include 'path:abspath' # and a path: pattern $ cd .. $ hg debugsparse [include] $TESTTMP/myrepo/hide hide path:abspath subdir/**.ext subdir/path $ rm -rf subdir Verify commiting while sparse includes other files $ echo z > hide $ hg ci -Aqm 'edit hide' $ ls hide $ hg manifest hide show Verify --reset brings files back $ hg debugsparse --reset $ ls hide show $ cat hide z $ cat show a Verify 'hg debugsparse' default output $ hg up -q null $ hg debugsparse --include 'show*' $ hg debugsparse [include] show* Verify update only writes included files $ hg up -q 0 $ ls show $ hg up -q 1 $ ls show show2 Verify status only shows included files $ touch hide $ touch hide3 $ echo c > show $ hg status M show Adding an excluded file should fail $ hg add hide3 abort: cannot add 'hide3' - it is outside the sparse checkout (include file with `hg debugsparse --include <pattern>` or use `hg add -s <file>` to include file directory while adding) [255] But adding a truly excluded file shouldn't count $ hg add hide3 -X hide3 Verify deleting sparseness while a file has changes fails $ hg debugsparse --delete 'show*' pending changes to 'hide' abort: cannot change sparseness due to pending changes (delete the files or use --force to bring them back dirty) [255] Verify deleting sparseness with --force brings back files $ hg debugsparse --delete -f 'show*' pending changes to 'hide' $ ls hide hide2 hide3 show show2 $ hg st M hide M show ? hide3 Verify editing sparseness fails if pending changes $ hg debugsparse --include 'show*' pending changes to 'hide' abort: could not update sparseness due to pending changes [255] Verify adding sparseness hides files $ hg debugsparse --exclude -f 'hide*' pending changes to 'hide' $ ls hide hide3 show show2 $ hg st M show $ hg up -qC . TODO: add an option to purge to also purge files outside the sparse config? $ hg purge --all --config extensions.purge= $ ls hide hide3 show show2 For now, manually remove the files $ rm hide hide3 Verify rebase temporarily includes excluded files $ hg rebase -d 1 -r 2 --config extensions.rebase= rebasing 2:b91df4f39e75 "edit hide" (tip) temporarily included 2 file(s) in the sparse checkout for merging merging hide warning: conflicts while merging hide! (edit, then use 'hg resolve --mark') unresolved conflicts (see hg resolve, then hg rebase --continue) [1] $ hg debugsparse [exclude] hide* Temporarily Included Files (for merge/rebase): hide $ cat hide <<<<<<< dest: 39278f7c08a9 - test: two y ======= z >>>>>>> source: b91df4f39e75 - test: edit hide Verify aborting a rebase cleans up temporary files $ hg rebase --abort --config extensions.rebase= cleaned up 1 temporarily added file(s) from the sparse checkout rebase aborted $ rm hide.orig $ ls show show2 Verify merge fails if merging excluded files $ hg up -q 1 $ hg merge -r 2 temporarily included 2 file(s) in the sparse checkout for merging merging hide warning: conflicts while merging hide! (edit, then use 'hg resolve --mark') 0 files updated, 0 files merged, 0 files removed, 1 files unresolved use 'hg resolve' to retry unresolved file merges or 'hg merge --abort' to abandon [1] $ hg debugsparse [exclude] hide* Temporarily Included Files (for merge/rebase): hide $ hg up -C . cleaned up 1 temporarily added file(s) from the sparse checkout 1 files updated, 0 files merged, 0 files removed, 0 files unresolved $ hg debugsparse [exclude] hide* Verify strip -k resets dirstate correctly $ hg status $ hg debugsparse [exclude] hide* $ hg log -r . -T '{rev}\n' --stat 1 hide | 2 +- hide2 | 1 + show | 2 +- show2 | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) $ hg strip -r . -k saved backup bundle to $TESTTMP/myrepo/.hg/strip-backup/39278f7c08a9-ce59e002-backup.hg $ hg status M show ? show2 Verify rebase succeeds if all changed files are in sparse checkout $ hg commit -Aqm "add show2" $ hg rebase -d 1 --config extensions.rebase= rebasing 2:bdde55290160 "add show2" (tip) saved backup bundle to $TESTTMP/myrepo/.hg/strip-backup/bdde55290160-216ed9c6-rebase.hg Verify log --sparse only shows commits that affect the sparse checkout $ hg log -T '{rev} ' 2 1 0 (no-eol) $ hg log --sparse -T '{rev} ' 2 0 (no-eol) Test status on a file in a subdir $ mkdir -p dir1/dir2 $ touch dir1/dir2/file $ hg debugsparse -I dir1/dir2 $ hg status ? dir1/dir2/file Mix files and subdirectories, both "glob:" and unprefixed $ hg debugsparse --reset $ touch dir1/notshown $ hg commit -A dir1/notshown -m "notshown" $ hg debugsparse --include 'dir1/dir2' $ "$PYTHON" $TESTDIR/list-tree.py . | egrep -v '\.[\/]\.hg' ./ ./dir1/ ./dir1/dir2/ ./dir1/dir2/file ./hide.orig $ hg debugsparse --delete 'dir1/dir2' $ hg debugsparse --include 'glob:dir1/dir2' $ "$PYTHON" $TESTDIR/list-tree.py . | egrep -v '\.[\/]\.hg' ./ ./dir1/ ./dir1/dir2/ ./dir1/dir2/file ./hide.orig Test that add -s adds dirs to sparse profile $ hg debugsparse --reset $ hg debugsparse --include empty $ hg debugsparse [include] empty $ mkdir add $ touch add/foo $ touch add/bar $ hg add add/foo abort: cannot add 'add/foo' - it is outside the sparse checkout (include file with `hg debugsparse --include <pattern>` or use `hg add -s <file>` to include file directory while adding) [255] $ hg add -s add/foo $ hg st A add/foo ? add/bar $ hg debugsparse [include] add empty $ hg add -s add/* add/foo already tracked! $ hg st A add/bar A add/foo $ hg debugsparse [include] add empty $ cd .. Test non-sparse repos work while sparse is loaded $ hg init sparserepo $ hg init nonsparserepo $ cd sparserepo $ cat > .hg/hgrc <<EOF > [extensions] > sparse= > EOF $ cd ../nonsparserepo $ echo x > x && hg add x && hg commit -qAm x $ cd ../sparserepo $ hg clone ../nonsparserepo ../nonsparserepo2 updating to branch default 1 files updated, 0 files merged, 0 files removed, 0 files unresolved Test debugrebuilddirstate $ cd ../sparserepo $ touch included $ touch excluded $ hg add included excluded $ hg commit -m 'a commit' -q $ cp .hg/dirstate ../dirstateboth $ hg debugsparse -X excluded $ cp ../dirstateboth .hg/dirstate $ hg debugrebuilddirstate $ hg debugdirstate n 0 -1 unset included Test debugdirstate --minimal where file is in the parent manifest but not the dirstate $ hg debugsparse -X included $ hg debugdirstate $ cp .hg/dirstate ../dirstateallexcluded $ hg debugsparse --reset $ hg debugsparse -X excluded $ cp ../dirstateallexcluded .hg/dirstate $ touch includedadded $ hg add includedadded $ hg debugdirstate --no-dates a 0 -1 unset includedadded $ hg debugrebuilddirstate --minimal $ hg debugdirstate --no-dates n 0 -1 unset included a 0 -1 * includedadded (glob) Test debugdirstate --minimal where a file is not in parent manifest but in the dirstate. This should take into account excluded files in the manifest $ cp ../dirstateboth .hg/dirstate $ touch includedadded $ hg add includedadded $ touch excludednomanifest $ hg add excludednomanifest $ cp .hg/dirstate ../moreexcluded $ hg forget excludednomanifest $ rm excludednomanifest $ hg debugsparse -X excludednomanifest $ cp ../moreexcluded .hg/dirstate $ hg manifest excluded included We have files in the dirstate that are included and excluded. Some are in the manifest and some are not. $ hg debugdirstate --no-dates n 644 0 * excluded (glob) a 0 -1 * excludednomanifest (glob) n 644 0 * included (glob) a 0 -1 * includedadded (glob) $ hg debugrebuilddirstate --minimal $ hg debugdirstate --no-dates n 644 0 * included (glob) a 0 -1 * includedadded (glob)