summaryrefslogtreecommitdiff
path: root/src/buildtool/storage/uplinker.cpp
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-07-01 16:54:24 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-05 13:32:39 +0200
commit18d26dea1bf9c29a073870988a190cdd7dbc8ed0 (patch)
tree5887e73048f7c576bece3fc23f401f7ddd4bdd00 /src/buildtool/storage/uplinker.cpp
parent993245d862fcd44b1d8d404b970cbd774526ae2b (diff)
downloadjustbuild-18d26dea1bf9c29a073870988a190cdd7dbc8ed0.tar.gz
Implement uplinking logic in a separate class.
Diffstat (limited to 'src/buildtool/storage/uplinker.cpp')
-rw-r--r--src/buildtool/storage/uplinker.cpp117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/buildtool/storage/uplinker.cpp b/src/buildtool/storage/uplinker.cpp
new file mode 100644
index 00000000..42213b33
--- /dev/null
+++ b/src/buildtool/storage/uplinker.cpp
@@ -0,0 +1,117 @@
+// Copyright 2024 Huawei Cloud Computing Technology Co., Ltd.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef BOOTSTRAP_BUILD_TOOL
+
+#include "src/buildtool/storage/uplinker.hpp"
+
+#include <algorithm>
+#include <cstddef>
+
+#include "src/buildtool/common/bazel_types.hpp"
+#include "src/buildtool/file_system/object_type.hpp"
+#include "src/buildtool/storage/local_ac.hpp"
+#include "src/buildtool/storage/local_cas.hpp"
+#include "src/buildtool/storage/storage.hpp"
+#include "src/buildtool/storage/target_cache.hpp"
+#include "src/buildtool/storage/target_cache_entry.hpp"
+
+namespace {
+[[nodiscard]] auto CreateGenerations(
+ gsl::not_null<StorageConfig const*> const& storage_config) noexcept
+ -> std::vector<Generation> {
+ std::vector<Generation> generations;
+ generations.reserve(storage_config->NumGenerations());
+ for (std::size_t i = 0; i < storage_config->NumGenerations(); ++i) {
+ auto const gen_config = storage_config->CreateGenerationConfig(i);
+ generations.emplace_back(gen_config);
+ }
+ return generations;
+}
+} // namespace
+
+GlobalUplinker::GlobalUplinker(
+ gsl::not_null<StorageConfig const*> const& storage_config) noexcept
+ : storage_config_{*storage_config},
+ generations_{CreateGenerations(&storage_config_)} {}
+
+auto GlobalUplinker::UplinkBlob(bazel_re::Digest const& digest,
+ bool is_executable) const noexcept -> bool {
+ // Try to find blob in all generations.
+ auto const& latest = generations_[Generation::kYoungest].CAS();
+ return std::any_of(
+ generations_.begin(),
+ generations_.end(),
+ [&latest, &digest, is_executable](Generation const& generation) {
+ return generation.CAS().LocalUplinkBlob(latest,
+ digest,
+ is_executable,
+ /*skip_sync=*/true,
+ /*splice_result=*/true);
+ });
+}
+
+auto GlobalUplinker::UplinkTree(bazel_re::Digest const& digest) const noexcept
+ -> bool {
+ // Try to find blob in all generations.
+ auto const& latest = generations_[Generation::kYoungest].CAS();
+ return std::any_of(generations_.begin(),
+ generations_.end(),
+ [&latest, &digest](Generation const& generation) {
+ return generation.CAS().LocalUplinkTree(
+ latest, digest, /*splice_result=*/true);
+ });
+}
+
+auto GlobalUplinker::UplinkLargeBlob(
+ bazel_re::Digest const& digest) const noexcept -> bool {
+ // Try to find large entry in all generations.
+ auto const& latest = generations_[Generation::kYoungest].CAS();
+ return std::any_of(
+ generations_.begin(),
+ generations_.end(),
+ [&latest, &digest](Generation const& generation) {
+ return generation.CAS().LocalUplinkLargeObject<ObjectType::File>(
+ latest, digest);
+ });
+}
+
+auto GlobalUplinker::UplinkActionCacheEntry(
+ bazel_re::Digest const& action_id) const noexcept -> bool {
+ // Try to find action-cache entry in all generations.
+ auto const& latest = generations_[Generation::kYoungest].ActionCache();
+ return std::any_of(generations_.begin(),
+ generations_.end(),
+ [&latest, &action_id](Generation const& generation) {
+ return generation.ActionCache().LocalUplinkEntry(
+ latest, action_id);
+ });
+}
+
+auto GlobalUplinker::UplinkTargetCacheEntry(
+ TargetCacheKey const& key,
+ std::optional<std::string> const& shard) const noexcept -> bool {
+ // Try to find target-cache entry in all generations.
+ auto const& latest =
+ generations_[Generation::kYoungest].TargetCache().WithShard(shard);
+ return std::any_of(
+ generations_.begin(),
+ generations_.end(),
+ [&latest, &key, &shard](Generation const& generation) {
+ return generation.TargetCache().WithShard(shard).LocalUplinkEntry(
+ latest, key);
+ });
+}
+
+#endif // BOOTSTRAP_BUILD_TOOL