aboutsummaryrefslogtreecommitdiff
path: root/zenserver/compute/apply.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zenserver/compute/apply.cpp')
-rw-r--r--zenserver/compute/apply.cpp54
1 files changed, 41 insertions, 13 deletions
diff --git a/zenserver/compute/apply.cpp b/zenserver/compute/apply.cpp
index 7b76bb80b..3197eaee4 100644
--- a/zenserver/compute/apply.cpp
+++ b/zenserver/compute/apply.cpp
@@ -588,7 +588,7 @@ HttpFunctionService::HttpFunctionService(CasStore& Store, CidStore& InCidStore,
TotalAttachmentBytes += CompressedSize;
++AttachmentCount;
- const CasStore::InsertResult InsertResult = m_CidStore.AddChunk(DataView);
+ const CidStore::InsertResult InsertResult = m_CidStore.AddChunk(DataView);
if (InsertResult.New)
{
@@ -659,16 +659,21 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action)
{
CbObjectView ExecEntry = It.AsObjectView();
- std::string_view Name = ExecEntry["name"sv].AsString();
- const IoHash Hash = ExecEntry["hash"sv].AsHash();
- const uint64_t Size = ExecEntry["size"sv].AsUInt64();
+ std::string_view Name = ExecEntry["name"sv].AsString();
+ const IoHash ChunkHash = ExecEntry["hash"sv].AsHash();
+ const uint64_t Size = ExecEntry["size"sv].AsUInt64();
std::filesystem::path FilePath{SandboxPath / Name};
- IoBuffer DataBuffer = m_CasStore.FindChunk(Hash);
+ IoBuffer DataBuffer = m_CasStore.FindChunk(ChunkHash);
if (!DataBuffer)
{
- throw std::runtime_error("worker CAS chunk '{}' missing"_format(Hash));
+ throw std::runtime_error("worker CAS chunk '{}' missing"_format(ChunkHash));
+ }
+
+ if (DataBuffer.Size() != Size)
+ {
+ throw std::runtime_error("worker CAS chunk '{}' size: {}, action spec expected {}"_format(ChunkHash, DataBuffer.Size(), Size));
}
zen::WriteFile(FilePath, DataBuffer);
@@ -685,16 +690,21 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action)
{
CbObjectView FileEntry = It.AsObjectView();
- std::string_view Name = FileEntry["name"sv].AsString();
- const IoHash Hash = FileEntry["hash"sv].AsHash();
- const uint64_t Size = FileEntry["size"sv].AsUInt64();
+ std::string_view Name = FileEntry["name"sv].AsString();
+ const IoHash ChunkHash = FileEntry["hash"sv].AsHash();
+ const uint64_t Size = FileEntry["size"sv].AsUInt64();
std::filesystem::path FilePath{SandboxPath / Name};
- IoBuffer DataBuffer = m_CasStore.FindChunk(Hash);
+ IoBuffer DataBuffer = m_CasStore.FindChunk(ChunkHash);
if (!DataBuffer)
{
- throw std::runtime_error("worker CAS chunk '{}' missing"_format(Hash));
+ throw std::runtime_error("worker CAS chunk '{}' missing"_format(ChunkHash));
+ }
+
+ if (DataBuffer.Size() != Size)
+ {
+ throw std::runtime_error("worker CAS chunk '{}' size: {}, action spec expected {}"_format(ChunkHash, DataBuffer.Size(), Size));
}
zen::WriteFile(FilePath, DataBuffer);
@@ -796,11 +806,14 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action)
CbPackage OutputPackage;
CbObject Output = zen::LoadCompactBinaryObject(OutputData.Data[0]);
+ uint64_t TotalAttachmentBytes = 0;
+ uint64_t TotalRawAttachmentBytes = 0;
+
Output.IterateAttachments([&](CbFieldView Field) {
IoHash Hash = Field.AsHash();
std::filesystem::path OutputPath{SandboxPath / "Outputs" / Hash.ToHexString()};
- FileContents ChunkData = zen::ReadFile(SandboxPath / "build.output");
+ FileContents ChunkData = zen::ReadFile(OutputPath);
if (ChunkData.ErrorCode)
{
@@ -809,12 +822,27 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action)
ZEN_ASSERT(OutputData.Data.size() == 1);
- CbAttachment Attachment(CompressedBuffer::FromCompressed(SharedBuffer(ChunkData.Data[0])));
+ CompressedBuffer AttachmentBuffer = CompressedBuffer::FromCompressed(SharedBuffer(ChunkData.Data[0]));
+
+ if (!AttachmentBuffer)
+ {
+ throw std::runtime_error("Invalid output encountered (not valid CompressedBuffer format)");
+ }
+
+ TotalAttachmentBytes += AttachmentBuffer.GetCompressedSize();
+ TotalRawAttachmentBytes += AttachmentBuffer.GetCompressedSize();
+
+ CbAttachment Attachment(AttachmentBuffer);
OutputPackage.AddAttachment(Attachment);
});
OutputPackage.SetObject(Output);
+ ZEN_DEBUG("Action completed with {} attachments ({} compressed, {} uncompressed)",
+ OutputPackage.GetAttachments().size(),
+ NiceBytes(TotalAttachmentBytes),
+ NiceBytes(TotalRawAttachmentBytes));
+
return OutputPackage;
}