feat(cache): add shared HTTP action cache and parallel snapshot hashing
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s

- D1: RemoteCasClient + registry /api/v1/cas endpoints with bearer auth and digest verification, StateStore remote action/blob APIs, build-path-independent action keys, --remote-cache CLI
- D2: parallel snapshot revalidation hashing via Void::Concurrency::ThreadPool
- Verified in Docker GCC 16: 8/8 CTest suites, cross-build-dir 100% cache hit, 5001-file warm no-op 374 ms
- Fix self-host recipe source list for RemoteCache.cpp and accept GCC 16 -lgcc_s_asneeded
This commit is contained in:
faumaray committed 2026-12-03 12:36:21 +03:00
1 parent 6c225c2dff
commit 09c0a91d1d
19 files changed
+1213 -18

No files matched your search

+43 -7
View File
@@ -1,18 +1,22 @@
#include <Void/Build/Snapshot/Snapshot.hpp>
#include <Void/Async/ThreadPool.hpp>
#include <Void/Build/Platform/FileOps.hpp>
#include <Void/Build/Util/Json.hpp>
#include <Void/Build/Util/Sha256.hpp>
#include <Void/System/Types.hpp>
#include <algorithm>
#include <atomic>
#include <cerrno>
#include <dirent.h>
#include <fcntl.h>
#include <format>
#include <functional>
#include <future>
#include <set>
#include <sys/stat.h>
#include <thread>
#include <unistd.h>
namespace Void::Build::Snapshot {
@@ -32,6 +36,29 @@ bool is_excluded_name(std::string_view name, const std::vector<std::string> &exc
return std::ranges::contains(excluded, name);
}
// Bounded-parallel index loop used for content hashing (Track D2). Small inputs stay
// sequential to avoid thread-pool startup overhead.
template <typename Fn> void parallel_for_indices(std::size_t count, Fn fn) {
constexpr std::size_t kParallelThreshold = 32;
if (count < kParallelThreshold) {
for (std::size_t i = 0; i < count; ++i) {
fn(i);
}
return;
}
const std::size_t workers =
std::min<std::size_t>(count, std::max(1u, std::thread::hardware_concurrency()));
Void::Concurrency::ThreadPool pool{workers};
std::vector<std::future<void>> futures;
futures.reserve(count);
for (std::size_t i = 0; i < count; ++i) {
futures.push_back(pool.submit([&fn, i] { fn(i); }));
}
for (auto &future : futures) {
future.get();
}
}
bool path_has_excluded_component(const std::filesystem::path &rel_path,
const std::vector<std::string> &excluded) {
for (const auto &part : rel_path) {
@@ -393,15 +420,24 @@ Void::Result::Result<InputSnapshot, Void::Result::Error> capture_snapshot(
}
// Revalidation pass before sealing: detect concurrent mutations during capture.
bool mutated = false;
for (const auto &[logical, src_path] : source_files_to_verify) {
// Content hashing runs on a bounded thread pool for large trees (Track D2).
std::vector<std::pair<std::string, std::filesystem::path>> files_to_rehash;
files_to_rehash.reserve(source_files_to_verify.size());
for (const auto &entry : source_files_to_verify) {
files_to_rehash.push_back(entry);
}
std::atomic<bool> mutated{false};
parallel_for_indices(files_to_rehash.size(), [&](std::size_t i) {
if (mutated.load(std::memory_order_relaxed)) {
return;
}
const auto &[logical, src_path] = files_to_rehash[i];
auto rehash = Util::sha256_file_hex(src_path);
if (!rehash || *rehash != snap.entries.at(logical).sha256) {
mutated = true;
break;
mutated.store(true, std::memory_order_relaxed);
}
}
if (!mutated) {
});
if (!mutated.load()) {
for (const auto &[logical_dir, dir_path] : dirs_to_verify) {
auto meta = Platform::stat_lstat(dir_path);
if (!meta) {
@@ -422,7 +458,7 @@ Void::Result::Result<InputSnapshot, Void::Result::Error> capture_snapshot(
}
}
}
if (mutated) {
if (mutated.load()) {
continue;
}