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

+96
View File
@@ -512,6 +512,102 @@ StateStore::materialize_blob(const BlobRef &ref, const std::filesystem::path &de
return {};
}
void StateStore::configure_remote_cache(std::optional<RemoteCacheConfig> config) {
if (config && !config->url.empty()) {
remote_.emplace(std::move(*config));
} else {
remote_.reset();
}
}
Void::Result::Result<std::optional<std::string>, Void::Result::Error>
StateStore::fetch_remote_action(std::string_view action_key) const {
if (!remote_) {
return std::optional<std::string>{};
}
return remote_->get_action(action_key);
}
Void::Result::Result<void, Void::Result::Error>
StateStore::publish_remote_action(std::string_view action_key, std::string_view json) const {
if (!remote_) {
return {};
}
return remote_->put_action(action_key, json);
}
Void::Result::Result<void, Void::Result::Error>
StateStore::publish_remote_blob(std::string_view sha256) const {
if (!remote_) {
return {};
}
if (!is_valid_sha256_hex(sha256)) {
return std::unexpected{make_error(Void::System::SystemErrorCode::invalid_argument,
"StateStore: invalid CAS blob digest")};
}
auto bytes = Void::FileSystem::read_file(cas_blob_path(sha256));
if (!bytes) {
return std::unexpected{bytes.error()};
}
if (Util::sha256_hex(*bytes) != sha256) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::invalid_argument,
std::format("StateStore: refusing to upload corrupted CAS blob '{}'", sha256))};
}
return remote_->put_blob(sha256, *bytes);
}
Void::Result::Result<bool, Void::Result::Error>
StateStore::ensure_remote_blob(std::string_view sha256) {
if (!is_valid_sha256_hex(sha256)) {
return false;
}
auto local = verify_blob(sha256);
if (!local) {
return std::unexpected{local.error()};
}
if (*local) {
return true;
}
if (!remote_) {
return false;
}
auto fetched = remote_->get_blob(sha256);
if (!fetched) {
return std::unexpected{fetched.error()};
}
if (!fetched->has_value()) {
return false;
}
const std::string &bytes = **fetched;
if (Util::sha256_hex(bytes) != sha256) {
return false;
}
const auto final_path = cas_blob_path(sha256);
std::error_code ec;
std::filesystem::create_directories(final_path.parent_path(), ec);
const auto stage_path =
staging_dir_ / std::format("remote_{}_{}.stage", sha256,
g_lease_seq.fetch_add(1, std::memory_order_relaxed));
auto wrote = Platform::atomic_write_file(stage_path, bytes, true, 0644);
if (!wrote) {
return std::unexpected{wrote.error()};
}
(void)::chmod(stage_path.c_str(), 0444);
std::filesystem::rename(stage_path, final_path, ec);
if (ec) {
std::filesystem::remove(stage_path, ec);
if (!std::filesystem::exists(final_path)) {
return std::unexpected{make_error(
Void::System::SystemErrorCode::io_error,
std::format("StateStore: failed publishing remote CAS blob '{}'", sha256))};
}
}
(void)Platform::fsync_directory(final_path.parent_path());
return true;
}
Void::Result::Result<std::optional<ActionSuccessRecord>, Void::Result::Error>
StateStore::lookup_action(std::string_view action_key) const {
std::optional<ActionSuccessRecord> found;