diff options
author | Maksim Denisov <denisov.maksim@huawei.com> | 2024-04-02 17:58:12 +0200 |
---|---|---|
committer | Maksim Denisov <denisov.maksim@huawei.com> | 2024-04-17 11:04:08 +0200 |
commit | d9bf1d63768f1c3d660c3057d6d77c9b3b4a346d (patch) | |
tree | 126390fab01d8271a12af7749c91f3fbfebce43a /src/buildtool/storage/garbage_collector.cpp | |
parent | aef304900c79493112c9c3951fcfc00e4f3a58bf (diff) | |
download | justbuild-d9bf1d63768f1c3d660c3057d6d77c9b3b4a346d.tar.gz |
Compactification: Remove spliced entries.
During garbage collection remove from the storage every entry that has the large entry.
Diffstat (limited to 'src/buildtool/storage/garbage_collector.cpp')
-rw-r--r-- | src/buildtool/storage/garbage_collector.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/buildtool/storage/garbage_collector.cpp b/src/buildtool/storage/garbage_collector.cpp index 7c5f9db2..1b7dc09b 100644 --- a/src/buildtool/storage/garbage_collector.cpp +++ b/src/buildtool/storage/garbage_collector.cpp @@ -18,6 +18,7 @@ #include <cstddef> #include <filesystem> +#include <memory> #include <vector> #include "nlohmann/json.hpp" @@ -31,6 +32,7 @@ #include "src/buildtool/file_system/object_type.hpp" #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" @@ -236,6 +238,16 @@ auto GarbageCollector::TriggerGarbageCollection(bool no_rotation) noexcept remove_me_dir.string()); } } + + // Compactification must take place before rotating generations. + // Otherwise, an interruption of the process during compactification + // would lead to an invalid old generation. + if (not GarbageCollector::Compactify()) { + Logger::Log(LogLevel::Error, + "Failed to compactify the youngest generation."); + return false; + } + // Rotate generations unless told not to do so if (not no_rotation) { auto remove_me_dir = @@ -278,4 +290,23 @@ auto GarbageCollector::TriggerGarbageCollection(bool no_rotation) noexcept return success; } +auto GarbageCollector::Compactify() noexcept -> bool { + const bool mode = Compatibility::IsCompatible(); + + // Return to the initial compatibility mode once done: + auto scope_guard = std::shared_ptr<void>(nullptr, [mode](void* /*unused*/) { + Compatibility::SetCompatible(mode); + }); + + // Compactification must be done for both native and compatible storages. + auto compactify = [](bool compatible) -> bool { + auto const storage = + ::Generation(StorageConfig::GenerationCacheDir(0, compatible)); + Compatibility::SetCompatible(compatible); + + return Compactifier::RemoveSpliced(storage.CAS()); + }; + return compactify(mode) and compactify(not mode); +} + #endif // BOOTSTRAP_BUILD_TOOL |