aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-05-20 14:05:01 +0200
committerStefan Boberg <[email protected]>2021-05-20 14:05:01 +0200
commit049f51d56a59299bcbf718bf1a55d7e745f2cf57 (patch)
tree575745847cd542dde5e826da77796da2ebd8e85c
parentAdded tentative Jupiter structured data endpoints (diff)
downloadzen-049f51d56a59299bcbf718bf1a55d7e745f2cf57.tar.xz
zen-049f51d56a59299bcbf718bf1a55d7e745f2cf57.zip
WIP structured cache endpoints - tactical check-in not fully functional yet
-rw-r--r--zenserver/cache/cachestore.cpp5
-rw-r--r--zenserver/cache/cachestore.h2
-rw-r--r--zenserver/cache/kvcache.cpp2
-rw-r--r--zenserver/cache/structuredcache.cpp47
-rw-r--r--zenserver/cache/structuredcache.h15
5 files changed, 67 insertions, 4 deletions
diff --git a/zenserver/cache/cachestore.cpp b/zenserver/cache/cachestore.cpp
index 5b0358994..87c89c6a8 100644
--- a/zenserver/cache/cachestore.cpp
+++ b/zenserver/cache/cachestore.cpp
@@ -1237,3 +1237,8 @@ ZenCacheTracker::TrackAccess(std::string_view Bucket, const zen::IoHash& HashKey
ZEN_UNUSED(Bucket);
ZEN_UNUSED(HashKey);
}
+
+void
+ZenCacheTracker::Flush()
+{
+}
diff --git a/zenserver/cache/cachestore.h b/zenserver/cache/cachestore.h
index 1ac01279b..61a8061be 100644
--- a/zenserver/cache/cachestore.h
+++ b/zenserver/cache/cachestore.h
@@ -21,6 +21,7 @@ class CasStore;
struct CacheValue
{
zen::IoBuffer Value;
+ bool IsCompactBinary = false;
};
/******************************************************************************
@@ -170,6 +171,7 @@ public:
~ZenCacheTracker();
void TrackAccess(std::string_view Bucket, const zen::IoHash& HashKey);
+ void Flush();
private:
};
diff --git a/zenserver/cache/kvcache.cpp b/zenserver/cache/kvcache.cpp
index 404b17e5a..4c3b1e33d 100644
--- a/zenserver/cache/kvcache.cpp
+++ b/zenserver/cache/kvcache.cpp
@@ -109,7 +109,7 @@ HttpKvCacheService::HandleRequest(zen::HttpServerRequest& Request)
if (!Success)
{
- // Success = m_cache_.Get(Key, Value);
+ Success = m_cache_.Get(Key, Value);
if (!Success)
{
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 <zencore/fmtutils.h>
#include <zencore/httpserver.h>
+#include <zencore/timer.h>
#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
{
diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h
index d0646e6e9..48b56128f 100644
--- a/zenserver/cache/structuredcache.h
+++ b/zenserver/cache/structuredcache.h
@@ -3,15 +3,25 @@
#pragma once
#include <zencore/httpserver.h>
+#include <zencore/refcount.h>
#include "cachestore.h"
#include "upstream/jupiter.h"
namespace zen {
+class CloudCacheClient;
+
/**
* New-style cache service. Imposes constraints on keys, supports blobs and
* structured values
+ *
+ * The storage strategy is as follows:
+ *
+ * -
+ *
+ * -
+ *
*/
class HttpStructuredCacheService : public zen::HttpService
@@ -33,8 +43,9 @@ private:
[[nodiscard]] bool ValidateUri(zen::HttpServerRequest& Request, CacheRef& OutRef);
- zen::CasStore& m_CasStore;
- ZenCacheStore m_CacheStore;
+ zen::CasStore& m_CasStore;
+ ZenCacheStore m_CacheStore;
+ RefPtr<CloudCacheClient> m_Cloud;
};
} // namespace zen