aboutsummaryrefslogtreecommitdiff
path: root/zenserver
diff options
context:
space:
mode:
authorPer Larsson <[email protected]>2021-12-05 16:03:27 +0100
committerPer Larsson <[email protected]>2021-12-05 16:03:27 +0100
commit9eb0876ab1f35317eb04dd8a74f0394e853f4f56 (patch)
tree1dfd11024baea97b01c69b40153086511987f361 /zenserver
parentMerge branch 'gc' of https://github.com/EpicGames/zen into gc (diff)
downloadzen-9eb0876ab1f35317eb04dd8a74f0394e853f4f56.tar.xz
zen-9eb0876ab1f35317eb04dd8a74f0394e853f4f56.zip
Added simple GC interval scheduling.
Diffstat (limited to 'zenserver')
-rw-r--r--zenserver/config.cpp13
-rw-r--r--zenserver/config.h25
-rw-r--r--zenserver/zenserver.cpp27
3 files changed, 56 insertions, 9 deletions
diff --git a/zenserver/config.cpp b/zenserver/config.cpp
index 1e847ce3d..49240d176 100644
--- a/zenserver/config.cpp
+++ b/zenserver/config.cpp
@@ -270,6 +270,19 @@ ParseCliOptions(int argc, char* argv[], ZenServerOptions& ServerOptions)
cxxopts::value<int32_t>(ServerOptions.UpstreamCacheConfig.TimeoutMilliseconds)->default_value("0"),
"");
+ options.add_option("gc",
+ "",
+ "gc-enabled",
+ "Whether garbage collection is enabled or not.",
+ cxxopts::value<bool>(ServerOptions.GcConfig.Enabled)->default_value("true"),
+ "");
+
+ options.add_option("gc",
+ "",
+ "gc-interval-seconds",
+ "Garbage collection interval. Default is 1h.",
+ cxxopts::value<int32_t>(ServerOptions.GcConfig.IntervalSeconds)->default_value("3600"),
+ "");
try
{
auto result = options.parse(argc, argv);
diff --git a/zenserver/config.h b/zenserver/config.h
index 19fba71a3..97f339a0e 100644
--- a/zenserver/config.h
+++ b/zenserver/config.h
@@ -55,9 +55,34 @@ struct ZenUpstreamCacheConfig
bool StatsEnabled = false;
};
+struct ZenCacheEvictionPolicy
+{
+ bool Enabled = true;
+ uint64_t DiskSizeLimit = ~uint64_t(0);
+ uint64_t MemorySizeLimit = 1024 * 1024 * 1024;
+};
+
+struct ZenCasEvictionPolicy
+{
+ bool Enabled = true;
+ bool ContainerGcEnabled = true;
+ uint64_t LargeStrategySizeLimit = ~uint64_t(0);
+ uint64_t SmallStrategySizeLimit = ~uint64_t(0);
+ uint64_t TinyStrategySizeLimit = ~uint64_t(0);
+};
+
+struct ZenGcConfig
+{
+ ZenCasEvictionPolicy Cas;
+ ZenCacheEvictionPolicy Cache;
+ int32_t IntervalSeconds = 60 * 60;
+ bool Enabled = true;
+};
+
struct ZenServerOptions
{
ZenUpstreamCacheConfig UpstreamCacheConfig;
+ ZenGcConfig GcConfig;
std::filesystem::path DataDir; // Root directory for state (used for testing)
std::filesystem::path ContentDir; // Root directory for serving frontend content (experimental)
std::filesystem::path AbsLogFile; // Absolute path to main log file
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index 47c79526b..5b5cfb3b7 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -198,15 +198,15 @@ public:
m_AdminService.RegisterGcHandler({.Trigger =
[this]() {
CbObjectWriter Writer;
- const bool Started = m_Gc.Trigger();
+ const bool Started = m_GcScheduler.ScheduleNow();
Writer << "Status"sv << (Started ? "Started"sv : "Running"sv);
return Writer.Save();
},
.Status =
[this]() {
- CbObjectWriter Writer;
- const GcStatus Status = m_Gc.Status();
- Writer << "Status"sv << (GcStatus::kIdle == Status ? "Idle"sv : "Running"sv);
+ CbObjectWriter Writer;
+ const GcSchedulerStatus Status = m_GcScheduler.Status();
+ Writer << "Status"sv << (GcSchedulerStatus::kIdle == Status ? "Idle"sv : "Running"sv);
return Writer.Save();
}});
@@ -229,11 +229,11 @@ public:
m_CasStore->Initialize(Config);
m_CidStore = std::make_unique<zen::CidStore>(*m_CasStore, m_DataRoot / "cid");
- m_Gc.Cas().SetCidStore(m_CidStore.get());
+ m_CasGc.SetCidStore(m_CidStore.get());
ZEN_INFO("instantiating project service");
- m_ProjectStore = new zen::ProjectStore(*m_CidStore, m_DataRoot / "projects", m_Gc.Cas());
+ m_ProjectStore = new zen::ProjectStore(*m_CidStore, m_DataRoot / "projects", m_CasGc);
m_HttpProjectService.reset(new zen::HttpProjectService{*m_CidStore, m_ProjectStore});
#if ZEN_USE_NAMED_PIPES
@@ -306,6 +306,14 @@ public:
{
m_Http->RegisterService(*m_FrontendService);
}
+
+ ZEN_INFO("initializing GC, enabled '{}', interval {}s", ServerOptions.GcConfig.Enabled, ServerOptions.GcConfig.IntervalSeconds);
+ zen::GcSchedulerConfig GcConfig{
+ .RootDirectory = m_DataRoot / "gc",
+ .Interval = std::chrono::seconds(ServerOptions.GcConfig.IntervalSeconds),
+ .Enabled = ServerOptions.GcConfig.Enabled,
+ };
+ m_GcScheduler.Initialize(GcConfig);
}
void InitializeState(const ZenServerOptions& ServerOptions);
@@ -518,8 +526,9 @@ private:
zen::Ref<zen::HttpServer> m_Http;
zen::HttpStatusService m_StatusService;
zen::HttpStatsService m_StatsService;
- zen::Gc m_Gc;
- std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore(m_Gc.Cas())};
+ zen::CasGc m_CasGc;
+ zen::GcScheduler m_GcScheduler{m_CasGc};
+ std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore(m_CasGc)};
std::unique_ptr<zen::CidStore> m_CidStore;
std::unique_ptr<zen::ZenCacheStore> m_CacheStore;
zen::CasScrubber m_Scrubber{*m_CasStore};
@@ -661,7 +670,7 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
auto ValueOrDefault = [](std::string_view Value, std::string_view Default) { return Value.empty() ? Default : Value; };
ZEN_INFO("instantiating structured cache service");
- m_CacheStore = std::make_unique<ZenCacheStore>(m_Gc.Cas(), m_DataRoot / "cache");
+ m_CacheStore = std::make_unique<ZenCacheStore>(m_CasGc, m_DataRoot / "cache");
std::unique_ptr<zen::UpstreamCache> UpstreamCache;
if (ServerOptions.UpstreamCacheConfig.CachePolicy != UpstreamCachePolicy::Disabled)