aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cidstore.cpp
diff options
context:
space:
mode:
authorDan Engelbrecht <[email protected]>2022-12-07 11:21:41 +0100
committerGitHub <[email protected]>2022-12-07 02:21:41 -0800
commit100c8f966b1c5b2fb190748f0177600562d1c5fe (patch)
treefc85e350dea47330149a1d42eb7a6c7ae0a06111 /zenserver/cidstore.cpp
parentCache request record/replay (#198) (diff)
downloadzen-100c8f966b1c5b2fb190748f0177600562d1c5fe.tar.xz
zen-100c8f966b1c5b2fb190748f0177600562d1c5fe.zip
optimizations (#200)
* Use direct file read and direct buffer allocation for small IoBuffer materalization * Reduce range of materialized data in CompositeBuffer reading CompressedBuffer header reading often only need a small part and not the whole file * reduce lock contention in IoBuffer::Materialize * Reduce parsing of compressed headers Validate header type at decompression * faster CreateDirectories - start from leaf going up and recurse back * optimized BufferHeader::IsValid * Add ValidateCompressedHeader to use when we don't need the actual compressed data Validate that we always get compressed data in CidStore::AddChunk * changelog
Diffstat (limited to 'zenserver/cidstore.cpp')
-rw-r--r--zenserver/cidstore.cpp26
1 files changed, 12 insertions, 14 deletions
diff --git a/zenserver/cidstore.cpp b/zenserver/cidstore.cpp
index 5de347a17..bce4f1dfb 100644
--- a/zenserver/cidstore.cpp
+++ b/zenserver/cidstore.cpp
@@ -39,22 +39,21 @@ HttpCidService::HttpCidService(CidStore& Store) : m_CidStore(Store)
case HttpVerb::kPut:
{
- IoBuffer Payload = ServerRequest.ReadPayload();
- CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Payload));
- if (!Compressed)
+ IoBuffer Payload = ServerRequest.ReadPayload();
+ IoHash RawHash;
+ uint64_t RawSize;
+ if (!CompressedBuffer::ValidateCompressedHeader(Payload, RawHash, RawSize))
{
return ServerRequest.WriteResponse(HttpResponseCode::UnsupportedMediaType);
}
- IoHash PayloadHash = IoHash::FromBLAKE3(Compressed.GetRawHash());
-
// URI hash must match content hash
- if (PayloadHash != Hash)
+ if (RawHash != Hash)
{
return ServerRequest.WriteResponse(HttpResponseCode::BadRequest);
}
- m_CidStore.AddChunk(Compressed);
+ m_CidStore.AddChunk(Payload, RawHash);
return ServerRequest.WriteResponse(HttpResponseCode::OK);
}
@@ -85,18 +84,17 @@ HttpCidService::HandleRequest(zen::HttpServerRequest& Request)
case HttpVerb::kPut:
case HttpVerb::kPost:
{
- IoBuffer Payload = Request.ReadPayload();
- CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Payload));
- if (!Compressed)
+ IoBuffer Payload = Request.ReadPayload();
+ IoHash RawHash;
+ uint64_t RawSize;
+ if (!CompressedBuffer::ValidateCompressedHeader(Payload, RawHash, RawSize))
{
return Request.WriteResponse(HttpResponseCode::UnsupportedMediaType);
}
- IoHash PayloadHash = IoHash::FromBLAKE3(Compressed.GetRawHash());
-
- ZEN_DEBUG("CID POST request for {} ({} bytes)", PayloadHash, Payload.Size());
+ ZEN_DEBUG("CID POST request for {} ({} bytes)", RawHash, Payload.Size());
- auto InsertResult = m_CidStore.AddChunk(Compressed);
+ auto InsertResult = m_CidStore.AddChunk(Payload, RawHash);
if (InsertResult.New)
{