summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/file_system/file_storage.hpp4
-rw-r--r--src/buildtool/storage/target_cache.hpp23
2 files changed, 24 insertions, 3 deletions
diff --git a/src/buildtool/file_system/file_storage.hpp b/src/buildtool/file_system/file_storage.hpp
index 922cbc54..488274a5 100644
--- a/src/buildtool/file_system/file_storage.hpp
+++ b/src/buildtool/file_system/file_storage.hpp
@@ -70,6 +70,10 @@ class FileStorage {
return storage_root_ / id.substr(0, 2) / id.substr(2, id.size() - 2);
}
+ [[nodiscard]] auto StorageRoot() const noexcept -> std::filesystem::path {
+ return storage_root_;
+ }
+
private:
static constexpr bool kFdLess{kType == ObjectType::Executable};
std::filesystem::path storage_root_{};
diff --git a/src/buildtool/storage/target_cache.hpp b/src/buildtool/storage/target_cache.hpp
index bd13ad99..c7f0ae53 100644
--- a/src/buildtool/storage/target_cache.hpp
+++ b/src/buildtool/storage/target_cache.hpp
@@ -51,9 +51,12 @@ class TargetCache {
std::function<bool(std::vector<Artifact::ObjectInfo> const&)>;
TargetCache(std::shared_ptr<LocalCAS<kDoGlobalUplink>> cas,
- std::filesystem::path const& store_path)
- : cas_{std::move(cas)}, file_store_{store_path / ComputeShard()} {
- if constexpr (kDoGlobalUplink) {
+ std::filesystem::path const& store_path,
+ bool compute_shard = true)
+ : cas_{std::move(cas)},
+ file_store_{compute_shard ? store_path / ComputeShard()
+ : store_path} {
+ if (kDoGlobalUplink && compute_shard) {
// write backend description (shard) to CAS
[[maybe_unused]] auto id =
cas_->StoreBlob(StorageConfig::ExecutionBackendDescription());
@@ -61,6 +64,20 @@ class TargetCache {
}
}
+ /// \brief Returns a new TargetCache backed by the same CAS, but the
+ /// FileStorage uses the given \p shard. This is particularly useful for the
+ /// just-serve server implementation, since the sharding must be performed
+ /// according to the client's request and not following the server
+ /// configuration. It is caller's responsibility to check that \p shard is a
+ /// valid path.
+ [[nodiscard]] auto WithShard(const std::string& shard) const
+ -> std::unique_ptr<TargetCache> {
+ return std::make_unique<TargetCache<kDoGlobalUplink>>(
+ cas_,
+ file_store_.StorageRoot().parent_path() / shard,
+ /*compute_shard=*/false);
+ }
+
TargetCache(TargetCache const&) = default;
TargetCache(TargetCache&&) noexcept = default;
auto operator=(TargetCache const&) -> TargetCache& = default;