summaryrefslogtreecommitdiff
path: root/src/buildtool/execution_api/execution_service/execution_server.cpp
diff options
context:
space:
mode:
authorOliver Reiche <oliver.reiche@huawei.com>2023-02-24 15:49:14 +0100
committerOliver Reiche <oliver.reiche@huawei.com>2023-03-13 17:28:59 +0100
commit42b452e72f536b63bac080880b8daa481099793c (patch)
tree0af1a60e5e0fefb5572df38e092def3d8ac74c05 /src/buildtool/execution_api/execution_service/execution_server.cpp
parent546bf5beebf2eb75e7b325f8f18969b4dd34a169 (diff)
downloadjustbuild-42b452e72f536b63bac080880b8daa481099793c.tar.gz
Storage: Reworked storage and garbage collection
The improved GC implementation uses refactored storage classes instead of directly accessing "unknown" file paths. The required storage class refactoring is quite substantial and outlined in the following paragraphs. The module `buildtool/file_system` was extended by: - `ObjectCAS`: a plain CAS implementation for reading/writing blobs and computing digests for a given `ObjectType`. Depending on that type, files written to the file system may have different properties (e.g., the x-bit set) or the digest may be computed differently (e.g., tree digests in non-compatible mode). A new module `buildtool/storage` was introduced containing: - `LocalCAS`: provides a common interface for the "logical CAS", which internally combines three `ObjectCAS`s, one for each `ObjectType` (file, executable, tree). - `LocalAC`: implements the action cache, which needs the `LocalCAS` for storing cache values. - `TargetCache`: implements the high-level target cache, which also needs the `LocalCAS` for storing cache values. - `LocalStorage`: combines the storage classes `LocalCAS`, `LocalAC`, and `TargetCache`. Those are initialized with settings from `StorageConfig`, such as the build root base path or number of generations for the garbage collector. `LocalStorage` is templated with a Boolean parameter `kDoGlobalUplink`, which indicates that, on every read/write access, the garbage collector should be used for uplinking across all generations (global). - `GarbageCollector`: responsible for garbage collection and the global uplinking across all generations. To do so, it employs instances of `LocalStorage` with `kDoGlobalUplink` set to false, in order to avoid endless recursion. The actual (local) uplinking within two single generations is performed by the corresponding storage class (e.g., `TargetCache` implements uplinking of target cache entries between two target cache generations etc.). Thereby, the actual knowledge how data should be uplinked is implemented by the instance that is responsible for creating the data in the first place.
Diffstat (limited to 'src/buildtool/execution_api/execution_service/execution_server.cpp')
-rw-r--r--src/buildtool/execution_api/execution_service/execution_server.cpp39
1 files changed, 20 insertions, 19 deletions
diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp
index 5f21f5ac..ed22e023 100644
--- a/src/buildtool/execution_api/execution_service/execution_server.cpp
+++ b/src/buildtool/execution_api/execution_service/execution_server.cpp
@@ -24,8 +24,8 @@
#include "fmt/format.h"
#include "gsl-lite/gsl-lite.hpp"
#include "src/buildtool/execution_api/execution_service/operation_cache.hpp"
-#include "src/buildtool/execution_api/local/garbage_collector.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
+#include "src/buildtool/storage/garbage_collector.hpp"
static void UpdateTimeStamp(::google::longrunning::Operation* op) {
::google::protobuf::Timestamp t;
@@ -40,7 +40,7 @@ auto ExecutionServiceImpl::GetAction(::bazel_re::ExecuteRequest const* request)
const noexcept -> std::pair<std::optional<::bazel_re::Action>,
std::optional<std::string>> {
// get action description
- auto path = storage_.BlobPath(request->action_digest(), false);
+ auto path = storage_->CAS().BlobPath(request->action_digest(), false);
if (!path) {
auto str = fmt::format("could not retrieve blob {} from cas",
request->action_digest().hash());
@@ -59,8 +59,8 @@ auto ExecutionServiceImpl::GetAction(::bazel_re::ExecuteRequest const* request)
}
path = Compatibility::IsCompatible()
- ? storage_.BlobPath(action.input_root_digest(), false)
- : storage_.TreePath(action.input_root_digest());
+ ? storage_->CAS().BlobPath(action.input_root_digest(), false)
+ : storage_->CAS().TreePath(action.input_root_digest());
if (!path) {
auto str = fmt::format("could not retrieve input root {} from cas",
@@ -75,7 +75,7 @@ auto ExecutionServiceImpl::GetCommand(::bazel_re::Action const& action)
const noexcept -> std::pair<std::optional<::bazel_re::Command>,
std::optional<std::string>> {
- auto path = storage_.BlobPath(action.command_digest(), false);
+ auto path = storage_->CAS().BlobPath(action.command_digest(), false);
if (!path) {
auto str = fmt::format("could not retrieve blob {} from cas",
action.command_digest().hash());
@@ -141,10 +141,10 @@ auto ExecutionServiceImpl::GetIExecutionAction(
}
static auto GetDirectoryFromDigest(::bazel_re::Digest const& digest,
- LocalStorage const& storage) noexcept
+ Storage const& storage) noexcept
-> std::optional<::bazel_re::Directory> {
// determine directory path from digest
- auto const& path = storage.BlobPath(digest, /*is_executable=*/false);
+ auto const& path = storage.CAS().BlobPath(digest, /*is_executable=*/false);
if (not path) {
return std::nullopt;
}
@@ -166,7 +166,7 @@ static auto GetDirectoryFromDigest(::bazel_re::Digest const& digest,
// NOLINTNEXTLINE(misc-no-recursion)
static auto CollectChildDirectoriesRecursively(
::bazel_re::Directory const& root,
- LocalStorage const& storage,
+ Storage const& storage,
gsl::not_null<std::unordered_map<::bazel_re::Digest,
::bazel_re::Directory>*> map) noexcept
-> bool {
@@ -196,7 +196,7 @@ static auto CollectChildDirectoriesRecursively(
}
static auto GetChildrenFromDirectory(::bazel_re::Directory const& root,
- LocalStorage const& storage) noexcept
+ Storage const& storage) noexcept
-> std::optional<std::vector<::bazel_re::Directory>> {
// determine child directories
std::unordered_map<::bazel_re::Digest, ::bazel_re::Directory> map{};
@@ -232,7 +232,7 @@ static auto GetChildrenFromDirectory(::bazel_re::Directory const& root,
static auto CreateTreeDigestFromDirectoryDigest(
::bazel_re::Digest const& dir_digest,
- LocalStorage const& storage) noexcept -> std::optional<::bazel_re::Digest> {
+ Storage const& storage) noexcept -> std::optional<::bazel_re::Digest> {
// determine root directory message
auto root = GetDirectoryFromDigest(dir_digest, storage);
if (not root) {
@@ -256,7 +256,8 @@ static auto CreateTreeDigestFromDirectoryDigest(
// serialize and store tree message
auto content = tree.SerializeAsString();
- auto tree_digest = storage.StoreBlob(content, /*is_executable=*/false);
+ auto tree_digest =
+ storage.CAS().StoreBlob(content, /*is_executable=*/false);
if (not tree_digest) {
return std::nullopt;
}
@@ -266,7 +267,7 @@ static auto CreateTreeDigestFromDirectoryDigest(
static auto AddOutputPaths(::bazel_re::ExecuteResponse* response,
IExecutionResponse::Ptr const& execution,
- LocalStorage const& storage) noexcept -> bool {
+ Storage const& storage) noexcept -> bool {
auto const& size = static_cast<int>(execution->Artifacts().size());
response->mutable_result()->mutable_output_files()->Reserve(size);
response->mutable_result()->mutable_output_directories()->Reserve(size);
@@ -311,7 +312,7 @@ auto ExecutionServiceImpl::AddResult(
IExecutionResponse::Ptr const& i_execution_response,
std::string const& action_hash) const noexcept
-> std::optional<std::string> {
- if (not AddOutputPaths(response, i_execution_response, storage_)) {
+ if (not AddOutputPaths(response, i_execution_response, *storage_)) {
auto str = fmt::format("Error in creating output paths of action {}",
action_hash);
logger_.Emit(LogLevel::Error, str);
@@ -320,8 +321,8 @@ auto ExecutionServiceImpl::AddResult(
auto* result = response->mutable_result();
result->set_exit_code(i_execution_response->ExitCode());
if (i_execution_response->HasStdErr()) {
- auto dgst = storage_.StoreBlob(i_execution_response->StdErr(),
- /*is_executable=*/false);
+ auto dgst = storage_->CAS().StoreBlob(i_execution_response->StdErr(),
+ /*is_executable=*/false);
if (!dgst) {
auto str =
fmt::format("Could not store stderr of action {}", action_hash);
@@ -331,8 +332,8 @@ auto ExecutionServiceImpl::AddResult(
result->mutable_stderr_digest()->CopyFrom(*dgst);
}
if (i_execution_response->HasStdOut()) {
- auto dgst = storage_.StoreBlob(i_execution_response->StdOut(),
- /*is_executable=*/false);
+ auto dgst = storage_->CAS().StoreBlob(i_execution_response->StdOut(),
+ /*is_executable=*/false);
if (!dgst) {
auto str =
fmt::format("Could not store stdout of action {}", action_hash);
@@ -375,8 +376,8 @@ auto ExecutionServiceImpl::StoreActionResult(
::bazel_re::Action const& action) const noexcept
-> std::optional<std::string> {
if (i_execution_response->ExitCode() == 0 && !action.do_not_cache() &&
- !storage_.StoreActionResult(request->action_digest(),
- execute_response.result())) {
+ !storage_->ActionCache().StoreResult(request->action_digest(),
+ execute_response.result())) {
auto str = fmt::format("Could not store action result for action {}",
request->action_digest().hash());
logger_.Emit(LogLevel::Error, str);