summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/execution_api/execution_service/TARGETS8
-rw-r--r--src/buildtool/execution_api/execution_service/ac_server.cpp3
-rw-r--r--src/buildtool/execution_api/execution_service/bytestream_server.cpp5
-rw-r--r--src/buildtool/execution_api/execution_service/cas_server.cpp11
-rw-r--r--src/buildtool/execution_api/execution_service/execution_server.cpp3
-rw-r--r--src/buildtool/main/main.cpp2
-rw-r--r--src/buildtool/serve_api/serve_service/source_tree.cpp12
-rw-r--r--src/buildtool/serve_api/serve_service/target.cpp4
-rw-r--r--src/buildtool/storage/garbage_collector.cpp22
-rw-r--r--src/buildtool/storage/garbage_collector.hpp12
-rw-r--r--src/other_tools/just_mr/TARGETS2
-rw-r--r--src/other_tools/just_mr/launch.cpp3
-rw-r--r--src/other_tools/just_mr/main.cpp3
13 files changed, 53 insertions, 37 deletions
diff --git a/src/buildtool/execution_api/execution_service/TARGETS b/src/buildtool/execution_api/execution_service/TARGETS
index 8bf4dc79..f0544913 100644
--- a/src/buildtool/execution_api/execution_service/TARGETS
+++ b/src/buildtool/execution_api/execution_service/TARGETS
@@ -14,7 +14,7 @@
]
, "private-deps":
[ ["@", "fmt", "", "fmt"]
- , ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/storage", "config"]
, ["src/buildtool/file_system", "file_system_manager"]
, ["src/buildtool/logging", "log_level"]
, "operation_cache"
@@ -37,7 +37,7 @@
, ["src/buildtool/storage", "storage"]
]
, "private-deps":
- [ ["src/buildtool/storage", "storage"]
+ [ ["src/buildtool/storage", "config"]
, ["src/buildtool/logging", "log_level"]
, ["src/utils/cpp", "verify_hash"]
]
@@ -59,7 +59,7 @@
[ ["src/buildtool/compatibility", "compatibility"]
, ["src/buildtool/logging", "log_level"]
, ["@", "fmt", "", "fmt"]
- , ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/storage", "config"]
, ["src/utils/cpp", "verify_hash"]
, "cas_utils"
]
@@ -107,7 +107,7 @@
, ["src/buildtool/logging", "log_level"]
, ["src/utils/cpp", "tmp_dir"]
, ["@", "fmt", "", "fmt"]
- , ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/storage", "config"]
, ["src/utils/cpp", "verify_hash"]
]
}
diff --git a/src/buildtool/execution_api/execution_service/ac_server.cpp b/src/buildtool/execution_api/execution_service/ac_server.cpp
index d998bd6d..8b0a216e 100644
--- a/src/buildtool/execution_api/execution_service/ac_server.cpp
+++ b/src/buildtool/execution_api/execution_service/ac_server.cpp
@@ -16,6 +16,7 @@
#include "fmt/core.h"
#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -30,7 +31,7 @@ auto ActionCacheServiceImpl::GetActionResult(
logger_.Emit(LogLevel::Trace,
"GetActionResult: {}",
request->action_digest().hash());
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str = fmt::format("Could not acquire SharedLock");
logger_.Emit(LogLevel::Error, str);
diff --git a/src/buildtool/execution_api/execution_service/bytestream_server.cpp b/src/buildtool/execution_api/execution_service/bytestream_server.cpp
index 92b06ef6..35ff221d 100644
--- a/src/buildtool/execution_api/execution_service/bytestream_server.cpp
+++ b/src/buildtool/execution_api/execution_service/bytestream_server.cpp
@@ -23,6 +23,7 @@
#include "src/buildtool/compatibility/native_support.hpp"
#include "src/buildtool/execution_api/common/bytestream_common.hpp"
#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/utils/cpp/tmp_dir.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -61,7 +62,7 @@ auto BytestreamServiceImpl::Read(
return ::grpc::Status{::grpc::StatusCode::INVALID_ARGUMENT, *error_msg};
}
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str = fmt::format("Could not acquire SharedLock");
logger_.Emit(LogLevel::Error, str);
@@ -125,7 +126,7 @@ auto BytestreamServiceImpl::Write(
*hash,
request.write_offset(),
request.finish_write());
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str = fmt::format("Could not acquire SharedLock");
logger_.Emit(LogLevel::Error, str);
diff --git a/src/buildtool/execution_api/execution_service/cas_server.cpp b/src/buildtool/execution_api/execution_service/cas_server.cpp
index c4cf8f6f..7d87ae75 100644
--- a/src/buildtool/execution_api/execution_service/cas_server.cpp
+++ b/src/buildtool/execution_api/execution_service/cas_server.cpp
@@ -27,6 +27,7 @@
#include "src/buildtool/compatibility/native_support.hpp"
#include "src/buildtool/execution_api/execution_service/cas_utils.hpp"
#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -62,7 +63,7 @@ auto CASServiceImpl::FindMissingBlobs(
::grpc::ServerContext* /*context*/,
const ::bazel_re::FindMissingBlobsRequest* request,
::bazel_re::FindMissingBlobsResponse* response) -> ::grpc::Status {
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str =
fmt::format("FindMissingBlobs: could not acquire SharedLock");
@@ -119,7 +120,7 @@ auto CASServiceImpl::BatchUpdateBlobs(
::grpc::ServerContext* /*context*/,
const ::bazel_re::BatchUpdateBlobsRequest* request,
::bazel_re::BatchUpdateBlobsResponse* response) -> ::grpc::Status {
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str =
fmt::format("BatchUpdateBlobs: could not acquire SharedLock");
@@ -183,7 +184,7 @@ auto CASServiceImpl::BatchReadBlobs(
::grpc::ServerContext* /*context*/,
const ::bazel_re::BatchReadBlobsRequest* request,
::bazel_re::BatchReadBlobsResponse* response) -> ::grpc::Status {
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str = fmt::format("BatchReadBlobs: Could not acquire SharedLock");
logger_.Emit(LogLevel::Error, "{}", str);
@@ -265,7 +266,7 @@ auto CASServiceImpl::SplitBlob(::grpc::ServerContext* /*context*/,
}
// Acquire garbage collection lock.
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (not lock) {
auto str =
fmt::format("SplitBlob: could not acquire garbage collection lock");
@@ -331,7 +332,7 @@ auto CASServiceImpl::SpliceBlob(::grpc::ServerContext* /*context*/,
request->chunk_digests().size());
// Acquire garbage collection lock.
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (not lock) {
auto str = fmt::format(
"SpliceBlob: could not acquire garbage collection lock");
diff --git a/src/buildtool/execution_api/execution_service/execution_server.cpp b/src/buildtool/execution_api/execution_service/execution_server.cpp
index b71380f5..ef00677e 100644
--- a/src/buildtool/execution_api/execution_service/execution_server.cpp
+++ b/src/buildtool/execution_api/execution_service/execution_server.cpp
@@ -25,6 +25,7 @@
#include "src/buildtool/execution_api/execution_service/operation_cache.hpp"
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/logging/log_level.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/utils/cpp/verify_hash.hpp"
@@ -446,7 +447,7 @@ auto ExecutionServiceImpl::Execute(
const ::bazel_re::ExecuteRequest* request,
::grpc::ServerWriter<::google::longrunning::Operation>* writer)
-> ::grpc::Status {
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto str = fmt::format("Could not acquire SharedLock");
logger_.Emit(LogLevel::Error, str);
diff --git a/src/buildtool/main/main.cpp b/src/buildtool/main/main.cpp
index 2b3add04..ee5bc661 100644
--- a/src/buildtool/main/main.cpp
+++ b/src/buildtool/main/main.cpp
@@ -909,7 +909,7 @@ auto main(int argc, char* argv[]) -> int {
#endif // BOOTSTRAP_BUILD_TOOL
#ifndef BOOTSTRAP_BUILD_TOOL
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (not lock) {
return kExitFailure;
}
diff --git a/src/buildtool/serve_api/serve_service/source_tree.cpp b/src/buildtool/serve_api/serve_service/source_tree.cpp
index b7e5d59c..8be074fc 100644
--- a/src/buildtool/serve_api/serve_service/source_tree.cpp
+++ b/src/buildtool/serve_api/serve_service/source_tree.cpp
@@ -775,7 +775,7 @@ auto SourceTreeService::ServeArchiveTree(
return ::grpc::Status::OK;
}
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeArchiveTreeResponse::INTERNAL_ERROR);
@@ -985,7 +985,7 @@ auto SourceTreeService::ServeDistdirTree(
const ::justbuild::just_serve::ServeDistdirTreeRequest* request,
ServeDistdirTreeResponse* response) -> ::grpc::Status {
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeDistdirTreeResponse::INTERNAL_ERROR);
@@ -1276,7 +1276,7 @@ auto SourceTreeService::ServeContent(
ServeContentResponse* response) -> ::grpc::Status {
auto const& content{request->content()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeContentResponse::INTERNAL_ERROR);
@@ -1386,7 +1386,7 @@ auto SourceTreeService::ServeTree(
ServeTreeResponse* response) -> ::grpc::Status {
auto const& tree_id{request->tree()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(ServeTreeResponse::INTERNAL_ERROR);
@@ -1520,7 +1520,7 @@ auto SourceTreeService::CheckRootTree(
CheckRootTreeResponse* response) -> ::grpc::Status {
auto const& tree_id{request->tree()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(CheckRootTreeResponse::INTERNAL_ERROR);
@@ -1622,7 +1622,7 @@ auto SourceTreeService::GetRemoteTree(
GetRemoteTreeResponse* response) -> ::grpc::Status {
auto const& tree_id{request->tree()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
logger_->Emit(LogLevel::Error, "Could not acquire gc SharedLock");
response->set_status(GetRemoteTreeResponse::INTERNAL_ERROR);
diff --git a/src/buildtool/serve_api/serve_service/target.cpp b/src/buildtool/serve_api/serve_service/target.cpp
index afafb720..cc21a7be 100644
--- a/src/buildtool/serve_api/serve_service/target.cpp
+++ b/src/buildtool/serve_api/serve_service/target.cpp
@@ -129,7 +129,7 @@ auto TargetService::ServeTarget(
ArtifactDigest{request->target_cache_key_id()};
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto msg = std::string("Could not acquire gc SharedLock");
logger_->Emit(LogLevel::Error, msg);
@@ -880,7 +880,7 @@ auto TargetService::ServeTargetDescription(
}
// acquire lock for CAS
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (!lock) {
auto error_msg = fmt::format("Could not acquire gc SharedLock");
logger_->Emit(LogLevel::Error, error_msg);
diff --git a/src/buildtool/storage/garbage_collector.cpp b/src/buildtool/storage/garbage_collector.cpp
index 3fe876c7..b4422d11 100644
--- a/src/buildtool/storage/garbage_collector.cpp
+++ b/src/buildtool/storage/garbage_collector.cpp
@@ -34,7 +34,6 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/storage/compactifier.hpp"
-#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/storage.hpp"
#include "src/buildtool/storage/target_cache_entry.hpp"
#include "src/utils/cpp/hex_string.hpp"
@@ -141,16 +140,19 @@ auto GarbageCollector::GlobalUplinkTargetCacheEntry(
return false;
}
-auto GarbageCollector::SharedLock() noexcept -> std::optional<LockFile> {
- return LockFile::Acquire(LockFilePath(), /*is_shared=*/true);
+auto GarbageCollector::SharedLock(StorageConfig const& storage_config) noexcept
+ -> std::optional<LockFile> {
+ return LockFile::Acquire(LockFilePath(storage_config), /*is_shared=*/true);
}
-auto GarbageCollector::ExclusiveLock() noexcept -> std::optional<LockFile> {
- return LockFile::Acquire(LockFilePath(), /*is_shared=*/false);
+auto GarbageCollector::ExclusiveLock(
+ StorageConfig const& storage_config) noexcept -> std::optional<LockFile> {
+ return LockFile::Acquire(LockFilePath(storage_config), /*is_shared=*/false);
}
-auto GarbageCollector::LockFilePath() noexcept -> std::filesystem::path {
- return StorageConfig::Instance().CacheRoot() / "gc.lock";
+auto GarbageCollector::LockFilePath(
+ StorageConfig const& storage_config) noexcept -> std::filesystem::path {
+ return storage_config.CacheRoot() / "gc.lock";
}
auto GarbageCollector::TriggerGarbageCollection(bool no_rotation) noexcept
@@ -167,7 +169,7 @@ auto GarbageCollector::TriggerGarbageCollection(bool no_rotation) noexcept
// With a shared lock, we can remove all directories with the given prefix,
// as we own the process id.
{
- auto lock = SharedLock();
+ auto lock = SharedLock(StorageConfig::Instance());
if (not lock) {
Logger::Log(LogLevel::Error,
"Failed to get a shared lock the local build root");
@@ -194,7 +196,7 @@ auto GarbageCollector::TriggerGarbageCollection(bool no_rotation) noexcept
// after releasing the shared lock, wait to get an exclusive lock for doing
// the critical renaming
{
- auto lock = ExclusiveLock();
+ auto lock = ExclusiveLock(StorageConfig::Instance());
if (not lock) {
Logger::Log(LogLevel::Error,
"Failed to exclusively lock the local build root");
@@ -287,7 +289,7 @@ auto GarbageCollector::TriggerGarbageCollection(bool no_rotation) noexcept
// have to remove
bool success{};
{
- auto lock = SharedLock();
+ auto lock = SharedLock(StorageConfig::Instance());
if (not lock) {
Logger::Log(LogLevel::Error,
"Failed to get a shared lock the local build root");
diff --git a/src/buildtool/storage/garbage_collector.hpp b/src/buildtool/storage/garbage_collector.hpp
index 0d80def0..18c9b280 100644
--- a/src/buildtool/storage/garbage_collector.hpp
+++ b/src/buildtool/storage/garbage_collector.hpp
@@ -20,6 +20,7 @@
#include <optional>
#include <string>
+#include "src/buildtool/storage/config.hpp"
#include "src/utils/cpp/file_locking.hpp"
// forward declarations
@@ -82,14 +83,19 @@ class GarbageCollector {
bool no_rotation = false) noexcept -> bool;
/// \brief Acquire shared lock to prevent garbage collection from running.
+ /// \param storage_config Storage to be locked.
/// \returns The acquired lock file on success or nullopt otherwise.
- [[nodiscard]] auto static SharedLock() noexcept -> std::optional<LockFile>;
+ [[nodiscard]] auto static SharedLock(
+ StorageConfig const& storage_config) noexcept
+ -> std::optional<LockFile>;
private:
- [[nodiscard]] auto static ExclusiveLock() noexcept
+ [[nodiscard]] auto static ExclusiveLock(
+ StorageConfig const& storage_config) noexcept
-> std::optional<LockFile>;
- [[nodiscard]] auto static LockFilePath() noexcept -> std::filesystem::path;
+ [[nodiscard]] auto static LockFilePath(
+ StorageConfig const& storage_config) noexcept -> std::filesystem::path;
/// \brief Remove spliced objects from the youngest generation and split
/// objects that are larger than the threshold.
diff --git a/src/other_tools/just_mr/TARGETS b/src/other_tools/just_mr/TARGETS
index 4f4dc20d..8d105b22 100644
--- a/src/other_tools/just_mr/TARGETS
+++ b/src/other_tools/just_mr/TARGETS
@@ -16,6 +16,7 @@
, ["src/buildtool/main", "retry"]
, ["src/buildtool/main", "version"]
, ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/storage", "config"]
, "cli"
, "exit_codes"
, "fetch"
@@ -195,6 +196,7 @@
, ["src/buildtool/logging", "logging"]
, ["src/buildtool/multithreading", "task_system"]
, ["src/buildtool/storage", "storage"]
+ , ["src/buildtool/storage", "config"]
, "exit_codes"
, "setup"
, "utils"
diff --git a/src/other_tools/just_mr/launch.cpp b/src/other_tools/just_mr/launch.cpp
index 132ed065..cfa45406 100644
--- a/src/other_tools/just_mr/launch.cpp
+++ b/src/other_tools/just_mr/launch.cpp
@@ -23,6 +23,7 @@
#include "src/buildtool/logging/log_level.hpp"
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
#include "src/other_tools/just_mr/setup.hpp"
@@ -61,7 +62,7 @@ auto CallJust(std::optional<std::filesystem::path> const& config_file,
if (subcommand and kKnownJustSubcommands.contains(*subcommand)) {
// Read the config file if needed
if (kKnownJustSubcommands.at(*subcommand).config) {
- lock = GarbageCollector::SharedLock();
+ lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (not lock) {
return kExitGenericFailure;
}
diff --git a/src/other_tools/just_mr/main.cpp b/src/other_tools/just_mr/main.cpp
index 1d1e5a43..f35d92b4 100644
--- a/src/other_tools/just_mr/main.cpp
+++ b/src/other_tools/just_mr/main.cpp
@@ -36,6 +36,7 @@
#include "src/buildtool/logging/logger.hpp"
#include "src/buildtool/main/retry.hpp"
#include "src/buildtool/main/version.hpp"
+#include "src/buildtool/storage/config.hpp"
#include "src/buildtool/storage/garbage_collector.hpp"
#include "src/other_tools/just_mr/cli.hpp"
#include "src/other_tools/just_mr/exit_codes.hpp"
@@ -347,7 +348,7 @@ auto main(int argc, char* argv[]) -> int {
forward_build_root,
my_name);
}
- auto lock = GarbageCollector::SharedLock();
+ auto lock = GarbageCollector::SharedLock(StorageConfig::Instance());
if (not lock) {
return kExitGenericFailure;
}