From 397067ff20be5d1441cc1d8103913484e15da0ca Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 16 Sep 2021 14:05:02 +0200 Subject: Fixed marshaling of outputs including sanity checks, logging --- zenserver/compute/apply.cpp | 22 ++++++++++++++++++++-- zenserver/compute/apply.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/zenserver/compute/apply.cpp b/zenserver/compute/apply.cpp index 2c3243655..e40c6918d 100644 --- a/zenserver/compute/apply.cpp +++ b/zenserver/compute/apply.cpp @@ -806,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) { @@ -819,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; } diff --git a/zenserver/compute/apply.h b/zenserver/compute/apply.h index 474156a5e..86b262213 100644 --- a/zenserver/compute/apply.h +++ b/zenserver/compute/apply.h @@ -28,6 +28,7 @@ public: virtual void HandleRequest(HttpServerRequest& Request) override; private: + spdlog::logger& Log() { return m_Log; } spdlog::logger& m_Log; HttpRequestRouter m_Router; CasStore& m_CasStore; -- cgit v1.2.3