From 049f51d56a59299bcbf718bf1a55d7e745f2cf57 Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Thu, 20 May 2021 14:05:01 +0200 Subject: WIP structured cache endpoints - tactical check-in not fully functional yet --- zenserver/cache/structuredcache.cpp | 47 ++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) (limited to 'zenserver/cache/structuredcache.cpp') diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp index 0d62f297c..e90f838da 100644 --- a/zenserver/cache/structuredcache.cpp +++ b/zenserver/cache/structuredcache.cpp @@ -4,6 +4,7 @@ #include #include +#include #include "cachestore.h" #include "structuredcache.h" @@ -14,11 +15,19 @@ namespace zen { +using namespace std::literals; + HttpStructuredCacheService::HttpStructuredCacheService(std::filesystem::path RootPath, zen::CasStore& InStore) : m_CasStore(InStore) , m_CacheStore(InStore, RootPath) { spdlog::info("initializing structured cache at '{}'", RootPath); + + 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 */); } HttpStructuredCacheService::~HttpStructuredCacheService() @@ -78,9 +87,45 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request) CacheValue Value; Value.Value = Body; + HttpContentType ContentType = Request.RequestContentType(); + + switch (ContentType) + { + case HttpContentType::kUnknownContentType: + case HttpContentType::kBinary: + Value.IsCompactBinary = false; + break; + + case HttpContentType::kCbObject: + Value.IsCompactBinary = true; + break; + + default: + return Request.WriteResponse(zen::HttpResponse::BadRequest); + } + m_CacheStore.Put(Ref.BucketSegment, Ref.HashKey, Value); - Request.WriteResponse(zen::HttpResponse::Created); + // This is currently synchronous for simplicity and debuggability but should be + // made asynchronous + + if (m_Cloud) + { + CloudCacheSession Session(m_Cloud); + + zen::Stopwatch Timer; + + if (Session.Put(Ref.BucketSegment, Ref.HashKey)) + { + spdlog::debug("upstream PUT succeeded after {:5}! {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), Ref.HashKey); + } + else + { + spdlog::debug("upstream PUT failed after {:5}! {}", zen::NiceTimeSpanMs(Timer.getElapsedTimeMs()), Ref.HashKey); + } + } + + return Request.WriteResponse(zen::HttpResponse::Created); } else { -- cgit v1.2.3