![]() |
Nix 2.36.0
Nix, the purely functional package manager; unstable internal interfaces
|
Public Member Functions | |
| GitRepoHandle | getRepo () |
| GitRepoPoolImpl (const std::filesystem::path &path, GitRepo::Options options) | |
| void | beginDependentPhase () |
| void | flush () override |
| std::unique_ptr< merkle::DirectorySinkWithFinalize > | makeDirectorySink () override |
| std::unique_ptr< merkle::RegularFileSinkWithFinalize > | makeRegularFileSink () override |
| merkle::TreeEntry | makeSymlink (const std::string &target) override |
| uint64_t | getRevCount (const Hash &rev) override |
Public Attributes | |
| std::filesystem::path | path |
| GitRepo::Options | options |
| bool | disablePackRefresh = true |
| Pool< GitRepoImpl > | pool |
| std::shared_ptr< GitRepoImpl > | singleRepo |
Additional Inherited Members | |
| Static Public Member Functions inherited from nix::GitRepoPool | |
| static ref< GitRepoPool > | create (const std::filesystem::path &path, GitRepo::Options options) |
A pool of GitRepoImpl instances for parallel merkle object writing.
libgit2 repositories are not thread-safe, so concurrent writes require separate repository handles. This pool manages those handles.
When disablePackRefresh is true, we monkey-patch the pack backend to only read the pack directory once. Otherwise it will do a readdir for each added oid when it's not found and that translates to ~6 syscalls. Since we are never writing pack files until flushing we can force the odb backend to read the directory just once. It's very convenient that the vtable is semi-public interface and is up for grabs.
This is purely an optimization for when we are writing independent data concurrently. For example, when we are only writing blobs to the git repo. Blobs are leaf nodes which cannot reference other objects, and so there is far less need for synchronisation.
The first makeDirectorySink call flushes all idle pool members to disk and opens the directory repo handle, which reads the pack directory as it is created — so that it sees those packfiles — and gets the same treatment, since nothing new will appear while we are writing the directories.
This comes up in our use-case of the tarball cache. We write all the files from the tarball to git, and only then write the directories. When writing files, libgit2 calls refresh() if the backend provides it when an oid isn't found. We are only writing objects to a mempack (it has higher priority) and there isn't a realistic use-case where a previously missing object would appear from thin air on the disk (unless another process happens to be unpacking a similar tarball to the cache at the same time, but that's a very unrealistic scenario). After we are done writing the files, we write the directories to a single dedicated repo handle (singleRepo).
|
inline |
Switch from writing independent objects to writing ones that refer to them: flush every idle pool member to disk, and open a handle that can see the packfiles just written.
Idempotent, and called lazily, so that a caller that only ever writes blobs never pays for it.
TODO: it would be nicer to merge the pool's mempacks, and let libgit2 decide when to spill to disk, rather than forcing a packfile per pool member just so the trees can refer to the blobs. libgit2 1.9 offers no way to do that: sys/mempack.h has no merge operation, and a git_odb_backend cannot be added to a second odb (add_backend_internal asserts it is unowned, and there is no refcount, so sharing one would double-free).
The ordering requirement is avoidable from the other end, though. git_treebuilder_write validates nothing; it is git_treebuilder_insert that checks that each child exists, via git_object__is_valid, which is a no-op when GIT_OPT_ENABLE_STRICT_OBJECT_CREATION is off. Turning that off would let the trees be written to any handle, so every handle could just flush once at the end, and this phase would not need to exist. It is a process-global setting, however, so we would be giving up that check everywhere.
|
inlineoverridevirtual |
Finish any writes that are still in progress.
Until this is called, objects written through this builder are not necessarily available to anything else that reads the same store.
Implements nix::merkle::FileSinkBuilder.
|
inlineoverridevirtual |
Implements nix::GitRepoPool.
|
inlineoverridevirtual |
Create a sink for one directory.
Every sink handed out before this call must have been finalized: an implementation is free to assume that, and to do whatever work making earlier objects referenceable requires.
Implements nix::merkle::FileSinkBuilder.
|
inlineoverridevirtual |
Implements nix::merkle::FileSinkBuilder.
|
inlineoverridevirtual |
Implements nix::merkle::FileSinkBuilder.
| bool nix::GitRepoPoolImpl::disablePackRefresh = true |
When true, new pool members have refresh disabled on their pack backend. Cleared once we start writing directories — not because refreshing is wanted then, but because the handle we write them with disables it for itself; see beginDependentPhase.
| std::shared_ptr<GitRepoImpl> nix::GitRepoPoolImpl::singleRepo |
Single repo handle used once we start writing directories. All sinks share this handle, avoiding per-sink pool overhead and extra packfile flushes. Only initialized by beginDependentPhase.