feat(cache): add shared HTTP action cache and parallel snapshot hashing
VoidBuildSystem CI / build-and-test-gcc16 (push) Failing after 4s
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:
1 parent
6c225c2dff
commit
09c0a91d1d
19 files changed
+1213
-18
No files matched your search
@@ -86,6 +86,14 @@ bool valid_package_name(std::string_view name) {
|
||||
});
|
||||
}
|
||||
|
||||
bool is_sha256_hex(std::string_view hex) {
|
||||
if (hex.size() != 64) {
|
||||
return false;
|
||||
}
|
||||
return std::ranges::all_of(
|
||||
hex, [](char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f'); });
|
||||
}
|
||||
|
||||
std::vector<std::string> split_path(std::string_view path) {
|
||||
std::vector<std::string> segs;
|
||||
for (const auto part : Void::Str::split(path, '/')) {
|
||||
@@ -144,6 +152,8 @@ std::string content_type_for_ext(const std::filesystem::path &p) {
|
||||
|
||||
RegistryService::RegistryService(RegistryConfig config)
|
||||
: config_{std::move(config)}, blobs_dir_{config_.data_dir / "cas" / "blobs"},
|
||||
action_blobs_dir_{config_.data_dir / "action-cache" / "blobs"},
|
||||
action_records_dir_{config_.data_dir / "action-cache" / "actions"},
|
||||
meta_file_{config_.data_dir / "metadata.v1.json"},
|
||||
lock_file_{config_.data_dir / "registry.lock"} {}
|
||||
|
||||
@@ -151,6 +161,8 @@ Void::Result::Result<std::unique_ptr<RegistryService>, Void::Result::Error>
|
||||
RegistryService::open(RegistryConfig config) {
|
||||
std::error_code ec;
|
||||
std::filesystem::create_directories(config.data_dir / "cas" / "blobs", ec);
|
||||
std::filesystem::create_directories(config.data_dir / "action-cache" / "blobs", ec);
|
||||
std::filesystem::create_directories(config.data_dir / "action-cache" / "actions", ec);
|
||||
if (ec) {
|
||||
return std::unexpected{make_error(Void::System::map_errno_to_system_code(ec.value()),
|
||||
"RegistryService::open: cannot create data directories")};
|
||||
@@ -638,6 +650,66 @@ HttpResponse RegistryService::handle_request(const HttpRequest &req) {
|
||||
"}\n");
|
||||
}
|
||||
|
||||
// Shared content-addressed action cache (Track D1).
|
||||
// GET/PUT /api/v1/cas/blobs/<sha256> and /api/v1/cas/actions/<action_key>.
|
||||
if (segs.size() == 5 && segs[0] == "api" && segs[1] == "v1" && segs[2] == "cas" &&
|
||||
(segs[3] == "blobs" || segs[3] == "actions")) {
|
||||
const bool is_blob = segs[3] == "blobs";
|
||||
const std::string &key = segs[4];
|
||||
if (!is_sha256_hex(key)) {
|
||||
return HttpResponse::error_json(400, "invalid_key",
|
||||
"CAS key must be a SHA-256 hex digest");
|
||||
}
|
||||
if (!principal) {
|
||||
return HttpResponse::error_json(401, "unauthorized", "authentication required");
|
||||
}
|
||||
const auto base_dir = is_blob ? action_blobs_dir_ : action_records_dir_;
|
||||
const auto resource_path = base_dir / key.substr(0, 2) / (is_blob ? key : key + ".json");
|
||||
|
||||
if (req.method == "GET") {
|
||||
auto bytes = Void::FileSystem::read_file(resource_path);
|
||||
if (!bytes) {
|
||||
return HttpResponse::error_json(404, "not_found", "CAS object not found");
|
||||
}
|
||||
HttpResponse resp;
|
||||
resp.status = 200;
|
||||
resp.headers["Content-Type"] =
|
||||
is_blob ? "application/octet-stream" : "application/json; charset=utf-8";
|
||||
resp.body = std::move(*bytes);
|
||||
return resp;
|
||||
}
|
||||
if (req.method != "PUT") {
|
||||
return HttpResponse::error_json(405, "method_not_allowed", "CAS supports GET and PUT");
|
||||
}
|
||||
if (!principal->scopes.contains("publish") && principal->role != Role::Admin) {
|
||||
append_audit_locked(principal->username, "cas.put", key, "denied",
|
||||
"missing publish scope");
|
||||
return HttpResponse::error_json(403, "forbidden", "publish scope required");
|
||||
}
|
||||
if (!is_blob && !Void::Json::Strict::parse(req.body)) {
|
||||
return HttpResponse::error_json(400, "invalid_json", "CAS action record must be JSON");
|
||||
}
|
||||
if (is_blob && Util::sha256_hex(req.body) != key) {
|
||||
append_audit_locked(principal->username, "cas.put", key, "denied",
|
||||
"blob digest mismatch");
|
||||
return HttpResponse::error_json(400, "digest_mismatch",
|
||||
"body SHA-256 does not match CAS key");
|
||||
}
|
||||
std::error_code cas_ec;
|
||||
if (std::filesystem::is_regular_file(resource_path, cas_ec)) {
|
||||
return HttpResponse::json(200, "{\"stored\":true,\"created\":false}\n");
|
||||
}
|
||||
std::filesystem::create_directories(resource_path.parent_path(), cas_ec);
|
||||
auto wrote =
|
||||
Platform::atomic_write_file(resource_path, req.body, true, is_blob ? 0444u : 0644u);
|
||||
if (!wrote) {
|
||||
return HttpResponse::error_json(500, "storage_error", "failed storing CAS object");
|
||||
}
|
||||
append_audit_locked(principal->username, is_blob ? "cas.blob.put" : "cas.action.put", key,
|
||||
"ok", "stored");
|
||||
return HttpResponse::json(201, "{\"stored\":true,\"created\":true}\n");
|
||||
}
|
||||
|
||||
auto can_read_pkg = [&](const PackageMeta &p) {
|
||||
if (!p.is_private)
|
||||
return true;
|
||||
|
||||
Reference in new issue
Block a user