Commit Graph

61 Commits

Author SHA1 Message Date
Durham Goode
2b272f7bbc revisionstore: use ok_or_else instead of ok_or
Summary:
When reading entries, we were using ok_or to read a slice and catch
errors, but this causes an unnecessary allocation for the error even if we don't
have an error. Let's use ok_or_else to avoid that.

Reviewed By: quark-zju

Differential Revision: D8897109

fbshipit-source-id: d308f64d54a58077d9ec2eb34dd1bef431ac1819
2018-07-26 12:17:20 -07:00
Durham Goode
6dc36e06d2 datapack: implement Repackable
Summary: Implements the Repackable interface.

Reviewed By: quark-zju

Differential Revision: D8895276

fbshipit-source-id: ba0c83894db283c5c1dddf68ec8fdbe64a17a801
2018-07-26 12:17:19 -07:00
Durham Goode
dfc30ad8e6 revisionstore: add Repackable trait
Summary:
Adds a trait that represents a store that is repackable. An implementor
only needs to be iterable, and expose some basic type and identifier information
and the trait provides the actual repack logic.

Reviewed By: quark-zju

Differential Revision: D8894756

fbshipit-source-id: 13053f8c7b6dca8b80ea819ef18949f3862cf367
2018-07-26 12:17:19 -07:00
Durham Goode
c18a1d04f1 revisionstore: implement iter for DataStore trait
Summary:
We need the ability to iterate over a datastore so we can implement
repack and cleanup. In a later diff we'll use this trait to implement repack
functionality in a way that it can apply to any store that implements
IterableStore.

Reviewed By: quark-zju

Differential Revision: D8885094

fbshipit-source-id: 0a2b1ab8cf524392d890302c33e386f1cd218d24
2018-07-26 12:17:19 -07:00
Durham Goode
e1b153825b revisionstore: store paths on DataPack object
Summary:
The paths for each data pack are used in various situations (repack,
error reporting, etc) so let's store them and make them accessible via the
python api.

Reviewed By: quark-zju

Differential Revision: D8884773

fbshipit-source-id: 4108c98b4e303ba9bded1f264746fa4a84845c73
2018-07-26 12:17:17 -07:00
Jeremy Fitzhardinge
03640e680e tp2: update rust-crates-io
Summary:
Fix crate names for where the crate name doesn't match the package
name. This affected a few crates, but in practice only rust-crypto/crypto was
used.

Reviewed By: Imxset21

Differential Revision: D9002131

fbshipit-source-id: d9591e4b6da9a00029054785b319a6584958f043
2018-07-25 15:50:52 -07:00
Durham Goode
e64f1c7c7f datapack: return KeyError for missing key
Summary:
If the DataIndex didn't have a key, we were returning a DataIndexError
when we should've been returning a KeyError. This tells the higher level stores
to continue to the next store instead of raising the exception further.

Reviewed By: quark-zju

Differential Revision: D8806186

fbshipit-source-id: c40da96101494d5e3ea7910bf4b1a89674463a77
2018-07-25 11:07:33 -07:00
Durham Goode
1f93a51285 datapack: change version to be an enum
Summary:
The version only has a few valid values, so let's change it to be an
enum. This will be used in an upcoming diff to make the python tests pass.

Reviewed By: quark-zju

Differential Revision: D8775752

fbshipit-source-id: b1101c123b4802fbcb0f0a6fe5a45d741aec764f
2018-07-25 11:07:32 -07:00
Durham Goode
1f260293cc datapack: fix indicator for end of chain vs missing delta
Summary:
In the python code, end of a delta chain is marked with one value while
a missing delta is marked with another value. This isn't actually used anywhere,
but let's make the rust code mimic this for now.

Reviewed By: quark-zju

Differential Revision: D8775039

fbshipit-source-id: c9f81471bfd67e720938d6c5bbd10db029406686
2018-07-25 11:07:32 -07:00
Durham Goode
c1baef6ce3 dataindex: hide IndexEntry fields behind methods
Summary:
In a future diff we'll be changing the storage of IndexEntry to be
different from the API. So let's hide the actual format behind functions.

Reviewed By: quark-zju

Differential Revision: D8923005

fbshipit-source-id: 2f87b35315f8a7a5a8e67b6d0be2c73a1d9bccb4
2018-07-25 11:07:32 -07:00
Durham Goode
82a6a73b98 datastore: add get_delta function to DataStore trait
Summary:
This function is present on the python data store api, so let's
replicate it here. Later we should come back and refactor this to be a special
case of the get_delta_chain result, but for now we'll maintain the custom API so
we can start using this code from python.

Reviewed By: quark-zju

Differential Revision: D8774474

fbshipit-source-id: aabcff3a43ae68859a1bf3b23f433214571b1a9d
2018-07-25 11:07:32 -07:00
Durham Goode
047bf26495 buck: add buck target files
Summary: This will let us build with buck.

Reviewed By: quark-zju

Differential Revision: D8980839

fbshipit-source-id: ea64328d32bc2c88984d0c861acefcc55b84ce02
2018-07-24 16:05:26 -07:00
Durham Goode
6c71f5a3c0 revisionstore: fix unused code warnings
Summary:
There were a bunch of unused code warnings because the mutabledatapack
module wasn't exposed as public. This then lead to us ignoring other warnings.
Let's fix all of them.

Reviewed By: quark-zju

Differential Revision: D8895468

fbshipit-source-id: 914c81026469382fcf28015b4a6bce13bad746c2
2018-07-18 10:08:49 -07:00
Durham Goode
fb0e3537bf dataindex: fix dataindex to store index_start relative locations
Summary:
Previously the rust dataindex would store the delta base location as an
offset relative to the start of the file. The python implementation stores it
relative to the start of the index though. So let's update the rust
implementation.

Reviewed By: quark-zju

Differential Revision: D8774206

fbshipit-source-id: d4317a95df353a7b635f1827fcfad7f3fb171afd
2018-07-17 15:10:01 -07:00
Durham Goode
a169a98521 loosefile: fix compilation errors in tests
Summary:
The Node::random() function changed while this was landing. So we need
to update the tests.

Reviewed By: quark-zju

Differential Revision: D8774074

fbshipit-source-id: 6f3bcdeac069ef5ffdb2deb1970a1655cabcedaf
2018-07-09 15:20:50 -07:00
Qingpeng Niu
7e0204ff39 loosefile class to read Mercurial loose file format data.
Summary: Create a simple rust reader for our loose file format.  One of Mercurial’s simplest file formats is the loose file format.  fbsource/fbcode/scm/hg/hgext/remotefilelog/remotefilelog.py:_createfileblob() is the python writing implementation.

Reviewed By: DurhamG

Differential Revision: D8731050

fbshipit-source-id: 80eb2abde2a2e5bb672d7e8ffa8ba58ed62184c1
2018-07-06 12:51:08 -07:00
Durham Goode
20c35ecbf3 revisionstore: use fixed random generator for tests
Summary:
Instead of using random nodes, let's use ones based off a seeded
generator.

Reviewed By: quark-zju

Differential Revision: D8741139

fbshipit-source-id: a90e6f092adac6aef35149ee6c4bf2b47c469602
2018-07-06 11:11:40 -07:00
Durham Goode
0e34d12531 mutabledatapack: implement get_delta_chain
Summary: Implements the get_delta_chain function of the DataStore trait.

Reviewed By: quark-zju

Differential Revision: D8598658

fbshipit-source-id: 708bca63e2da3aae6064ed18076a9a1f1282a756
2018-07-06 11:11:40 -07:00
Durham Goode
32ce9b99ab revisionstore: change delta base to be an Option<>
Summary:
Deltas may not have bases if they are a full text. Let's represent
that as an Option instead of as a magical null id value. This has the nice
effect of moving the decision to serialize a missing delta base down into the
serializer instead of up at the delta chain construction level.

Reviewed By: quark-zju

Differential Revision: D8739231

fbshipit-source-id: b58bd40dae45cb85890812db21e7eeff46aa6b4e
2018-07-06 11:11:40 -07:00
Jun Wu
d0c1b6d014 cargo: add a workspace
Summary:
Make `lib` a cargo workspace so building in subprojects would share a
`target` directory and `cargo doc` will build documentation for all
subprojects.

Reviewed By: DurhamG

Differential Revision: D8741175

fbshipit-source-id: 512325bcb23d51e866e764bdc76dddb22c59ef05
2018-07-05 16:06:35 -07:00
Durham Goode
a1b6fa3007 mutabledatapack: implement get_meta
Summary:
Implements the get_meta function of the DataStore trait. This caught a
bug in how we record lengths as well.

Reviewed By: quark-zju

Differential Revision: D8598661

fbshipit-source-id: 566dca1770d6666e4215fa1fd8f33babdede2f90
2018-07-05 14:53:19 -07:00
Durham Goode
b728154963 mutabledatapack: change error to contain String
Summary:
We want to be able to format error strings, so we can't return a static
str anymore.

Reviewed By: quark-zju

Differential Revision: D8598659

fbshipit-source-id: 44d7a73c06416efca51ca4d0f24a0c8911af8582
2018-07-05 14:53:19 -07:00
Durham Goode
587fc95964 mutabledatapack: begin implementing DataStore trait
Summary:
A mutabledatapack also needs to be readable as a normal store. Let's
start implementing the DataStore trait, starting with get_missing

Reviewed By: quark-zju

Differential Revision: D8598657

fbshipit-source-id: 1f8bc89fae2be73fe789bc0ef1cdd922222019a2
2018-07-05 14:53:18 -07:00
Durham Goode
875758fdbe datapack: implement getdeltachain
Summary: Implements the last of the DataStore api, getdeltachain.

Reviewed By: quark-zju

Differential Revision: D8557950

fbshipit-source-id: 7f6530fe2064f0d035414b7920a126c6aab41beb
2018-07-05 14:53:18 -07:00
Durham Goode
24a4751ff0 revisionstore: change Delta.data to Rc
Summary:
In a future diff we'll be returning data read from a pack file out as a
Delta. To avoid copies, we need to be able to return an Rc from DataPack. This
seems like it will be a common pattern, so let's go ahead and make Delta contain
its data as an Rc.

Reviewed By: quark-zju

Differential Revision: D8557949

fbshipit-source-id: 276005360bfa48e9154143dedce579a21129e976
2018-07-05 14:53:18 -07:00
Durham Goode
c6af00dbc9 datapack: implement getmetadata
Summary:
Introduces the DataEntry structure which is able to parse data entries
from pack files. Uses it to implement getmetadata

Reviewed By: quark-zju

Differential Revision: D8556610

fbshipit-source-id: c25427c3c247970a879ad7d409b821f3695b97d9
2018-07-05 14:53:17 -07:00
Durham Goode
79a9dd976f datapack: implement getmissing
Summary: Adds the DataStore trait and implements the getmissing function.

Reviewed By: quark-zju

Differential Revision: D8554391

fbshipit-source-id: 41c107c07de7d6945ca7370e264c6bc0bf154754
2018-07-05 14:53:17 -07:00
Durham Goode
ebc31e8daf datapack: add initial datapack structure
Summary:
This adds the initial struct and opener for a datapack. Future diffs
will add actual functionality and tests.

Reviewed By: quark-zju

Differential Revision: D8553436

fbshipit-source-id: 3b17f995632e859019205f242a4cce389ac77407
2018-07-05 14:53:17 -07:00
Durham Goode
029666cf27 mutabledatapack: write index to disk during serialization
Summary:
Actually write the index to disk when the mutabledatapack is
serializing.

Reviewed By: quark-zju

Differential Revision: D8552276

fbshipit-source-id: 354c7fdc3fe84b91d582f0e8cde8c6ae2494c559
2018-07-05 14:53:17 -07:00
Durham Goode
e68c0ec7e0 mutabledatapack: add logic for reading DataIndex
Summary: This adds the logic for reading a DataIndex from disk.

Reviewed By: quark-zju

Differential Revision: D8552278

fbshipit-source-id: 611ff09c27716b8d8ff7424c1a27287b9fc42b78
2018-07-05 14:53:16 -07:00
Durham Goode
d22f6ce58d mutabledatapack: add logic for writing DataIndex
Summary:
Soon we will be writing the index during pack file serialization, so
let's add the logic for serializing the index.

Reviewed By: quark-zju

Differential Revision: D8552277

fbshipit-source-id: 60829631eb060f62d266c16f6016f34080311f8e
2018-07-05 14:53:16 -07:00
Durham Goode
69a59f53d9 revisionstore: add Node::from_slice
Summary: A simple helper method for producing Node's from slices in a safe way.

Reviewed By: quark-zju

Differential Revision: D8547679

fbshipit-source-id: 85ae8fcd7749c662b1459af1d84ccf9695dd5f0b
2018-07-05 14:53:16 -07:00
Durham Goode
1c3767bc11 mutabledatapack: implement data index header serialization
Summary:
We're beginning to implement the DataPack index file logic. Let's start
with header serialization/deserialization.

Reviewed By: quark-zju

Differential Revision: D8319727

fbshipit-source-id: 079aab06ececb1c5159aec2da3243268eea0cb61
2018-07-05 14:53:15 -07:00
Durham Goode
12e0e5bf16 mutabledatapack: build inmemory index as revisions are added
Summary:
Let's build an inmemory hash table of the revisions that were added. A
future diff will serialize this index into a dataidx file.

Reviewed By: quark-zju

Differential Revision: D8309730

fbshipit-source-id: 9efc7f0f34129a63c52309b4d70179f2c10840b3
2018-07-05 14:53:15 -07:00
Durham Goode
763d1e4bef datapack: implement a fanout table
Summary:
Implements a fanout table trait that history pack and data pack will
use. It basically consists of logic to build and read a quick lookup table that
uses the first few bytes of a key to determine the bounding range of a binary
search.

Reviewed By: quark-zju

Differential Revision: D8309729

fbshipit-source-id: 71e398277dc8ae041447035f044e5d47ca41cf7e
2018-07-05 14:53:15 -07:00
Durham Goode
4588cc18c8 mutabledatapack: write version number header
Summary:
The mutabledatapack format has a one byte header containing the version
number.

Reviewed By: quark-zju

Differential Revision: D8305653

fbshipit-source-id: c4a96dc48e64acd2c5849034e5d90b87363fbc8d
2018-07-05 14:53:15 -07:00
Durham Goode
99a11bbb24 mutabledatapack: use hash of contents as name
Summary:
Implements the logic that builds a hash of the contents of the pack
file and uses it as the name.

Reviewed By: quark-zju

Differential Revision: D8305654

fbshipit-source-id: d1270e7519a7718aa5427f3be5cdc0cd0dee2fe2
2018-07-05 14:53:14 -07:00
Durham Goode
3f467bd21f mutabledatapack: implement add()
Summary:
This is the start of a rust mutable datapack implementation. The first
diff adds a simple add function. Later diffs will add the logic that builds the
index, serializes the index, and computes the final hash name.

Reviewed By: quark-zju

Differential Revision: D8304036

fbshipit-source-id: db05c2b845e51a3552c039b7fc0b8f4cc0ff0852
2018-07-05 14:53:14 -07:00
Durham Goode
8057817dc1 revisionstore: add read/write functions to Metadata
Summary:
In a future diff we'll be serializing and deserializing metadata in
datapacks. Let's add the reader and writer functions for Metadata and some unit
tests.

Reviewed By: quark-zju

Differential Revision: D8303603

fbshipit-source-id: 7e7a7aa218c05179b205abf8b151b1488be674b3
2018-07-05 14:53:14 -07:00
Saurabh Singh
fa3c7b34a3 add basic tests for unionhistorystore
Summary:
This commit adds very basic tests for the Union History Store. These
tests just test for expected output of operations on bad/empty stores.

Reviewed By: quark-zju

Differential Revision: D8553821

fbshipit-source-id: a0dfa47f10083c37901535e8a810a99693a28c82
2018-06-27 19:05:31 -07:00
Saurabh Singh
40e70758b7 introduce union history store
Summary: This commit just introduces the Union History Store.

Reviewed By: DurhamG

Differential Revision: D8553822

fbshipit-source-id: 6c7ee0b5d33dae6d51b4179616d206f42eb0cd50
2018-06-27 19:05:31 -07:00
Saurabh Singh
0326fe4584 introduce history store
Summary: This commit just introduces the history store.

Reviewed By: DurhamG

Differential Revision: D8553823

fbshipit-source-id: 93af6059296d11c4fcc0dd306b4472c4f2168fa7
2018-06-27 19:05:31 -07:00
Saurabh Singh
164bf3e85a fix error messaging
Summary: This commit just fixes the messaging for the errors.

Reviewed By: DurhamG

Differential Revision: D8553820

fbshipit-source-id: 73f2cd13e7538b6870b16a0e47e657a6d08af9e3
2018-06-26 11:36:09 -07:00
Saurabh Singh
7c9227818a refactor rust datastore to a consistent naming scene
Summary: This is just a refactor to address the naming scheme.

Reviewed By: quark-zju

Differential Revision: D8269217

fbshipit-source-id: 8c52d2c67837550e0b7dc1a45b3faf9a80319b61
2018-06-04 17:39:47 -07:00
Saurabh Singh
7067e4ca1f fix nit in implementation
Summary:
Based on review for D8214151 by quark-zju, addressing the nit here as
well.

Reviewed By: quark-zju

Differential Revision: D8267140

fbshipit-source-id: 12c3355852a49859c2b0a243fa8666105c914c73
2018-06-04 16:21:38 -07:00
Saurabh Singh
8ba5a79489 adding tests for bad data store
Summary:
Adding the tests for the case when the union store has only one data
store which always returns an `Err` as `Result`. This `Err` is not of the type
`KeyError` which the union store handles differently.

Reviewed By: quark-zju

Differential Revision: D8214156

fbshipit-source-id: bd077af343086c92f46ec6a6f1551d05dd9bda09
2018-06-04 16:21:38 -07:00
Saurabh Singh
242f2b904f add tests for empty data store
Summary:
Adding tests for the case when the union store only has a single data
store which is completely empty.

Reviewed By: quark-zju

Differential Revision: D8214151

fbshipit-source-id: 9d8f329548a1b7e105a5dc6219067a6e292fe97c
2018-06-04 16:21:37 -07:00
Saurabh Singh
34ca90a6f8 rename test methods to be more specific
Summary:
This commit just renames the methods to be more specific. This is
useful for later changes.

Reviewed By: quark-zju

Differential Revision: D8214153

fbshipit-source-id: e8db9148334f7cd539aca626e3798e256b9b022f
2018-06-04 16:21:37 -07:00
Saurabh Singh
a4f5e8aefc add tests for empty union date store
Summary:
These tests just test the expected outcome when the union data store
is empty.

Reviewed By: quark-zju

Differential Revision: D8018975

fbshipit-source-id: a2cc4c87509b857dbf5f6af506f165ea62080db8
2018-05-15 18:37:47 -07:00
Saurabh Singh
cab75fbb90 add common traits for Key
Summary:
This commit derives the common traits for the Key type just as we did
for the Node type in D7872300.

Reviewed By: quark-zju

Differential Revision: D8018973

fbshipit-source-id: 566a69be16d74529c6eb5f157b84de25835f780f
2018-05-15 18:37:47 -07:00