Mercurial > hg
view tests/test-mq-qrefresh-replace-log-message.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 | d157b5bfaef0 |
children | c6d31e659a28 |
line wrap: on
line source
Environment setup for MQ $ echo "[extensions]" >> $HGRCPATH $ echo "mq=" >> $HGRCPATH $ cat >> $HGRCPATH <<EOF > [defaults] > # explicit date to commit with fixed hashid > qnew = -d "0 0" > qrefresh = -d "0 0" > qfold = -d "0 0" > EOF $ hg init $ hg qinit Should fail if no patches applied (this tests also that editor is not invoked if '--edit' is not specified) $ hg qrefresh no patches applied [1] $ hg qrefresh -e no patches applied [1] $ hg qnew -m "First commit message" first-patch $ echo aaaa > file $ hg add file $ HGEDITOR=cat hg qrefresh Should display 'First commit message' $ hg log -l1 --template "{desc}\n" First commit message Testing changing message with -m (this tests also that '--edit' can be used with '--message', and that '[committemplate] changeset' definition and commit log specific template keyword 'extramsg' work well) $ cat >> .hg/hgrc <<EOF > [committemplate] > listupfiles = {file_adds % > "HG: added {file}\n" }{file_mods % > "HG: changed {file}\n" }{file_dels % > "HG: removed {file}\n" }{if(files, "", > "HG: no files changed\n")} > > changeset = HG: this is customized commit template > {desc}\n\n > HG: Enter commit message. Lines beginning with 'HG:' are removed. > HG: {extramsg} > HG: -- > HG: user: {author} > HG: branch '{branch}'\n{listupfiles} > EOF $ echo bbbb > file $ HGEDITOR=cat hg qrefresh -m "Second commit message" -e HG: this is customized commit template Second commit message HG: Enter commit message. Lines beginning with 'HG:' are removed. HG: Leave message empty to use default message. HG: -- HG: user: test HG: branch 'default' HG: added file $ cat >> .hg/hgrc <<EOF > # disable customizing for subsequent tests > [committemplate] > changeset = > EOF Should display 'Second commit message' $ hg log -l1 --template "{desc}\n" Second commit message Testing changing message with -l $ echo "Third commit message" > logfile $ echo " This is the 3rd log message" >> logfile $ echo bbbb > file $ hg qrefresh -l logfile Should display 'Third commit message\\\n This is the 3rd log message' $ hg log -l1 --template "{desc}\n" Third commit message This is the 3rd log message Testing changing message with -l- $ hg qnew -m "First commit message" second-patch $ echo aaaa > file2 $ hg add file2 $ echo bbbb > file2 $ (echo "Fifth commit message"; echo " This is the 5th log message") | hg qrefresh -l- Should display 'Fifth commit message\\\n This is the 5th log message' $ hg log -l1 --template "{desc}\n" Fifth commit message This is the 5th log message Test saving last-message.txt: $ cat > $TESTTMP/editor.sh << EOF > echo "==== before editing" > cat \$1 > echo "====" > (echo; echo "test saving last-message.txt") >> \$1 > EOF $ cat > $TESTTMP/commitfailure.py <<EOF > from mercurial import error > def reposetup(ui, repo): > class commitfailure(repo.__class__): > def commit(self, *args, **kwargs): > raise error.Abort(b'emulating unexpected abort') > repo.__class__ = commitfailure > EOF $ cat >> .hg/hgrc <<EOF > [extensions] > # this failure occurs before editor invocation > commitfailure = $TESTTMP/commitfailure.py > EOF $ hg qapplied first-patch second-patch $ hg tip --template "{files}\n" file2 (test that editor is not invoked before transaction starting) $ rm -f .hg/last-message.txt $ HGEDITOR="sh $TESTTMP/editor.sh" hg qrefresh -e qrefresh interrupted while patch was popped! (revert --all, qpush to recover) abort: emulating unexpected abort [255] $ test -f .hg/last-message.txt [1] (reset applied patches and directory status) $ cat >> .hg/hgrc <<EOF > [extensions] > commitfailure = ! > EOF $ hg qapplied first-patch $ hg status -A file2 ? file2 $ rm file2 $ hg qpush -q second-patch now at: second-patch (test that editor is invoked and commit message is saved into "last-message.txt") $ cat >> .hg/hgrc <<EOF > [hooks] > # this failure occurs after editor invocation > pretxncommit.unexpectedabort = false > EOF $ rm -f .hg/last-message.txt $ hg status --rev "second-patch^1" -arm A file2 $ HGEDITOR="sh $TESTTMP/editor.sh" hg qrefresh -e ==== before editing Fifth commit message This is the 5th log message HG: Enter commit message. Lines beginning with 'HG:' are removed. HG: Leave message empty to use default message. HG: -- HG: user: test HG: branch 'default' HG: added file2 ==== note: commit message saved in .hg/last-message.txt transaction abort! rollback completed qrefresh interrupted while patch was popped! (revert --all, qpush to recover) abort: pretxncommit.unexpectedabort hook exited with status 1 [255] $ cat .hg/last-message.txt Fifth commit message This is the 5th log message test saving last-message.txt Test visibility of in-memory dirstate changes outside transaction to external process $ cat > $TESTTMP/checkvisibility.sh <<EOF > echo "====" > hg parents --template "{rev}:{node|short}\n" > hg status -arm > echo "====" > EOF == test visibility to external editor $ hg update -C -q first-patch $ rm -f file2 $ hg qpush -q second-patch --config hooks.pretxncommit.unexpectedabort= now at: second-patch $ echo bbbb >> file2 $ sh "$TESTTMP/checkvisibility.sh" ==== 1:e30108269082 M file2 ==== $ HGEDITOR="sh \"$TESTTMP/checkvisibility.sh\"" hg qrefresh -e ==== 0:25e397dabed2 A file2 ==== note: commit message saved in .hg/last-message.txt transaction abort! rollback completed qrefresh interrupted while patch was popped! (revert --all, qpush to recover) abort: pretxncommit.unexpectedabort hook exited with status 1 [255] (rebuilding at failure of qrefresh bases on rev #0, and it causes dropping status of "file2") $ sh "$TESTTMP/checkvisibility.sh" ==== 0:25e397dabed2 ==== == test visibility to precommit external hook $ hg update -C -q $ rm -f file2 $ hg qpush -q second-patch --config hooks.pretxncommit.unexpectedabort= now at: second-patch $ echo bbbb >> file2 $ cat >> .hg/hgrc <<EOF > [hooks] > precommit.checkvisibility = sh "$TESTTMP/checkvisibility.sh" > EOF $ sh "$TESTTMP/checkvisibility.sh" ==== 1:e30108269082 M file2 ==== $ hg qrefresh ==== 0:25e397dabed2 A file2 ==== transaction abort! rollback completed qrefresh interrupted while patch was popped! (revert --all, qpush to recover) abort: pretxncommit.unexpectedabort hook exited with status 1 [255] $ sh "$TESTTMP/checkvisibility.sh" ==== 0:25e397dabed2 ==== $ cat >> .hg/hgrc <<EOF > [hooks] > precommit.checkvisibility = > EOF == test visibility to pretxncommit external hook $ hg update -C -q $ rm -f file2 $ hg qpush -q second-patch --config hooks.pretxncommit.unexpectedabort= now at: second-patch $ echo bbbb >> file2 $ cat >> .hg/hgrc <<EOF > [hooks] > pretxncommit.checkvisibility = sh "$TESTTMP/checkvisibility.sh" > # make checkvisibility run before unexpectedabort > priority.pretxncommit.checkvisibility = 10 > EOF $ sh "$TESTTMP/checkvisibility.sh" ==== 1:e30108269082 M file2 ==== $ hg qrefresh ==== 0:25e397dabed2 A file2 ==== transaction abort! rollback completed qrefresh interrupted while patch was popped! (revert --all, qpush to recover) abort: pretxncommit.unexpectedabort hook exited with status 1 [255] $ sh "$TESTTMP/checkvisibility.sh" ==== 0:25e397dabed2 ==== $ cat >> .hg/hgrc <<EOF > [hooks] > pretxncommit.checkvisibility = > EOF