aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2021-08-17 22:14:28 +0200
committerStefan Boberg <[email protected]>2021-08-17 22:14:28 +0200
commit5bbca1c180bd40544ba0fee3d699202e81aa9da1 (patch)
treee5bc14180fe1e2e1c637032b371bc8cc30fc5afc
parentImplemented support for dropping z$ buckets while online (diff)
downloadzen-5bbca1c180bd40544ba0fee3d699202e81aa9da1.tar.xz
zen-5bbca1c180bd40544ba0fee3d699202e81aa9da1.zip
added 'zen drop' command to drop cache buckets online
also cleaned up the server side implementation a bit
-rw-r--r--zen/cmds/cache.cpp66
-rw-r--r--zen/cmds/cache.h21
-rw-r--r--zen/zen.cpp3
-rw-r--r--zen/zen.vcxproj2
-rw-r--r--zen/zen.vcxproj.filters2
-rw-r--r--zenserver/cache/structuredcache.cpp12
-rw-r--r--zenserver/cache/structuredcache.h2
7 files changed, 104 insertions, 4 deletions
diff --git a/zen/cmds/cache.cpp b/zen/cmds/cache.cpp
new file mode 100644
index 000000000..9a2591ded
--- /dev/null
+++ b/zen/cmds/cache.cpp
@@ -0,0 +1,66 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "cache.h"
+
+#include <zencore/filesystem.h>
+#include <zenserverprocess.h>
+
+#include <spdlog/spdlog.h>
+#include <memory>
+
+// cpr ////////////////////////////////////////////////////////////////////
+//
+// For some reason, these don't seem to stick, so we disable the warnings
+//# define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING 1
+//# define _SILENCE_ALL_CXX17_DEPRECATION_WARNINGS 1
+#pragma warning(push)
+#pragma warning(disable : 4004)
+#pragma warning(disable : 4996)
+#include <cpr/cpr.h>
+#pragma warning(pop)
+
+using namespace fmt::literals;
+
+DropCommand::DropCommand()
+{
+ m_Options.add_options()("h,help", "Print help");
+ m_Options.add_option("", "b", "bucket", "Bucket name", cxxopts::value(m_BucketName), "<bucketname>");
+ m_Options.add_option("", "", "positional", "Positional arguments", cxxopts::value(m_Positional), "");
+}
+
+DropCommand::~DropCommand() = default;
+
+int
+DropCommand::Run(const ZenCliOptions& GlobalOptions, int argc, char** argv)
+{
+ ZEN_UNUSED(GlobalOptions, argc, argv);
+
+ m_Options.parse_positional({"bucket", "positional"});
+ m_Options.parse(argc, argv);
+
+ spdlog::info("Dropping cache bucket '{}' from '{}'", m_BucketName, m_HostName);
+
+ cpr::Session Session;
+ Session.SetUrl({"{}/z$/{}"_format(m_HostName, m_BucketName)});
+ cpr::Response Result = Session.Delete();
+
+ if (Result.status_code >= 200 && Result.status_code < 300)
+ {
+ spdlog::info("OK: dropped cache bucket '{}' from '{}'", m_BucketName, m_HostName);
+
+ return 0;
+ }
+
+ if (Result.status_code)
+ {
+ spdlog::error("Drop failed: {}: {} ({})", Result.status_code, Result.reason, Result.text);
+ }
+ else
+ {
+ spdlog::error("Drop failed: {}", Result.error.message);
+ }
+
+ return 1;
+}
diff --git a/zen/cmds/cache.h b/zen/cmds/cache.h
new file mode 100644
index 000000000..7e37ce914
--- /dev/null
+++ b/zen/cmds/cache.h
@@ -0,0 +1,21 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include "../zen.h"
+
+class DropCommand : public ZenCmdBase
+{
+public:
+ DropCommand();
+ ~DropCommand();
+
+ virtual int Run(const ZenCliOptions& GlobalOptions, int argc, char** argv) override;
+ virtual cxxopts::Options* Options() override { return &m_Options; }
+
+private:
+ cxxopts::Options m_Options{"drop", "Drop one or more cache buckets"};
+ std::vector<std::string> m_Positional;
+ std::string m_BucketName;
+ std::string m_HostName{"http://localhost:1337"};
+};
diff --git a/zen/zen.cpp b/zen/zen.cpp
index 9e3095367..67ff50105 100644
--- a/zen/zen.cpp
+++ b/zen/zen.cpp
@@ -8,6 +8,7 @@
#include "zen.h"
#include "chunk/chunk.h"
+#include "cmds/cache.h"
#include "cmds/copy.h"
#include "cmds/dedup.h"
#include "cmds/deploy.h"
@@ -122,6 +123,7 @@ main(int argc, char** argv)
CopyCommand CopyCmd;
DedupCommand DedupCmd;
DeployCommand DeployCmd;
+ DropCommand DropCmd;
ChunkCommand ChunkCmd;
RunTestsCommand RunTestsCmd;
RunCommand RunCmd;
@@ -141,6 +143,7 @@ main(int argc, char** argv)
{"copy", &CopyCmd, "Copy file(s)"},
{"deploy", &DeployCmd, "Deploy data"},
{"dedup", &DedupCmd, "Dedup files"},
+ {"drop", &DropCmd, "Drop cache bucket(s)"},
{"hash", &HashCmd, "Compute file hashes"},
{"runtests", &RunTestsCmd, "Run zen tests"},
{"run", &RunCmd, "Remote execution"},
diff --git a/zen/zen.vcxproj b/zen/zen.vcxproj
index 78f978ba5..cbf769835 100644
--- a/zen/zen.vcxproj
+++ b/zen/zen.vcxproj
@@ -96,6 +96,7 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="chunk\chunk.cpp" />
+ <ClCompile Include="cmds\cache.cpp" />
<ClCompile Include="cmds\copy.cpp" />
<ClCompile Include="cmds\dedup.cpp" />
<ClCompile Include="cmds\deploy.cpp" />
@@ -109,6 +110,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="chunk\chunk.h" />
+ <ClInclude Include="cmds\cache.h" />
<ClInclude Include="cmds\copy.h" />
<ClInclude Include="cmds\dedup.h" />
<ClInclude Include="cmds\deploy.h" />
diff --git a/zen/zen.vcxproj.filters b/zen/zen.vcxproj.filters
index 17c9da9c1..47b321727 100644
--- a/zen/zen.vcxproj.filters
+++ b/zen/zen.vcxproj.filters
@@ -26,6 +26,7 @@
<Filter>cmds</Filter>
</ClCompile>
<ClCompile Include="cmds\up.cpp" />
+ <ClCompile Include="cmds\cache.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="chunk\chunk.h" />
@@ -53,6 +54,7 @@
<Filter>cmds</Filter>
</ClInclude>
<ClInclude Include="cmds\up.h" />
+ <ClInclude Include="cmds\cache.h" />
</ItemGroup>
<ItemGroup>
<Filter Include="cmds">
diff --git a/zenserver/cache/structuredcache.cpp b/zenserver/cache/structuredcache.cpp
index f744ae131..def1adb90 100644
--- a/zenserver/cache/structuredcache.cpp
+++ b/zenserver/cache/structuredcache.cpp
@@ -92,7 +92,7 @@ HttpStructuredCacheService::HandleRequest(zen::HttpServerRequest& Request)
{
CacheRef Ref;
- if (!ValidateUri(Request, /* out */ Ref))
+ if (!ValidateKeyUri(Request, /* out */ Ref))
{
std::string_view Key = Request.RelativeUri();
@@ -129,14 +129,20 @@ HttpStructuredCacheService::HandleCacheBucketRequest(zen::HttpServerRequest& Req
case kHead:
case kGet:
{
+ // Query stats
}
break;
+
case kDelete:
// Drop bucket
if (m_CacheStore.DropBucket(Bucket))
{
- return Request.WriteResponse(zen::HttpResponse::OK); // invalid URL
+ return Request.WriteResponse(zen::HttpResponse::OK);
+ }
+ else
+ {
+ return Request.WriteResponse(zen::HttpResponse::NotFound);
}
break;
}
@@ -496,7 +502,7 @@ HttpStructuredCacheService::HandleCachePayloadRequest(zen::HttpServerRequest& Re
}
bool
-HttpStructuredCacheService::ValidateUri(zen::HttpServerRequest& Request, CacheRef& OutRef)
+HttpStructuredCacheService::ValidateKeyUri(zen::HttpServerRequest& Request, CacheRef& OutRef)
{
std::string_view Key = Request.RelativeUri();
std::string_view::size_type BucketSplitOffset = Key.find_first_of('/');
diff --git a/zenserver/cache/structuredcache.h b/zenserver/cache/structuredcache.h
index e9796999b..73b0825dc 100644
--- a/zenserver/cache/structuredcache.h
+++ b/zenserver/cache/structuredcache.h
@@ -64,7 +64,7 @@ private:
IoHash PayloadId;
};
- [[nodiscard]] bool ValidateUri(zen::HttpServerRequest& Request, CacheRef& OutRef);
+ [[nodiscard]] bool ValidateKeyUri(zen::HttpServerRequest& Request, CacheRef& OutRef);
void HandleCacheRecordRequest(zen::HttpServerRequest& Request, CacheRef& Ref);
void HandleCachePayloadRequest(zen::HttpServerRequest& Request, CacheRef& Ref);
void HandleCacheBucketRequest(zen::HttpServerRequest& Request, std::string_view Bucket);