Commit Graph

51 Commits

Author SHA1 Message Date
Tony Tung
5e5270d3a7 [ctree] initialize the ManifestEntry in addChild after adding to the list
Summary: When a ManifestEntry is destroyed, we reap the heap-allocated resources it holds.  However, this (erroneously) happens when we create a ManifestEntry and add it to the list of children.  What we really need is a move constructor from C++11.  The workaround is to initialize a blank ManifestEntry, add it to the proper location, and then populate it afterwards.

Test Plan: addChild (in a later diff) no longer tramples over memory it no longer owns.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3772915

Signature: t1:3772915:1472174144:a4baac5cb5f6e01a38042c5c6cd92570c8f8e100
2016-08-26 13:49:17 -07:00
Tony Tung
4244eaa191 [ctree] addChild should return a ManifestEntry *
Summary: This gives us a bit of flexibility when we call this method, as references cannot be reassigned.

Test Plan: compiles

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3772844

Signature: t1:3772844:1472174021:565d7f25a27c2fd78ce14b86b5bc499c74d47976
2016-08-26 13:49:17 -07:00
Tony Tung
13ec463298 [ctree] a newly instantiated ManifestEntry should point to a new Manifest
Test Plan: haven't used this yet, but it makes a whole lot of sense.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3770366

Signature: t1:3770366:1472173969:b83e10e27a63b863a3566d2df7cc861417b8208e
2016-08-26 13:49:17 -07:00
Tony Tung
4b0840f5ea [ctree] add two new methods to Manifest
Summary:
1. `children()`, which returns the number of children the manifest has.
2. `removeChild()`, which removes the entry that the iterator references.

Test Plan: used in later diffs

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3770363

Signature: t1:3770363:1472173823:737043b4613a669b402dcfd7921ac55278c3ece9
2016-08-26 13:49:17 -07:00
Tony Tung
96f89fa049 [ctree] fix findChild
Summary: The strings are not necessarily null-terminated and length needs to be considered.

Test Plan: used in later diff to find a path.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3770358

Signature: t1:3770358:1472173786:9a2f681c90476aafd481c301ff65ac8b199214ec
2016-08-26 13:49:17 -07:00
Tony Tung
79f0ebb34a [ctree] create a new method appendbinfromhex
Summary:
appendbinfromhex appends the binary representation of a 40-byte hex string onto a std::string.  This allows us to reuse a std::string rather than to allocate a new one every time.

Also:

1. converted binfromhex to use this method.
2. updated the docblocks to actually reflect reality.

Test Plan: `make local && cd ~/work/fbsource && PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/:~/work/mercurial/facebook-hg-rpms/lz4revlog/ /opt/local/bin/python2.7 ~/work/mercurial/facebook-hg-rpms/hg-crew/hg --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "master~5::master"`

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3770048

Signature: t1:3770048:1472105520:eac79a42360ebfa258519346b68fc4541c2dbb7c
2016-08-26 13:49:17 -07:00
Tony Tung
a6bc389217 [ctree] free memory when destroying a treemanifest object
Summary: Everyone who holds heap-allocated memory gets destructors!

Test Plan: valgrind and confirmed no memory leaking from ctreemanifest

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3763327

Tasks: 12818084

Signature: t1:3763327:1472105103:8ac9d9694be4bf3b09e19e4381737622c94a2dac
2016-08-26 14:00:37 -07:00
Tony Tung
118cc2f8f0 [ctree] cache the root manifest upon retrieval
Summary: In most cases, this is pretty straightforward.  The only unusual case is `_treemanifest_find`, which does the actual resolution of the root manifest (unlike diff and iter).

Test Plan: make local

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3763324

Signature: t1:3763324:1472173572:3dcda9b318ad818d2f51e8c3472c7770739faafe
2016-08-26 13:49:17 -07:00
Tony Tung
5436c47a0d [ctree] rename node to rootNode
Summary: This more accurately describes its purpose.

Test Plan: simple refactor, so thus just make local

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3763323

Signature: t1:3763323:1472104318:b48246777db0527c7022066438c211f54c88703e
2016-08-26 13:49:17 -07:00
Tony Tung
75c02e78a9 [ctree] initialize all the fields in ManifestEntry constructor
Summary: It makes a destructor possible.

Test Plan: make local

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3763322

Signature: t1:3763322:1472104242:e76ef1943c2082ddecff872c6472de4706505922
2016-08-26 13:49:17 -07:00
Tony Tung
de4ad14a9c [ctree] make path a reference in diff
Summary: It's a fixed reference that we use, so no need for a pointer.

Test Plan: `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/:~/work/mercurial/facebook-hg-rpms/lz4revlog/ /opt/local/bin/python2.7 ~/work/mercurial/facebook-hg-rpms/hg-crew/hg --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "master~5::master"`

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3753463

Signature: t1:3753463:1471905506:802315db9d2aa34363c7b0bccaefcbcda21b1a1e
2016-08-22 15:47:46 -07:00
Tony Tung
aab04b7fcf [ctree] have ManifestIterator::next return the entry directly
Summary: Since we're no longer returning a struct, we no longer need to return the value through a pointer argument.

Test Plan: `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/:~/work/mercurial/facebook-hg-rpms/lz4revlog/ /opt/local/bin/python2.7 ~/work/mercurial/facebook-hg-rpms/hg-crew/hg --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "master~5::master"`

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3752376

Tasks: 12818084

Signature: t1:3752376:1471891162:e7cc159d2077d77d234902e4598b9661f15840c0
2016-08-22 15:47:31 -07:00
Tony Tung
fc7dffd109 [ctree] change the ManifestIterator to return ManifestEntry *
Summary: This allows us to modify the ManifestEntry stored in memory.  This also requires us to remove the const qualifier in a number of places.

Test Plan: `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/:~/work/mercurial/facebook-hg-rpms/lz4revlog/ /opt/local/bin/python2.7 ~/work/mercurial/facebook-hg-rpms/hg-crew/hg --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "master~5::master"`

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3752366

Tasks: 12818084

Signature: t1:3752366:1471891101:1d42a04d85b7e8db34644dc8fbf1bb3481fbb7bc
2016-08-22 15:47:16 -07:00
Tony Tung
a3b14127d3 [ctree] extract treemanifest code to its own file
Test Plan: make local

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3733819

Signature: t1:3733819:1471542946:8b322a7099eceb41826bb9e0edeca52e2daceb4c
2016-08-22 15:45:06 -07:00
Tony Tung
4b9e4ad3ee [ctree] rename treemanifest.cpp to py-treemanifest.cpp
Summary: py-treemanifest.cpp will be mostly just python binding stuff.

Test Plan: make local

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3733832

Signature: t1:3733832:1471542792:d6f1130b5c16487f4d0173cedd91857fd3711c1d
2016-08-22 15:44:50 -07:00
Tony Tung
e953a3cc27 [ctree] get rid of manifestkey
Summary: Directly pass in the path + len and the node.  Note that the path is now a char* + len, because this allows us to use the path in treemanifest_find directly, rather than to construct a new path.

Test Plan: run existing perftest without crash.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3738280

Signature: t1:3738280:1471890923:c13283f1c61dc020ba1918ee9b25c24dfd2fc19b
2016-08-22 15:42:03 -07:00
Tony Tung
8205ab233f [ctree] methods to find and add children
Test Plan: used in later diff.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3732102

Signature: t1:3732102:1471905481:000ff5d976c348bac9f993f9c0b56f4b9c8b84f0
2016-08-22 15:41:52 -07:00
Tony Tung
33f0d41725 [ctree] modularize the code
Summary:
I like many small files.

There is one place where I'm making a functional change (convert.h) to satisfy angry compilers.

Test Plan: make local.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3732584

Signature: t1:3732584:1471542758:d0b7804753ea4fd39a507090338ae3c5104dc7fa
2016-08-22 15:40:56 -07:00
Tony Tung
b05f64d3f0 [ctree] add constructor for ManifestEntry that allocates memory and places its data
Summary: For adding new children to Manifests, we need to be able to create new ManifestEntries.  Since these ManifestEntries will not be backed by datapack data structures, we need ManifestEntries that have its own memory allocation.

Test Plan: used in later diff.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3732101

Signature: t1:3732101:1471541200:17b60af0977109757610168637a276f5dd999f8b
2016-08-22 13:58:42 -07:00
Tony Tung
f22b6105d5 [ctree] remove hack for clang
Summary: D3730823 removes the need for it.

Test Plan: compiles

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mathieubaudet, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3730880

Signature: t1:3730880:1471467917:2b202c5cab1a10fcfe5899670b11bc44740983f7
2016-08-22 13:58:10 -07:00
Tony Tung
efd9e50796 [ctree] remove dead code
Summary: This is not used.

Test Plan: compiles

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3726149

Signature: t1:3726149:1471401105:3c27f091b180dd14493a3e50d4043b10b077142b
2016-08-22 13:57:58 -07:00
Tony Tung
fd38308160 [ctree] add a Manifest pointer to ManifestEntry
Summary:
If a manifest has already been loaded for a ManifestEntry, we should cache that entry and reuse it.  Two reasons:

1) if someone makes a modification to a tree, we need to persist that.
2) better performance.

Missing in this diff: memory cleanup

Test Plan: compiles

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3725842

Signature: t1:3725842:1471401136:cbf4a987c35ea19ca432059cc15e299f0aa5568b
2016-08-22 13:57:41 -07:00
Tony Tung
f1ce770ce5 [ctree] convert ManifestFetcher to standard declaration + definitions layout
Summary: This allows us to use ManifestFetcher inside the ManifestEntry class.

Test Plan: compiles

Reviewers: #fastmanifest, durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3725838
2016-08-22 13:55:43 -07:00
Tony Tung
71837a8c16 [ctree] transact in manifests rather than manifestkeys
Summary: This will allow us to replace portions of manifests with in-memory representations.

Test Plan: existing script doesn't crash.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3725831

Signature: t1:3725831:1471400740:4d9891c01f8567f4ceab76d6bd36e7dc595de4a6
2016-08-22 13:55:19 -07:00
Tony Tung
0727c6d030 [ctree] remove the need for a nextentrystart by returning the end of the entry
Summary: `parseptr` refers to where the parsing is going next.  This simplifies the code and makes ManifestEntry less tied to the original memory allocation.

Test Plan: the existing test i've been running doesn't crash.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3717940

Signature: t1:3717940:1471383988:9b718e137b8ffaf8aad09f78f15791eec57fce6e
2016-08-22 13:42:55 -07:00
Tony Tung
dc8b5e0229 [ctree] parse manifests at load time
Summary: Parse manifests when we construct the Manifest object.  This allows us to do manipulations to the Manifest object and not have to deal with a parallel set of data structures.

Test Plan:
`PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/ valgrind ~/work/mercurial/facebook-hg-rpms/hg-crew/hg  --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "@~2::@"`

note that I'm running this with Valgrind.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3717936

Signature: t1:3717936:1471383856:012634c1e59f1da9fc1e5a918e7f7d99d30d6992
2016-08-22 13:42:40 -07:00
Tony Tung
4245bfb5d8 [ctree] get rid of unused index field
Summary: It's not necessary for the direction we're going in.

Test Plan: compiles

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3717930

Signature: t1:3717930:1471383901:d8bfddb7ea7fb08d26315cbfce7af65d14662bc8
2016-08-22 13:42:27 -07:00
Tony Tung
56a6784b4d [ctree] Manifest objects are now allocated on the heap to permit them to be persisted
Summary:
We need manifest objects to be able to stick around in memory, because now they have overrides and all that other good stuff.

This probably introduces a metric ton of memory leaks, but we'll slowly whittle them down.

Test Plan: same script.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3717304

Signature: t1:3717304:1471385439:9269ab248d233a970c6725dbb4ca3eb661f6a96e
2016-08-22 13:41:27 -07:00
Tony Tung
a89dcaf23f [ctree] remove InMemoryManifest
Summary: All manifests will be in-memory to simplify the design.

Test Plan: `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/ ~/work/mercurial/facebook-hg-rpms/hg-crew/hg  --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "@~2::@"`

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3717296

Signature: t1:3717296:1471383272:0fca293beaf811ef39de87300437b0bf880e1ca7
2016-08-22 13:40:57 -07:00
Tony Tung
25b86ae774 [ctree] use a common idiom for naming structures
Summary: xxx is the C++ class, py_xxx is the python wrapper for it.

Test Plan: make local

Reviewers: #fastmanifest, akushner

Reviewed By: akushner

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3701536

Signature: t1:3701536:1471150787:5f3dfc3a65360233f9ee2ea1757ed4f368f70d62
2016-08-22 13:40:15 -07:00
Tony Tung
ff44d5f816 [ctree] handle construction and destruction in treemanifest object
Summary: py_treemanifest is initialized to 0s.  We initialize the `tm` field by explicitly calling the constructor in `treemanifest_init` and we destroy everything by explicitly calling the destructor in `treemanifest_dealloc`

Test Plan: `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/:~/work/mercurial/facebook-hg-rpms/lz4revlog/ /opt/local/bin/python2.7 ~/work/mercurial/facebook-hg-rpms/hg-crew/hg --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "master~5::master"` in fbsource

Reviewers: #fastmanifest

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3730823
2016-08-22 13:39:35 -07:00
Tony Tung
536f6aaaee [ctree] create a py_treemanifest struct that handles the exclusively-python stuff
Summary: treemanifest will become the C++-only treemanifest object.

Test Plan: `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/ ~/work/mercurial/facebook-hg-rpms/hg-crew/hg  --config extensions.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "@~2::@"`

Reviewers: #fastmanifest, durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3701468
2016-08-22 13:37:53 -07:00
Tony Tung
11823e1845 [ctree] move conversion methods to convert.h
Summary:
yo refactoring.

Depends on D3699264

Test Plan: compiles

Reviewers: #fastmanifest, akushner

Reviewed By: akushner

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3699498

Signature: t1:3699498:1471151476:b08a69fb474413c9fc780eaffba4058aca00dacc
2016-08-18 14:44:26 -07:00
Tony Tung
8894da1d35 [ctree] fix comments for clarity/grammar
Test Plan: meh.

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3718053

Signature: t1:3718053:1471384016:be6ad07218e90e03708eae3c9f8a9bc4b1c67520
2016-08-17 12:42:42 -07:00
Tony Tung
1f25a00b79 [ctree] fix comment style
Summary: Matches javadoc/doxygen style

Test Plan: compiles

Reviewers: #fastmanifest, akushner

Reviewed By: akushner

Subscribers: akushner, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3699264

Signature: t1:3699264:1471152249:d917e1f53426ace7b2e26df2cc72379fa97f93c1
2016-08-17 12:41:54 -07:00
Tony Tung
1083a7147d [ctree] if the flag is unset, return the null character as the flag
Summary: If the flag is not present, then `flag` field is set to NULL.  In that case, the current code will segfault.  Now we will assign `\0` to `*resultflag`.

Test Plan:
run `PYTHONPATH=~/work/mercurial/facebook-hg-rpms/remotefilelog:~/work/mercurial/facebook-hg-rpms/fb-hgext/:~/work/mercurial/facebook-hg-rpms/remotenames/ ~/work/mercurial/facebook-hg-rpms/hg-crew/hg  --config extens
.perftest=~/work/mercurial/facebook-hg-rpms/remotefilelog/tests/perftest.py testtree --kind flat,ctree,fast --test fulliter,diff,find --build "@~2::@"`
 without crashing.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3700352
2016-08-17 12:37:19 -07:00
Tony Tung
d1a61c4d0f [ctree] move the treemf reference up to fileiter
Summary: This is the first step in disentangling the C++ code from the python interface.

Test Plan: `PYTHONPATH=~/remotefilelog/build/lib.linux-x86_64-2.6/ python ~/hg/hg --config extensions.remotefilelog=~/remotefilelog/remotefilelog --config extensions.perftest=~/remotefilelog/tests/perftest.py testtree --kind flat,ctree --test fulliter,diff,find --build "master~5000::master"`

Reviewers: #fastmanifest, durham

Reviewed By: durham

Subscribers: durham, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3700627

Signature: t1:3700627:1471382403:d8dc6dc5c295ec55878ca020b91fc0b30d930ce8
2016-08-17 11:48:01 -07:00
Tony Tung
aa27058507 [ctree] fix build on clang
Summary:
clang has a bug where the fully qualified class name cannot be used to invoke the destructor https://llvm.org/bugs/show_bug.cgi?id=12350

This is one of the suggested workarounds.

Test Plan: compiles on darwin

Reviewers: #fastmanifest, lcharignon

Reviewed By: lcharignon

Subscribers: mathieubaudet, mitrandir

Differential Revision: https://phabricator.intern.facebook.com/D3692812

Signature: t1:3692812:1470852812:09ef7de2a322034a01f5569b574c47fcc6f0c8d7
2016-08-10 13:04:38 -07:00
Durham Goode
f63c7b38a0 ctree: large refactor to introduce Manifest, ManifestFetcher, and InMemoryManifest
This is a large refactor of the original code base. I apologize for it not being
broken up into multiple commits.

This adds the Manifest class (that represents a single Manifest directory
entry), the ManifestFetcher class (which allows fetching children manifests),
and the InMemoryManifest class (that represents an uncommitted Manifest).

The combination of these classes does a few things:
1. It removes most of the references to PythonObj from the primary algorithms.
So in the future we could use this code from other C++ code without relying on
Python.
2. It refactors the manifest access in such a way that we allow manifests to be
stored in either python strings or in memory. This opens the doors to
implementing manifest editting apis.
2016-08-08 12:20:44 -07:00
Durham Goode
c8ca415b0e ctree: add getattr to PythonObj
Summary:
Now that we have a wrapper around python objects, let's add a getattr() function
to easily retrieve attributes off the object.

Test Plan: Ran the perf test

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3674366
2016-08-08 12:16:25 -07:00
Durham Goode
18a54f3d14 ctree: switch all PyObjects to use new wrapper class
Summary:
This patch introduces a PythonObj class which implements the copy-constructor,
destructor, and assignment operator in a way that will manage the ref count
automatically. If we move to C++ 11 we could also implement the move constructor
and move assignment operators to make this even more efficient.

The current implementation allows implicitly converting to and from PyObject*,
which may be questionable design wise, but makes switching to and using this
class much cleaner since we can do things like `PythonObj foo = PyObject_New()`
and `PyObject_DoStuff(myPythonObj)`.

Test Plan: Ran the perf test. It succeeded, and I saw no effect on perf.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3674311
2016-08-08 12:16:25 -07:00
Durham Goode
81e68944ae ctree: use new pyexception type to propagate python exceptions
Summary:
Instead of returning NULL and propagating it up the call stack, let's throw
pyexception (which assumes the python error string has already been set) and the
top of the stack can just return NULL.

Test Plan: Ran my perf test suite

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3673804
2016-08-08 12:16:25 -07:00
Durham Goode
f9a0e52da4 ctree: implement diff
Summary:
This implements treemanifest.diff(). It takes two manifests and iterates over
them to produce a python dictionary containing the differences.

I'm not proud of this.  Just putting it up for review for completeness since it
completes the find, diff, iter trifecta. I need to refactor it to remove some of
the duplication before it gets accepted.

Test Plan:
Ran it as part of a perf test suite using diffs across various
distances.  It takes 250ms to diff across 5000 commits, and 900ms to diff across
50,000 commits.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3646003
2016-08-08 12:16:25 -07:00
Durham Goode
031783c47f ctree: convert manifesttree struct to class
Summary:
By making this a class we can encapsulate common operations like parsing and
directory checking. The later diff that implements treemanifest_diff uses this
a lot.

Test Plan: Ran my perf tests for find and iter (and for the later patch diff).

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3673228
2016-08-08 12:16:25 -07:00
Durham Goode
c43476ae8a ctree: explicitly cast to Py_ssize_t
Summary:
The varargs style Py_BuildValue functions have no idea what type the incoming
arguments are, so it passed the hard coded ints as 32 bit instead of 64bit.
Let's explicitly cast every number being passed to that function as Py_ssize_t
instead.

Test Plan: We were seeing segfaults without this change. Now we don't.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3673217
2016-08-08 12:16:25 -07:00
Durham Goode
bced440ce6 ctree: implement find
Summary:
This implements treemanifest.find(), which takes a filename and returns the node
and flag for it, if it exists.

This isn't the prettiest function I've ever written.  I need to think about how
to refactor this to unify the various traversal algorithms that are used in
treemanifest.

Test Plan:
Ran it as part of a perf test suite. It's basically 0 milliseconds in
every case.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3645967
2016-08-08 12:16:25 -07:00
Durham Goode
d5ae2f2fdf ctree: implement __iter__
Summary:
This implements the basic __iter__ logic. It returns an iterator that returns
every file path in the manifest.

Test Plan:
Ran a separate perf test suite to verify the performance of this. It
can iterate over 1 million files in about 550 milliseconds, assuming a fast
store.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3645890
2016-08-08 12:16:25 -07:00
Durham Goode
f3263cc7ab ctree: define basic fileiter type
Summary:
This defines the basic type for representing an iteration over all the keys in
the treemanifest. The next patch fill add the logic that constructs and mutates
this type as it iterates.

Test Plan: I ran a perf test in a future patch that executes all of this code.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3645768
2016-08-08 12:16:25 -07:00
Durham Goode
28b736554e ctree: add common helper methods
Summary:
This adds getdata and binfromhex functions. These are common functions that will
be used throughout the implementation of the ctreemanifest.

Test Plan: Ran a perf test suit on the code in a later diff.

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3644960
2016-08-08 12:16:25 -07:00
Durham Goode
d55020433d ctree: add an initial c type definition for treemanifest
Summary:
This is the basic definition of the c treemanifest type. Future patches will add
functions to this type.

Test Plan: Tested by running a perf suite on a later version of this series

Reviewers: #fastmanifest

Differential Revision: https://phabricator.intern.facebook.com/D3644935
2016-08-08 12:16:25 -07:00