sapling/eden/fs/inodes/overlay.thrift

44 lines
1.3 KiB
Thrift
Raw Normal View History

Reimplement dirstate used by Eden's Hg extension as a subclass of Hg's dirstate. Summary: This is a major change to Eden's Hg extension. Our initial attempt to implement `edendirstate` was to create a "clean room" implementation that did not share code with `mercurial/dirstate.py`. This was helpful in uncovering the subset of the dirstate API that matters for Eden. It also provided a better safeguard against upstream changes to `dirstate.py` in Mercurial itself. In this implementation, the state transition management was mostly done on the server in `Dirstate.cpp`. We also made a modest attempt to make `Dirstate.cpp` "SCM-agnostic" such that the same APIs could be used for Git at some point. However, as we have tried to support more of the sophisticated functionality in Mercurial, particularly `hg histedit`, achieving parity between the clean room implementation and Mercurial's internals has become more challenging. Ultimately, the clean room implementation is likely the right way to go for Eden, but for now, we need to prioritize having feature parity with vanilla Hg when using Eden. Once we have a more complete set of integration tests in place, we can reimplement Eden's dirstate more aggressively to optimize things. Fortunately, the [[ https://bitbucket.org/facebook/hg-experimental/src/default/sqldirstate/ | sqldirstate ]] extension has already demonstrated that it is possible to provide a faithful dirstate implementation that subclasses the original `dirstate` while using a different storage mechanism. As such, I used `sqldirstate` as a model when implementing the new `eden_dirstate` (distinguishing it from our v1 implementation, `edendirstate`). In particular, `sqldirstate` uses SQL tables as storage for the following private fields of `dirstate`: `_map`, `_dirs`, `_copymap`, `_filefoldmap`, `_dirfoldmap`. Because `_filefoldmap` and `_dirfoldmap` exist to deal with case-insensitivity issues, we do not support them in `eden_dirstate` and add code to ensure the codepaths that would access them in `dirstate` never get exercised. Similarly, we also implemented `eden_dirstate` so that it never accesses `_dirs`. (`_dirs` is a multiset of all directories in the dirstate, which is an O(repo) data structure, so we do not want to maintain it in Eden. It appears to be primarily used for checking whether a path to a file already exists in the dirstate as a directory. We can protect against that in more efficient ways.) That leaves only `_map` and `_copymap` to worry about. `_copymap` contains the set of files that have been marked "copied" in the current dirstate, so it is fairly small and can be stored on disk or in memory with little concern. `_map` is a bit trickier because it is expected to have an entry for every file in the dirstate. In `sqldirstate`, it is stored across two tables: `files` and `nonnormalfiles`. For Eden, we already represent the data analogous to the `files` table in RocksDB/the overlay, so we do not need to create a new equivalent to the `files` table. We do, however, need an equivalent to the `nonnormalfiles` table, which we store in as Thrift-serialized data in an ordinary file along with the `_copymap` data. In our Hg extension, our implementation of `_map` is `eden_dirstate_map`, which is defined in a Python file of the same name. Our implementation of `_copymap` is `dummy_copymap`, which is defined in `eden_dirstate.py`. Both of these collections are simple pass-through data structures that translate their method calls to Thrift server calls. I expect we will want to optimize this in the future via some client-side caching, as well as creating batch APIs for talking to the server via Thrift. One advantage of this new implementation is that it enables us to delete `eden/hg/eden/overrides.py`, which overrode the entry points for `hg add` and `hg remove`. Between the recent implementation of `dirstate.walk()` for Eden and this switch to the real dirstate, we can now use the default implementation of `hg add` and `hg remove` (although we have to play some tricks, like in the implementation of `eden_dirstate.status()` in order to make `hg remove` work). In the course of doing this revision, I discovered that I had to make a minor fix to `EdenMatchInfo.make_glob_list()` because `hg add foo` was being treated as `hg add foo/**/*` even when `foo` was just a file (as opposed to a directory), in which case the glob was not matching `foo`! I also had to do some work in `eden_dirstate.status()` in which the `match` argument was previously largely ignored. It turns out that `dirstate.py` uses `status()` for a number of things with the `match` specified as a filter, so the output of `status()` must be filtered by `match` accordingly. Ultimately, this seems like work that would be better done on the server, but for simplicity, we're just going to do it in Python, for now. For the reasons explained above, this revision deletes a lot of code `Dirstate.cpp`. As such, `DirstateTest.cpp` does not seem worth refactoring, though the scenarios it was testing should probably be converted to integration tests. At a high level, the role of `DirstatePersistence` has not changed, but the exact data it writes is much different. Its corresponding unit test is also disabled, for now. Note that this revision does not change the name of the file where "dirstate data" is written (this is defined as `kDirstateFile` in `ClientConfig.cpp`), so we should blow away any existing instances of this file once this change lands. (It is still early enough in the project that it does not seem worth the overhead of a proper migration.) The true test of the success of this new approach is the ease with which we can write more integration tests for things like `hg histedit` and `hg graft`. Ideally, these should require very few changes to `eden_dirstate.py`. Reviewed By: simpkins Differential Revision: D5071778 fbshipit-source-id: e8fec4d393035d80f36516ac050cad025dc3ba31
2017-05-26 21:51:30 +03:00
include "eden/fs/inodes/hgdirstate.thrift"
namespace cpp2 facebook.eden.overlay
namespace py facebook.eden.overlay
typedef binary Hash
typedef string PathComponent
typedef string RelativePath
struct OverlayEntry {
// Holds the mode_t data, which encodes the file type and permissions
1: i32 mode
// The inodeNumber of the child, if it is materialized.
// If the child is not materialized this will be 0, and the hash will
// contain the hash of a source control Tree or Blob.
2: i64 inodeNumber
// If inodeNumber is 0, then this child is identical to an existing
// source control Tree or Blob. This contains the hash of that Tree or Blob.
3: Hash hash
}
struct OverlayDir {
// The contents of this dir.
1: map<PathComponent, OverlayEntry> entries
}
struct OverlayData {
// A map of RelativePath -> OverlayDir for the entire contents of the
// overlay area. The assumption is that the locally materialized data
// (since it should be O(things-changed-in-1-diff) should reasonably
// fit in memory and thus that this won't be too big to work with.
1: map<RelativePath, OverlayDir> localDirs
}
Flip Dirstate -> EdenMount dependency. Summary: Previously, `Dirstate` took a `std::shared_ptr<EdenMount>`, but now it takes pointers to a `MountPoint` and an `ObjectStore` because it does not need the entire `EdenMount`. Ultimately, this will enable us to have `EdenMount` create the `Dirstate` itself, but that will be done in a follow-up commit. Fortunately, it was pretty easy to remove the references to `edenMount_` in `Dirstate.cpp` and rewrite them in terms of `mountPoint_` or `objectStore_`. The one thing that I also decided to move was `getModifiedDirectoriesForMount()` because I already needed to create an `EdenMounts` file (admittedly not a great name) to collect some utility functions that use members of an `EdenMount` while not having access to the `EdenMount` itself. As part of this change, all of the code in `eden/fs/model/hg` has been moved to `eden/fs/inodes` so that it is alongside `EdenMount`. We are going to change the `Dirstate` from an Hg-specific concept to a more general concept. `LocalDirstatePersistence` is no longer one of two implementations of `DirstatePersistence`. (The other was `FakeDirstatePersistence`.) Now there is just one concrete implementation called `DirstatePersistence` that takes its implementation from `LocalDirstatePersistence`. Because there is no longer a `FakeDirstatePersistence`, `TestMount` must create a `DirstatePersistence` that uses a `TemporaryFile`. Because `TestMount` now takes responsibility for creating the `Dirstate`, it must also give callers the ability to specify the user directives. To that end, `TestMountBuilder` got an `addUserDirectives()` method while `TestMount` got a `getDirstate()` method. Surprisingly, `TestMountTest` did not need to be updated as part of this revision, but `DirstateTest` needed quite a few updates (which were generally mechanical). Reviewed By: simpkins Differential Revision: D4230154 fbshipit-source-id: 9b8cb52b45ef5d75bc8f5e62a58fcd1cddc32bfa
2016-11-26 23:00:15 +03:00
enum UserStatusDirective {
Add = 0x0,
Remove = 0x1,
}
struct DirstateData {
Reimplement dirstate used by Eden's Hg extension as a subclass of Hg's dirstate. Summary: This is a major change to Eden's Hg extension. Our initial attempt to implement `edendirstate` was to create a "clean room" implementation that did not share code with `mercurial/dirstate.py`. This was helpful in uncovering the subset of the dirstate API that matters for Eden. It also provided a better safeguard against upstream changes to `dirstate.py` in Mercurial itself. In this implementation, the state transition management was mostly done on the server in `Dirstate.cpp`. We also made a modest attempt to make `Dirstate.cpp` "SCM-agnostic" such that the same APIs could be used for Git at some point. However, as we have tried to support more of the sophisticated functionality in Mercurial, particularly `hg histedit`, achieving parity between the clean room implementation and Mercurial's internals has become more challenging. Ultimately, the clean room implementation is likely the right way to go for Eden, but for now, we need to prioritize having feature parity with vanilla Hg when using Eden. Once we have a more complete set of integration tests in place, we can reimplement Eden's dirstate more aggressively to optimize things. Fortunately, the [[ https://bitbucket.org/facebook/hg-experimental/src/default/sqldirstate/ | sqldirstate ]] extension has already demonstrated that it is possible to provide a faithful dirstate implementation that subclasses the original `dirstate` while using a different storage mechanism. As such, I used `sqldirstate` as a model when implementing the new `eden_dirstate` (distinguishing it from our v1 implementation, `edendirstate`). In particular, `sqldirstate` uses SQL tables as storage for the following private fields of `dirstate`: `_map`, `_dirs`, `_copymap`, `_filefoldmap`, `_dirfoldmap`. Because `_filefoldmap` and `_dirfoldmap` exist to deal with case-insensitivity issues, we do not support them in `eden_dirstate` and add code to ensure the codepaths that would access them in `dirstate` never get exercised. Similarly, we also implemented `eden_dirstate` so that it never accesses `_dirs`. (`_dirs` is a multiset of all directories in the dirstate, which is an O(repo) data structure, so we do not want to maintain it in Eden. It appears to be primarily used for checking whether a path to a file already exists in the dirstate as a directory. We can protect against that in more efficient ways.) That leaves only `_map` and `_copymap` to worry about. `_copymap` contains the set of files that have been marked "copied" in the current dirstate, so it is fairly small and can be stored on disk or in memory with little concern. `_map` is a bit trickier because it is expected to have an entry for every file in the dirstate. In `sqldirstate`, it is stored across two tables: `files` and `nonnormalfiles`. For Eden, we already represent the data analogous to the `files` table in RocksDB/the overlay, so we do not need to create a new equivalent to the `files` table. We do, however, need an equivalent to the `nonnormalfiles` table, which we store in as Thrift-serialized data in an ordinary file along with the `_copymap` data. In our Hg extension, our implementation of `_map` is `eden_dirstate_map`, which is defined in a Python file of the same name. Our implementation of `_copymap` is `dummy_copymap`, which is defined in `eden_dirstate.py`. Both of these collections are simple pass-through data structures that translate their method calls to Thrift server calls. I expect we will want to optimize this in the future via some client-side caching, as well as creating batch APIs for talking to the server via Thrift. One advantage of this new implementation is that it enables us to delete `eden/hg/eden/overrides.py`, which overrode the entry points for `hg add` and `hg remove`. Between the recent implementation of `dirstate.walk()` for Eden and this switch to the real dirstate, we can now use the default implementation of `hg add` and `hg remove` (although we have to play some tricks, like in the implementation of `eden_dirstate.status()` in order to make `hg remove` work). In the course of doing this revision, I discovered that I had to make a minor fix to `EdenMatchInfo.make_glob_list()` because `hg add foo` was being treated as `hg add foo/**/*` even when `foo` was just a file (as opposed to a directory), in which case the glob was not matching `foo`! I also had to do some work in `eden_dirstate.status()` in which the `match` argument was previously largely ignored. It turns out that `dirstate.py` uses `status()` for a number of things with the `match` specified as a filter, so the output of `status()` must be filtered by `match` accordingly. Ultimately, this seems like work that would be better done on the server, but for simplicity, we're just going to do it in Python, for now. For the reasons explained above, this revision deletes a lot of code `Dirstate.cpp`. As such, `DirstateTest.cpp` does not seem worth refactoring, though the scenarios it was testing should probably be converted to integration tests. At a high level, the role of `DirstatePersistence` has not changed, but the exact data it writes is much different. Its corresponding unit test is also disabled, for now. Note that this revision does not change the name of the file where "dirstate data" is written (this is defined as `kDirstateFile` in `ClientConfig.cpp`), so we should blow away any existing instances of this file once this change lands. (It is still early enough in the project that it does not seem worth the overhead of a proper migration.) The true test of the success of this new approach is the ease with which we can write more integration tests for things like `hg histedit` and `hg graft`. Ideally, these should require very few changes to `eden_dirstate.py`. Reviewed By: simpkins Differential Revision: D5071778 fbshipit-source-id: e8fec4d393035d80f36516ac050cad025dc3ba31
2017-05-26 21:51:30 +03:00
1: map<RelativePath, hgdirstate.DirstateTuple> hgDirstateTuples
2: map<RelativePath, RelativePath> hgDestToSourceCopyMap
Flip Dirstate -> EdenMount dependency. Summary: Previously, `Dirstate` took a `std::shared_ptr<EdenMount>`, but now it takes pointers to a `MountPoint` and an `ObjectStore` because it does not need the entire `EdenMount`. Ultimately, this will enable us to have `EdenMount` create the `Dirstate` itself, but that will be done in a follow-up commit. Fortunately, it was pretty easy to remove the references to `edenMount_` in `Dirstate.cpp` and rewrite them in terms of `mountPoint_` or `objectStore_`. The one thing that I also decided to move was `getModifiedDirectoriesForMount()` because I already needed to create an `EdenMounts` file (admittedly not a great name) to collect some utility functions that use members of an `EdenMount` while not having access to the `EdenMount` itself. As part of this change, all of the code in `eden/fs/model/hg` has been moved to `eden/fs/inodes` so that it is alongside `EdenMount`. We are going to change the `Dirstate` from an Hg-specific concept to a more general concept. `LocalDirstatePersistence` is no longer one of two implementations of `DirstatePersistence`. (The other was `FakeDirstatePersistence`.) Now there is just one concrete implementation called `DirstatePersistence` that takes its implementation from `LocalDirstatePersistence`. Because there is no longer a `FakeDirstatePersistence`, `TestMount` must create a `DirstatePersistence` that uses a `TemporaryFile`. Because `TestMount` now takes responsibility for creating the `Dirstate`, it must also give callers the ability to specify the user directives. To that end, `TestMountBuilder` got an `addUserDirectives()` method while `TestMount` got a `getDirstate()` method. Surprisingly, `TestMountTest` did not need to be updated as part of this revision, but `DirstateTest` needed quite a few updates (which were generally mechanical). Reviewed By: simpkins Differential Revision: D4230154 fbshipit-source-id: 9b8cb52b45ef5d75bc8f5e62a58fcd1cddc32bfa
2016-11-26 23:00:15 +03:00
}