view tests/test-convert-splicemap.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 58a309e9cf80
children
line wrap: on
line source


  $ echo "[extensions]" >> $HGRCPATH
  $ echo "convert=" >> $HGRCPATH
  $ glog()
  > {
  >     hg log -G --template '{rev}:{node|short} "{desc|firstline}"\
  >  files: {files}\n' "$@"
  > }
  $ hg init repo1
  $ cd repo1
  $ echo a > a
  $ hg ci -Am adda
  adding a
  $ echo b > b
  $ echo a >> a
  $ hg ci -Am addb
  adding b
  $ PARENTID1=`hg id --debug -i`
  $ echo c > c
  $ hg ci -Am addc
  adding c
  $ PARENTID2=`hg id --debug -i`
  $ cd ..
  $ glog -R repo1
  @  2:e55c719b85b6 "addc" files: c
  |
  o  1:6d4c2037ddc2 "addb" files: a b
  |
  o  0:07f494440405 "adda" files: a
  

  $ hg init repo2
  $ cd repo2
  $ echo b > a
  $ echo d > d
  $ hg ci -Am addaandd
  adding a
  adding d
  $ INVALIDID1=afd12345af
  $ INVALIDID2=28173x36ddd1e67bf7098d541130558ef5534a86
  $ CHILDID1=`hg id --debug -i`
  $ echo d >> d
  $ hg ci -Am changed
  $ CHILDID2=`hg id --debug -i`
  $ echo e > e
  $ hg ci -Am adde
  adding e
  $ cd ..
  $ glog -R repo2
  @  2:a39b65753b0a "adde" files: e
  |
  o  1:e4ea00df9189 "changed" files: d
  |
  o  0:527cdedf31fb "addaandd" files: a d
  

test invalid splicemap1

  $ cat > splicemap <<EOF
  > $CHILDID2
  > EOF
  $ hg convert --splicemap splicemap repo2 repo1
  abort: syntax error in splicemap(1): child parent1[,parent2] expected
  [255]

test invalid splicemap2

  $ cat > splicemap <<EOF
  > $CHILDID2 $PARENTID1, $PARENTID2, $PARENTID2
  > EOF
  $ hg convert --splicemap splicemap repo2 repo1
  abort: syntax error in splicemap(1): child parent1[,parent2] expected
  [255]

test invalid splicemap3

  $ cat > splicemap <<EOF
  > $INVALIDID1 $INVALIDID2
  > EOF
  $ hg convert --splicemap splicemap repo2 repo1
  abort: splicemap entry afd12345af is not a valid revision identifier
  [255]

splice repo2 on repo1

  $ cat > splicemap <<EOF
  > $CHILDID1 $PARENTID1
  > $CHILDID2 $PARENTID2,$CHILDID1
  > 
  > EOF
  $ cat splicemap
  527cdedf31fbd5ea708aa14eeecf53d4676f38db 6d4c2037ddc2cb2627ac3a244ecce35283268f8e
  e4ea00df91897da3079a10fab658c1eddba6617b e55c719b85b60e5102fac26110ba626e7cb6b7dc,527cdedf31fbd5ea708aa14eeecf53d4676f38db
  
  $ hg clone repo1 target1
  updating to branch default
  3 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ hg convert --splicemap splicemap repo2 target1
  scanning source...
  sorting...
  converting...
  2 addaandd
  spliced in 6d4c2037ddc2cb2627ac3a244ecce35283268f8e as parents of 527cdedf31fbd5ea708aa14eeecf53d4676f38db
  1 changed
  spliced in e55c719b85b60e5102fac26110ba626e7cb6b7dc and 527cdedf31fbd5ea708aa14eeecf53d4676f38db as parents of e4ea00df91897da3079a10fab658c1eddba6617b
  0 adde
  $ glog -R target1
  o  5:16bc847b02aa "adde" files: e
  |
  o    4:e30e4fee3418 "changed" files: d
  |\
  | o  3:e673348c3a3c "addaandd" files: a d
  | |
  @ |  2:e55c719b85b6 "addc" files: c
  |/
  o  1:6d4c2037ddc2 "addb" files: a b
  |
  o  0:07f494440405 "adda" files: a
  



Test splicemap and conversion order

  $ hg init ordered
  $ cd ordered
  $ echo a > a
  $ hg ci -Am adda
  adding a
  $ hg branch branch
  marked working directory as branch branch
  (branches are permanent and global, did you want a bookmark?)
  $ echo a >> a
  $ hg ci -Am changea
  $ echo a >> a
  $ hg ci -Am changeaagain
  $ hg up 0
  1 files updated, 0 files merged, 0 files removed, 0 files unresolved
  $ echo b > b
  $ hg ci -Am addb
  adding b

We want 2 to depend on 1 and 3. Since 3 is always converted after 2,
the bug should be exhibited with all conversion orders.

  $ cat > ../splicemap <<EOF
  > `(hg id -r 2 -i --debug)` `(hg id -r 1 -i --debug)`, `(hg id -r 3 -i --debug)`
  > EOF
  $ cd ..
  $ cat splicemap
  7c364e7fa7d70ae525610c016317ed717b519d97 717d54d67e6c31fd75ffef2ff3042bdd98418437, 102a90ea7b4a3361e4082ed620918c261189a36a

Test regular conversion

  $ hg convert --splicemap splicemap ordered ordered-hg1
  initializing destination ordered-hg1 repository
  scanning source...
  sorting...
  converting...
  3 adda
  2 changea
  1 addb
  0 changeaagain
  spliced in 717d54d67e6c31fd75ffef2ff3042bdd98418437 and 102a90ea7b4a3361e4082ed620918c261189a36a as parents of 7c364e7fa7d70ae525610c016317ed717b519d97
  $ glog -R ordered-hg1
  o    3:4cb04b9afbf2 "changeaagain" files: a
  |\
  | o  2:102a90ea7b4a "addb" files: b
  | |
  o |  1:717d54d67e6c "changea" files: a
  |/
  o  0:07f494440405 "adda" files: a
  

Test conversion with parent revisions already in dest, using source
and destination identifiers. Test unknown splicemap target.

  $ hg convert -r1 ordered ordered-hg2
  initializing destination ordered-hg2 repository
  scanning source...
  sorting...
  converting...
  1 adda
  0 changea
  $ hg convert -r3 ordered ordered-hg2
  scanning source...
  sorting...
  converting...
  0 addb
  $ cat > splicemap <<EOF
  > `(hg -R ordered id -r 2 -i --debug)` \
  > `(hg -R ordered-hg2 id -r 1 -i --debug)`,\
  > `(hg -R ordered-hg2 id -r 2 -i --debug)`
  > deadbeef102a90ea7b4a3361e4082ed620918c26 deadbeef102a90ea7b4a3361e4082ed620918c27
  > EOF
  $ hg convert --splicemap splicemap ordered ordered-hg2
  scanning source...
  splice map revision deadbeef102a90ea7b4a3361e4082ed620918c26 is not being converted, ignoring
  sorting...
  converting...
  0 changeaagain
  spliced in 717d54d67e6c31fd75ffef2ff3042bdd98418437 and 102a90ea7b4a3361e4082ed620918c261189a36a as parents of 7c364e7fa7d70ae525610c016317ed717b519d97
  $ glog -R ordered-hg2
  o    3:4cb04b9afbf2 "changeaagain" files: a
  |\
  | o  2:102a90ea7b4a "addb" files: b
  | |
  o |  1:717d54d67e6c "changea" files: a
  |/
  o  0:07f494440405 "adda" files: a
  

Test empty conversion

  $ hg convert --splicemap splicemap ordered ordered-hg2
  scanning source...
  splice map revision deadbeef102a90ea7b4a3361e4082ed620918c26 is not being converted, ignoring
  sorting...
  converting...

Test clonebranches

  $ hg --config convert.hg.clonebranches=true convert \
  >   --splicemap splicemap ordered ordered-hg3
  initializing destination ordered-hg3 repository
  scanning source...
  abort: revision 717d54d67e6c31fd75ffef2ff3042bdd98418437 not found in destination repository (lookups with clonebranches=true are not implemented)
  [255]

Test invalid dependency

  $ cat > splicemap <<EOF
  > `(hg -R ordered id -r 2 -i --debug)` \
  > deadbeef102a90ea7b4a3361e4082ed620918c26,\
  > `(hg -R ordered-hg2 id -r 2 -i --debug)`
  > EOF
  $ hg convert --splicemap splicemap ordered ordered-hg4
  initializing destination ordered-hg4 repository
  scanning source...
  abort: unknown splice map parent: deadbeef102a90ea7b4a3361e4082ed620918c26
  [255]