diff options
| author | Carl-Magnus Nordin <[email protected]> | 2021-06-02 21:04:20 +0200 |
|---|---|---|
| committer | Carl-Magnus Nordin <[email protected]> | 2021-06-02 21:04:20 +0200 |
| commit | 02c1a005633ce6d2a3465e08cf6555843e4efcd1 (patch) | |
| tree | 8de6bb97121cedafad7fcb9ab5b1bb8818f88a55 /zenserver/projectstore.cpp | |
| parent | clang-format (diff) | |
| download | zen-02c1a005633ce6d2a3465e08cf6555843e4efcd1.tar.xz zen-02c1a005633ce6d2a3465e08cf6555843e4efcd1.zip | |
Added initial implementation of chunk batch API
Diffstat (limited to 'zenserver/projectstore.cpp')
| -rw-r--r-- | zenserver/projectstore.cpp | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/zenserver/projectstore.cpp b/zenserver/projectstore.cpp index 2aac5fe50..32592d7a8 100644 --- a/zenserver/projectstore.cpp +++ b/zenserver/projectstore.cpp @@ -775,8 +775,6 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) const auto& ProjectId = Req.GetCapture(1); const auto& OplogId = Req.GetCapture(2); - m_Log.info("batch - {} / {}", ProjectId, OplogId); - ProjectStore::Oplog* FoundLog = m_ProjectStore->OpenProjectOplog(ProjectId, OplogId); if (FoundLog == nullptr) @@ -817,18 +815,19 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) HttpReq.WriteResponse(HttpResponse::BadRequest); } - RequestHeader Hdr; - Reader.Read(&Hdr, sizeof Hdr); + RequestHeader RequestHdr; + Reader.Read(&RequestHdr, sizeof RequestHdr); - if (Hdr.Magic != RequestHeader::kMagic) + if (RequestHdr.Magic != RequestHeader::kMagic) { HttpReq.WriteResponse(HttpResponse::BadRequest); } - // Make Response + std::vector<RequestChunkEntry> RequestedChunks; + RequestedChunks.resize(RequestHdr.ChunkCount); + Reader.Read(RequestedChunks.data(), sizeof(RequestChunkEntry) * RequestHdr.ChunkCount); - MemoryOutStream MemOut; - BinaryWriter MemWriter(MemOut); + // Make Response struct ResponseHeader { @@ -845,7 +844,55 @@ HttpProjectService::HttpProjectService(CasStore& Store, ProjectStore* Projects) uint64_t ChunkSize; }; - return HttpReq.WriteResponse(HttpResponse::NotFound); + std::vector<IoBuffer> OutBlobs; + OutBlobs.emplace_back(sizeof(ResponseHeader) + RequestHdr.ChunkCount * sizeof(ResponseChunkEntry)); + for (uint32_t ChunkIndex = 0; ChunkIndex < RequestHdr.ChunkCount; ++ChunkIndex) + { + const RequestChunkEntry& RequestedChunk = RequestedChunks[ChunkIndex]; + IoBuffer FoundChunk = FoundLog->FindChunk(RequestedChunk.ChunkId); + if (FoundChunk) + { + if (RequestedChunk.Offset > 0 || RequestedChunk.RequestBytes < uint64_t(-1)) + { + uint64_t Offset = RequestedChunk.Offset; + if (Offset > FoundChunk.Size()) + { + Offset = FoundChunk.Size(); + } + uint64_t Size = RequestedChunk.RequestBytes; + if ((Offset + Size) > FoundChunk.Size()) + { + Size = FoundChunk.Size() - Offset; + } + FoundChunk = IoBuffer(FoundChunk, Offset, Size); + } + } + OutBlobs.emplace_back(std::move(FoundChunk)); + } + uint8_t* ResponsePtr = reinterpret_cast<uint8_t*>(OutBlobs[0].MutableData()); + ResponseHeader ResponseHdr; + ResponseHdr.ChunkCount = RequestHdr.ChunkCount; + memcpy(ResponsePtr, &ResponseHdr, sizeof(ResponseHdr)); + ResponsePtr += sizeof(ResponseHdr); + for (uint32_t ChunkIndex = 0; ChunkIndex < RequestHdr.ChunkCount; ++ChunkIndex) + { + const RequestChunkEntry& RequestedChunk = RequestedChunks[ChunkIndex]; + const IoBuffer& FoundChunk(OutBlobs[ChunkIndex + 1]); + ResponseChunkEntry ResponseChunk; + ResponseChunk.CorrelationId = ChunkIndex; + if (FoundChunk) + { + ResponseChunk.ChunkSize = FoundChunk.Size(); + } + else + { + ResponseChunk.ChunkSize = uint64_t(-1); + } + memcpy(ResponsePtr, &ResponseChunk, sizeof(ResponseChunk)); + ResponsePtr += sizeof(ResponseChunk); + } + + return HttpReq.WriteResponse(HttpResponse::OK, HttpContentType::kBinary, OutBlobs); }, HttpVerb::kPost); |