aboutsummaryrefslogtreecommitdiff
path: root/zenserver/cache/structuredcache.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-21 20:41:34 +0200
committerStefan Boberg <[email protected]>2021-05-21 20:41:34 +0200
commit78dbac2648bbfe2a3687f37e06a3ed32241cb809 (patch)
tree5d053c139fb3738a6848c681015ea0d051a40423 /zenserver/cache/structuredcache.cpp
parentstd::min -> zen::Min (diff)
downloadzen-78dbac2648bbfe2a3687f37e06a3ed32241cb809.tar.xz
zen-78dbac2648bbfe2a3687f37e06a3ed32241cb809.zip
Partial refactoring of structured cache implementation - WIP
Diffstat (limited to 'zenserver/cache/structuredcache.cpp')
-rw-r--r--zenserver/cache/structuredcache.cpp61
1 files changed, 49 insertions, 12 deletions
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index e90f838da..9e771a715 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -23,11 +23,13 @@ HttpStructuredCacheService::HttpStructuredCacheService(std::filesystem::path Roo
{
spdlog::info("initializing structured cache at '{}'", RootPath);
+#if 0
m_Cloud = new CloudCacheClient("https://jupiter.devtools.epicgames.com"sv,
"ue4.ddc"sv /* namespace */,
"https://epicgames.okta.com/oauth2/auso645ojjWVdRI3d0x7/v1/token"sv /* provider */,
"0oao91lrhqPiAlaGD0x7"sv /* client id */,
"-GBWjjenhCgOwhxL5yBKNJECVIoDPH0MK4RDuN7d"sv /* oauth secret */);
+#endif
}
HttpStructuredCacheService::~HttpStructuredCacheService()
@@ -58,8 +60,8 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request)
case kHead:
case kGet:
{
- CacheValue Value;
- bool Success = m_CacheStore.Get(Ref.BucketSegment, Ref.HashKey, /* out */ Value);
+ ZenCacheValue Value;
+ bool Success = m_CacheStore.Get(Ref.BucketSegment, Ref.HashKey, /* out */ Value);
if (!Success)
{
@@ -84,7 +86,7 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request)
{
if (zen::IoBuffer Body = Request.ReadPayload())
{
- CacheValue Value;
+ ZenCacheValue Value;
Value.Value = Body;
HttpContentType ContentType = Request.RequestContentType();
@@ -115,13 +117,21 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request)
zen::Stopwatch Timer;
- if (Session.Put(Ref.BucketSegment, Ref.HashKey))
+ try
{
- spdlog::debug("upstream PUT succeeded after {:5}! {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), Ref.HashKey);
+ Session.Put(Ref.BucketSegment, Ref.HashKey, Value);
+ spdlog::debug("upstream PUT ({}) succeeded after {:5}!",
+ Ref.HashKey,
+ zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()));
}
- else
+ catch (std::exception& e)
{
- spdlog::debug("upstream PUT failed after {:5}! {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), Ref.HashKey);
+ spdlog::debug("upstream PUT ({}) failed after {:5}: '{}'",
+ Ref.HashKey,
+ zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()),
+ e.what());
+
+ throw;
}
}
@@ -146,22 +156,50 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request)
HttpStructuredCacheService::ValidateUri(zen::HttpServerRequest& Request, CacheRef& OutRef)
{
std::string_view Key = Request.RelativeUri();
- std::string_view::size_type BucketSplitOffset = Key.find_last_of('/');
+ std::string_view::size_type BucketSplitOffset = Key.find_first_of('/');
if (BucketSplitOffset == std::string_view::npos)
{
return false;
}
- OutRef.BucketSegment = Key.substr(0, BucketSplitOffset);
- std::string_view HashSegment = Key.substr(BucketSplitOffset + 1);
+ OutRef.BucketSegment = Key.substr(0, BucketSplitOffset);
+
+ std::string_view HashSegment;
+ std::string_view PayloadSegment;
+
+ std::string_view::size_type PayloadSplitOffset = Key.find_last_of('/');
+
+ // We know there is a slash so no need to check for npos return
+
+ if (PayloadSplitOffset == BucketSplitOffset)
+ {
+ // Basic cache record lookup
+ HashSegment = Key.substr(BucketSplitOffset + 1);
+ }
+ else
+ {
+ // Cache record + payload lookup
+ HashSegment = Key.substr(BucketSplitOffset + 1, PayloadSplitOffset - BucketSplitOffset - 1);
+ PayloadSegment = Key.substr(PayloadSplitOffset + 1);
+ }
if (HashSegment.size() != (2 * sizeof OutRef.HashKey.Hash))
{
return false;
}
- bool IsOk = zen::ParseHexBytes(HashSegment.data(), HashSegment.size(), OutRef.HashKey.Hash);
+ if (!PayloadSegment.empty() && PayloadSegment.size() != 24)
+ {
+ OutRef.PayloadId = zen::Oid::FromHexString(PayloadSegment);
+
+ if (!OutRef.PayloadId)
+ {
+ return false;
+ }
+ }
+
+ const bool IsOk = zen::ParseHexBytes(HashSegment.data(), HashSegment.size(), OutRef.HashKey.Hash);
if (!IsOk)
{
@@ -170,5 +208,4 @@ HttpStructuredCacheService::ValidateUri(zen::HttpServerRequest& Request, CacheRe
return true;
}
-
} // namespace zen