Mercurial > hg
view tests/test-verify.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 | f1186c292d03 |
children | e1936ae27897 |
line wrap: on
line source
#require reporevlogstore prepare repo $ hg init a $ cd a $ echo "some text" > FOO.txt $ echo "another text" > bar.txt $ echo "more text" > QUICK.txt $ hg add adding FOO.txt adding QUICK.txt adding bar.txt $ hg ci -mtest1 verify $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 1 changesets with 3 changes to 3 files verify with journal $ touch .hg/store/journal $ hg verify abandoned transaction found - run hg recover checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 1 changesets with 3 changes to 3 files $ rm .hg/store/journal introduce some bugs in repo $ cd .hg/store/data $ mv _f_o_o.txt.i X_f_o_o.txt.i $ mv bar.txt.i xbar.txt.i $ rm _q_u_i_c_k.txt.i $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files warning: revlog 'data/FOO.txt.i' not in fncache! 0: empty or missing FOO.txt FOO.txt@0: manifest refers to unknown revision f62022d3d590 warning: revlog 'data/QUICK.txt.i' not in fncache! 0: empty or missing QUICK.txt QUICK.txt@0: manifest refers to unknown revision 88b857db8eba warning: revlog 'data/bar.txt.i' not in fncache! 0: empty or missing bar.txt bar.txt@0: manifest refers to unknown revision 256559129457 checked 1 changesets with 0 changes to 3 files 3 warnings encountered! hint: run "hg debugrebuildfncache" to recover from corrupt fncache 6 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cd ../../.. $ cd .. Set up a repo for testing missing revlog entries $ hg init missing-entries $ cd missing-entries $ echo 0 > file $ hg ci -Aqm0 $ cp -R .hg/store .hg/store-partial $ echo 1 > file $ hg ci -Aqm1 $ cp -R .hg/store .hg/store-full Entire changelog missing $ rm .hg/store/00changelog.* $ hg verify -q 0: empty or missing changelog manifest@0: d0b6632564d4 not in changesets manifest@1: 941fc4534185 not in changesets 3 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Entire manifest log missing $ rm .hg/store/00manifest.* $ hg verify -q 0: empty or missing manifest 1 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Entire filelog missing $ rm .hg/store/data/file.* $ hg verify -q warning: revlog 'data/file.i' not in fncache! 0: empty or missing file file@0: manifest refers to unknown revision 362fef284ce2 file@1: manifest refers to unknown revision c10f2164107d 1 warnings encountered! hint: run "hg debugrebuildfncache" to recover from corrupt fncache 3 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Entire changelog and manifest log missing $ rm .hg/store/00changelog.* $ rm .hg/store/00manifest.* $ hg verify -q warning: orphan data file 'data/file.i' 1 warnings encountered! $ cp -R .hg/store-full/. .hg/store Entire changelog and filelog missing $ rm .hg/store/00changelog.* $ rm .hg/store/data/file.* $ hg verify -q 0: empty or missing changelog manifest@0: d0b6632564d4 not in changesets manifest@1: 941fc4534185 not in changesets warning: revlog 'data/file.i' not in fncache! ?: empty or missing file file@0: manifest refers to unknown revision 362fef284ce2 file@1: manifest refers to unknown revision c10f2164107d 1 warnings encountered! hint: run "hg debugrebuildfncache" to recover from corrupt fncache 6 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Entire manifest log and filelog missing $ rm .hg/store/00manifest.* $ rm .hg/store/data/file.* $ hg verify -q 0: empty or missing manifest warning: revlog 'data/file.i' not in fncache! 0: empty or missing file 1 warnings encountered! hint: run "hg debugrebuildfncache" to recover from corrupt fncache 2 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Changelog missing entry $ cp -f .hg/store-partial/00changelog.* .hg/store $ hg verify -q manifest@?: rev 1 points to nonexistent changeset 1 manifest@?: 941fc4534185 not in changesets file@?: rev 1 points to nonexistent changeset 1 (expected 0) 1 warnings encountered! 3 integrity errors encountered! [1] $ cp -R .hg/store-full/. .hg/store Manifest log missing entry $ cp -f .hg/store-partial/00manifest.* .hg/store $ hg verify -q manifest@1: changeset refers to unknown revision 941fc4534185 file@1: c10f2164107d not in manifests 2 integrity errors encountered! (first damaged changeset appears to be 1) [1] $ cp -R .hg/store-full/. .hg/store Filelog missing entry $ cp -f .hg/store-partial/data/file.* .hg/store/data $ hg verify -q file@1: manifest refers to unknown revision c10f2164107d 1 integrity errors encountered! (first damaged changeset appears to be 1) [1] $ cp -R .hg/store-full/. .hg/store Changelog and manifest log missing entry $ cp -f .hg/store-partial/00changelog.* .hg/store $ cp -f .hg/store-partial/00manifest.* .hg/store $ hg verify -q file@?: rev 1 points to nonexistent changeset 1 (expected 0) file@?: c10f2164107d not in manifests 1 warnings encountered! 2 integrity errors encountered! [1] $ cp -R .hg/store-full/. .hg/store Changelog and filelog missing entry $ cp -f .hg/store-partial/00changelog.* .hg/store $ cp -f .hg/store-partial/data/file.* .hg/store/data $ hg verify -q manifest@?: rev 1 points to nonexistent changeset 1 manifest@?: 941fc4534185 not in changesets file@?: manifest refers to unknown revision c10f2164107d 3 integrity errors encountered! [1] $ cp -R .hg/store-full/. .hg/store Manifest and filelog missing entry $ cp -f .hg/store-partial/00manifest.* .hg/store $ cp -f .hg/store-partial/data/file.* .hg/store/data $ hg verify -q manifest@1: changeset refers to unknown revision 941fc4534185 1 integrity errors encountered! (first damaged changeset appears to be 1) [1] $ cp -R .hg/store-full/. .hg/store Corrupt changelog base node to cause failure to read revision $ printf abcd | dd conv=notrunc of=.hg/store/00changelog.i bs=1 seek=16 \ > 2> /dev/null $ hg verify -q 0: unpacking changeset 08b1860757c2: * (glob) manifest@?: rev 0 points to unexpected changeset 0 manifest@?: d0b6632564d4 not in changesets file@?: rev 0 points to unexpected changeset 0 (expected 1) 1 warnings encountered! 4 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Corrupt manifest log base node to cause failure to read revision $ printf abcd | dd conv=notrunc of=.hg/store/00manifest.i bs=1 seek=16 \ > 2> /dev/null $ hg verify -q manifest@0: reading delta d0b6632564d4: * (glob) file@0: 362fef284ce2 not in manifests 2 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store Corrupt filelog base node to cause failure to read revision $ printf abcd | dd conv=notrunc of=.hg/store/data/file.i bs=1 seek=16 \ > 2> /dev/null $ hg verify -q file@0: unpacking 362fef284ce2: * (glob) 1 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ cp -R .hg/store-full/. .hg/store $ cd .. test changelog without a manifest $ hg init b $ cd b $ hg branch foo marked working directory as branch foo (branches are permanent and global, did you want a bookmark?) $ hg ci -m branchfoo $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 1 changesets with 0 changes to 0 files test revlog corruption $ touch a $ hg add a $ hg ci -m a $ echo 'corrupted' > b $ dd if=.hg/store/data/a.i of=start bs=1 count=20 2>/dev/null $ cat start b > .hg/store/data/a.i $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files a@1: broken revlog! (index data/a.i is corrupted) warning: orphan data file 'data/a.i' checked 2 changesets with 0 changes to 1 files 1 warnings encountered! 1 integrity errors encountered! (first damaged changeset appears to be 1) [1] $ cd .. test revlog format 0 $ revlog-formatv0.py $ cd formatv0 $ hg verify repository uses revlog format 0 checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 1 changesets with 1 changes to 1 files $ cd .. test flag processor and skipflags $ hg init skipflags $ cd skipflags $ cat >> .hg/hgrc <<EOF > [extensions] > flagprocessor=$RUNTESTDIR/flagprocessorext.py > EOF $ echo '[BASE64]content' > base64 $ hg commit -Aqm 'flag processor content' base64 $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 1 changesets with 1 changes to 1 files $ cat >> $TESTTMP/break-base64.py <<EOF > from __future__ import absolute_import > import base64 > base64.b64decode=lambda x: x > EOF $ cat >> .hg/hgrc <<EOF > breakbase64=$TESTTMP/break-base64.py > EOF $ hg verify checking changesets checking manifests crosschecking files in changesets and manifests checking files base64@0: unpacking 794cee7777cb: integrity check failed on data/base64.i:0 checked 1 changesets with 1 changes to 1 files 1 integrity errors encountered! (first damaged changeset appears to be 0) [1] $ hg verify --config verify.skipflags=2147483647 checking changesets checking manifests crosschecking files in changesets and manifests checking files checked 1 changesets with 1 changes to 1 files