summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaksim Denisov <denisov.maksim@huawei.com>2024-07-01 10:51:05 +0200
committerMaksim Denisov <denisov.maksim@huawei.com>2024-07-01 11:24:28 +0200
commitb5ca0c1b80d62ae786b7a90215c8a2a6c5fb17a9 (patch)
treee6cd16585575804be989ce78a866678f318d6a86 /src
parent01d9abcfc85d974763c3a7f8fed998342d92a681 (diff)
downloadjustbuild-b5ca0c1b80d62ae786b7a90215c8a2a6c5fb17a9.tar.gz
Ensure unique paths are used in compactification
Diffstat (limited to 'src')
-rw-r--r--src/buildtool/storage/TARGETS1
-rw-r--r--src/buildtool/storage/compactification_task.cpp35
2 files changed, 25 insertions, 11 deletions
diff --git a/src/buildtool/storage/TARGETS b/src/buildtool/storage/TARGETS
index ec395ec5..61546d5d 100644
--- a/src/buildtool/storage/TARGETS
+++ b/src/buildtool/storage/TARGETS
@@ -72,6 +72,7 @@
, ["src/buildtool/logging", "log_level"]
, ["src/buildtool/execution_api/common", "message_limits"]
, ["src/buildtool/multithreading", "task_system"]
+ , ["src/utils/cpp", "path_hash"]
]
}
, "fs_utils":
diff --git a/src/buildtool/storage/compactification_task.cpp b/src/buildtool/storage/compactification_task.cpp
index ee9411ba..66ad0db2 100644
--- a/src/buildtool/storage/compactification_task.cpp
+++ b/src/buildtool/storage/compactification_task.cpp
@@ -14,9 +14,11 @@
#include "src/buildtool/storage/compactification_task.hpp"
+#include <array>
#include <atomic>
#include <optional>
#include <unordered_map>
+#include <unordered_set>
#include <utility> //std::move
#include <vector>
@@ -24,13 +26,14 @@
#include "src/buildtool/file_system/file_system_manager.hpp"
#include "src/buildtool/file_system/object_type.hpp"
#include "src/buildtool/multithreading/task_system.hpp"
+#include "src/utils/cpp/path_hash.hpp"
namespace {
[[nodiscard]] auto GetObjectTask(CompactificationTask const& task,
ObjectType type) noexcept
-> CompactificationTask::ObjectTask const&;
-[[nodiscard]] auto GetFilterTypes(CompactificationTask const& task) noexcept
+[[nodiscard]] auto GetFilterTypes(CompactificationTask const& task)
-> std::vector<ObjectType>;
using FilterResult = std::optional<std::vector<std::filesystem::path>>;
@@ -45,8 +48,8 @@ using FilterResult = std::optional<std::vector<std::filesystem::path>>;
{
TaskSystem ts;
// Filter entries to create execution tasks:
- for (auto type : GetFilterTypes(task)) {
- try {
+ try {
+ for (auto type : GetFilterTypes(task)) {
auto tstask =
[result = &scan_results[type], &failed, type, &task] {
*result = ::FilterEntries(task, type);
@@ -55,10 +58,10 @@ using FilterResult = std::optional<std::vector<std::filesystem::path>>;
}
};
ts.QueueTask(std::move(tstask));
- } catch (...) {
- ts.Shutdown();
- return false;
}
+ } catch (...) {
+ ts.Shutdown();
+ return false;
}
}
@@ -102,12 +105,22 @@ namespace {
Ensures(false); // unreachable
}
-[[nodiscard]] auto GetFilterTypes(CompactificationTask const& task) noexcept
+[[nodiscard]] auto GetFilterTypes(CompactificationTask const& task)
-> std::vector<ObjectType> {
- return task.large ? std::vector{ObjectType::File, ObjectType::Tree}
- : std::vector{ObjectType::File,
- ObjectType::Tree,
- ObjectType::Executable};
+ static constexpr std::array kObjectTypes{
+ ObjectType::File, ObjectType::Tree, ObjectType::Executable};
+
+ // Ensure that types point to unique disk locations.
+ // Duplication of roots leads to duplication of tasks.
+ std::vector<ObjectType> result;
+ std::unordered_set<std::filesystem::path> unique_roots;
+ for (ObjectType type : kObjectTypes) {
+ auto root = task.cas.StorageRoot(type, task.large);
+ if (unique_roots.insert(std::move(root)).second) {
+ result.emplace_back(type);
+ }
+ }
+ return result;
}
[[nodiscard]] auto FilterEntries(CompactificationTask const& task,