aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-09-28 15:08:37 +0200
committerPer Larsson <[email protected]>2021-09-28 15:08:37 +0200
commit8727cffdf192b176a43e52141a86ab0a9b8d3983 (patch)
tree99153a29b11525df32875d9d8dc29bf3ff53040c /zenserver/cache/structuredcache.cpp
parentCompact binary to JSON (#12) (diff)
downloadzen-8727cffdf192b176a43e52141a86ab0a9b8d3983.tar.xz
zen-8727cffdf192b176a43e52141a86ab0a9b8d3983.zip
Removed using the bucket name to detect binary cache records and store content type in cache.
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp80
1 files changed, 50 insertions, 30 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index 3ac1ec37f..5225d3ebb 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -290,9 +290,7 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
if (QueryUpstream)
{
- const ZenContentType CacheRecordType = Ref.BucketSegment == "legacy"sv ? ZenContentType::kBinary
- : AcceptType == ZenContentType::kCbPackage ? ZenContentType::kCbPackage
- : ZenContentType::kCbObject;
+ const ZenContentType CacheRecordType = AcceptType;
if (auto UpstreamResult = m_UpstreamCache->GetCacheRecord({Ref.BucketSegment, Ref.HashKey}, CacheRecordType);
UpstreamResult.Success)
@@ -321,9 +319,10 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
else
{
Success = false;
- ZEN_WARN("Get - cache record '{}/{}' FAILED, invalid compact binary object from upstream",
+ ZEN_WARN("Get - '{}/{}' '{}' FAILED, invalid compact binary object from upstream",
Ref.BucketSegment,
- Ref.HashKey);
+ Ref.HashKey,
+ ToString(AcceptType));
}
}
@@ -353,9 +352,10 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
}
else
{
- ZEN_WARN("GET - cache record '{}/{}' FAILED, upstream attachment not compressed",
+ ZEN_WARN("Get - '{}/{}' '{}' FAILED, upstream attachment not compressed",
Ref.BucketSegment,
- Ref.HashKey);
+ Ref.HashKey,
+ ToString(ZenContentType::kCbPackage));
}
}
AttachmentCount++;
@@ -380,15 +380,16 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
else
{
Success = false;
- ZEN_WARN("GET - cache record '{}/{}' FAILED, attachments missing in upstream package",
+ ZEN_WARN("Get - '{}/{}' '{}' FAILED, attachments missing in upstream package",
Ref.BucketSegment,
- Ref.HashKey);
+ Ref.HashKey,
+ ToString(AcceptType));
}
}
else
{
Success = false;
- ZEN_WARN("GET - cache record '{}/{}' FAILED, invalid upstream package", Ref.BucketSegment, Ref.HashKey);
+ ZEN_WARN("Get - '{}/{}' '{}' FAILED, invalid upstream package", Ref.BucketSegment, Ref.HashKey, ToString(AcceptType));
}
}
}
@@ -396,8 +397,7 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
if (!Success)
{
- ZEN_DEBUG("MISS - '{}/{}'", Ref.BucketSegment, Ref.HashKey);
-
+ ZEN_DEBUG("MISS - '{}/{}' '{}'", Ref.BucketSegment, Ref.HashKey, ToString(AcceptType));
return Request.WriteResponse(HttpResponseCode::NotFound);
}
@@ -409,7 +409,7 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
if (ValidationResult != CbValidateError::None)
{
- ZEN_WARN("GET - cache record '{}/{}' FAILED, invalid compact binary object", Ref.BucketSegment, Ref.HashKey);
+ ZEN_WARN("GET - '{}/{}' '{}' FAILED, invalid compact binary object", Ref.BucketSegment, Ref.HashKey, ToString(AcceptType));
return Request.WriteResponse(HttpResponseCode::NotFound, HttpContentType::kText, "Invalid cache record"sv);
}
@@ -435,9 +435,10 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
if (ValidCount != AttachmentCount)
{
- ZEN_WARN("GET - cache record '{}/{}' FAILED, found '{}' of '{}' attachments",
+ ZEN_WARN("GET - '{}/{}' '{}' FAILED, found '{}' of '{}' attachments",
Ref.BucketSegment,
Ref.HashKey,
+ ToString(AcceptType),
ValidCount,
AttachmentCount);
@@ -447,10 +448,11 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
Package.SetObject(LoadCompactBinaryObject(Value.Value));
- ZEN_DEBUG("HIT - '{}/{}' {}, {} attachments (LOCAL)",
+ ZEN_DEBUG("HIT - '{}/{}' {} '{}', {} attachments (LOCAL)",
Ref.BucketSegment,
Ref.HashKey,
NiceBytes(AttachmentBytes + Value.Value.Size()),
+ ToString(HttpContentType::kCbPackage),
AttachmentCount);
MemoryOutStream MemStream;
@@ -463,10 +465,11 @@ HttpStructuredCacheService::HandleGetCacheRecord(zen::HttpServerRequest& Request
}
else
{
- ZEN_DEBUG("HIT - '{}/{}' {} ({})",
+ ZEN_DEBUG("HIT - '{}/{}' {} '{}' ({})",
Ref.BucketSegment,
Ref.HashKey,
NiceBytes(Value.Value.Size()),
+ ToString(Value.Value.GetContentType()),
InUpstreamCache ? "UPSTREAM" : "LOCAL");
Request.WriteResponse(HttpResponseCode::OK, Value.Value.GetContentType(), Value.Value);
@@ -486,10 +489,12 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
const HttpContentType ContentType = Request.RequestContentType();
const bool StoreUpstream = m_UpstreamCache && (CachePolicy::StoreRemote == (Policy & CachePolicy::StoreRemote));
- if (ContentType == HttpContentType::kBinary || ContentType == HttpContentType::kUnknownContentType)
+ Body.SetContentType(ContentType);
+
+ if (ContentType == HttpContentType::kBinary)
{
+ ZEN_DEBUG("PUT - '{}/{}' {} '{}'", Ref.BucketSegment, Ref.HashKey, NiceBytes(Body.Size()), ToString(ContentType));
m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, {.Value = Body});
- ZEN_DEBUG("PUT - binary '{}/{}' {}", Ref.BucketSegment, Ref.HashKey, NiceBytes(Body.Size()));
if (StoreUpstream)
{
@@ -505,7 +510,7 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
if (ValidationResult != CbValidateError::None)
{
- ZEN_WARN("PUT - cache record '{}/{}' ({} bytes) FAILED, invalid compact binary", Ref.BucketSegment, Ref.HashKey, Body.Size());
+ ZEN_WARN("PUT - '{}/{}' '{}' FAILED, invalid compact binary", Ref.BucketSegment, Ref.HashKey, ToString(ContentType));
return Request.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Compact binary validation failed"sv);
}
@@ -527,7 +532,13 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
if (ValidCacheRecord)
{
- ZEN_DEBUG("PUT - cache record '{}/{}' {}, {} attachments", Ref.BucketSegment, Ref.HashKey, NiceBytes(Body.Size()), ValidCount);
+ ZEN_DEBUG("PUT - '{}/{}' {} '{}', {} attachments",
+ Ref.BucketSegment,
+ Ref.HashKey,
+ NiceBytes(Body.Size()),
+ ToString(ContentType),
+ ValidCount);
+
m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, {.Value = Body});
if (StoreUpstream)
@@ -542,9 +553,10 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
}
else
{
- ZEN_WARN("PUT - cache record '{}/{}' FAILED, found {}/{} attachments",
+ ZEN_WARN("PUT - '{}/{}' '{}' FAILED, found {}/{} attachments",
Ref.BucketSegment,
Ref.HashKey,
+ ToString(ContentType),
ValidCount,
AttachmentCount);
@@ -557,7 +569,7 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
if (!Package.TryLoad(Body))
{
- ZEN_WARN("PUT - cache record '{}/{}' FAILED, invalid package", Ref.BucketSegment, Ref.HashKey);
+ ZEN_WARN("PUT - '{}/{}' '{}' FAILED, invalid package", Ref.BucketSegment, Ref.HashKey, ToString(ContentType));
return Request.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Invalid package"sv);
}
@@ -586,17 +598,19 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
}
else
{
- ZEN_WARN("PUT - cache record '{}/{}' FAILED, attachment '{}' is not compressed",
+ ZEN_WARN("PUT - '{}/{}' '{}' FAILED, attachment '{}' is not compressed",
Ref.BucketSegment,
Ref.HashKey,
+ ToString(HttpContentType::kCbPackage),
AttachmentHash.AsHash());
}
}
else
{
- ZEN_WARN("PUT - cache record '{}/{}' FAILED, missing attachment '{}'",
+ ZEN_WARN("PUT - '{}/{}' '{}' FAILED, missing attachment '{}'",
Ref.BucketSegment,
Ref.HashKey,
+ ToString(HttpContentType::kCbPackage),
AttachmentHash.AsHash());
}
});
@@ -608,13 +622,17 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
return Request.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Invalid attachments"sv);
}
- ZEN_DEBUG("PUT - cache record '{}/{}' {}, {}/{} new attachments",
+ ZEN_DEBUG("PUT - '{}/{}' {} '{}', {}/{} new attachments",
Ref.BucketSegment,
Ref.HashKey,
NiceBytes(Body.GetSize()),
+ ToString(ContentType),
NewAttachmentCount,
Attachments.size());
+ IoBuffer CacheRecordValue = CacheRecord.GetBuffer().AsIoBuffer();
+ CacheRecordValue.SetContentType(ZenContentType::kCbObject);
+
m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, {.Value = CacheRecord.GetBuffer().AsIoBuffer()});
if (StoreUpstream)
@@ -629,7 +647,7 @@ HttpStructuredCacheService::HandlePutCacheRecord(zen::HttpServerRequest& Request
}
else
{
- Request.WriteResponse(HttpResponseCode::BadRequest);
+ return Request.WriteResponse(HttpResponseCode::BadRequest, HttpContentType::kText, "Content-Type invalid"sv);
}
}
@@ -692,12 +710,12 @@ HttpStructuredCacheService::HandleGetCachePayload(zen::HttpServerRequest& Reques
return Request.WriteResponse(HttpResponseCode::NotFound);
}
- ZEN_DEBUG("HIT - '{}/{}/{}' {} (type: {}) ({})",
+ ZEN_DEBUG("HIT - '{}/{}/{}' {} '{}' ({})",
Ref.BucketSegment,
Ref.HashKey,
Ref.PayloadId,
NiceBytes(Payload.Size()),
- Payload.GetContentType(),
+ ToString(Payload.GetContentType()),
InUpstreamCache ? "UPSTREAM" : "LOCAL");
Request.WriteResponse(HttpResponseCode::OK, HttpContentType::kBinary, Payload);
@@ -716,6 +734,8 @@ HttpStructuredCacheService::HandlePutCachePayload(zen::HttpServerRequest& Reques
return Request.WriteResponse(HttpResponseCode::BadRequest);
}
+ Body.SetContentType(Request.RequestContentType());
+
IoHash ChunkHash = IoHash::HashBuffer(Body);
CompressedBuffer Compressed = CompressedBuffer::FromCompressed(SharedBuffer(Body));
@@ -733,12 +753,12 @@ HttpStructuredCacheService::HandlePutCachePayload(zen::HttpServerRequest& Reques
m_CidStore.AddCompressedCid(Ref.PayloadId, ChunkHash);
- ZEN_DEBUG("PUT - payload '{}/{}/{}' {} (type: {}) {}",
+ ZEN_DEBUG("PUT - '{}/{}/{}' {} '{}' ({})",
Ref.BucketSegment,
Ref.HashKey,
Ref.PayloadId,
NiceBytes(Body.Size()),
- Body.GetContentType(),
+ ToString(Body.GetContentType()),
Result.New ? "NEW" : "OLD");
const HttpResponseCode ResponseCode = Result.New ? HttpResponseCode::Created : HttpResponseCode::OK;