aboutsummaryrefslogtreecommitdiff
path: root/zenserver/zenserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'zenserver/zenserver.cpp')
-rw-r--r--zenserver/zenserver.cpp93
1 files changed, 59 insertions, 34 deletions
diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp
index c2d2c1d39..49bb3004d 100644
--- a/zenserver/zenserver.cpp
+++ b/zenserver/zenserver.cpp
@@ -47,7 +47,7 @@ ZEN_THIRD_PARTY_INCLUDES_END
# define BUILD_VERSION ("dev-build")
#endif
-#define ZEN_SCHEMA_VERSION 1
+#define ZEN_SCHEMA_VERSION 3 // Canged ZenCache manifest (per larsson)
//////////////////////////////////////////////////////////////////////////
// We don't have any doctest code in this file but this is needed to bring
@@ -218,12 +218,22 @@ public:
m_CasStore->Initialize(Config);
m_CidStore = std::make_unique<zen::CidStore>(*m_CasStore, m_DataRoot / "cid");
+ m_CasGc.SetCidStore(m_CidStore.get());
ZEN_INFO("instantiating project service");
- m_ProjectStore = new zen::ProjectStore(*m_CidStore, m_DataRoot / "projects");
+ 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
m_LocalProjectService = zen::LocalProjectService::New(*m_CasStore, m_ProjectStore);
+#endif
+
+#if ZEN_USE_EXEC
+ std::filesystem::path SandboxDir = m_DataRoot / "exec" / "sandbox";
+ zen::CreateDirectories(SandboxDir);
+ m_HttpLaunchService = std::make_unique<zen::HttpLaunchService>(*m_CasStore, SandboxDir);
+#endif
#if ZEN_WITH_COMPUTE_SERVICES
ZEN_INFO("instantiating compute services");
@@ -235,7 +245,7 @@ public:
std::filesystem::path ApplySandboxDir = m_DataRoot / "exec" / "apply";
zen::CreateDirectories(ApplySandboxDir);
m_HttpFunctionService = std::make_unique<zen::HttpFunctionService>(*m_CasStore, *m_CidStore, ApplySandboxDir);
-#endif // ZEN_WITH_COMPUTE_SERVICES
+#endif // ZEN_WITH_COMPUTE_SERVICES
if (ServerOptions.StructuredCacheEnabled)
{
@@ -283,7 +293,7 @@ public:
{
m_Http->RegisterService(*m_HttpFunctionService);
}
-#endif // ZEN_WITH_COMPUTE_SERVICES
+#endif // ZEN_WITH_COMPUTE_SERVICES
m_FrontendService = std::make_unique<HttpFrontendService>(m_ContentRoot);
@@ -291,6 +301,16 @@ 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),
+ .MaxCacheDuration = std::chrono::seconds(ServerOptions.GcConfig.Cache.MaxDurationSeconds),
+ .CollectSmallObjects = ServerOptions.GcConfig.CollectSmallObjects,
+ .Enabled = ServerOptions.GcConfig.Enabled,
+ };
+ m_GcScheduler.Initialize(GcConfig);
}
void InitializeState(const ZenServerOptions& ServerOptions);
@@ -503,10 +523,11 @@ private:
zen::Ref<zen::HttpServer> m_Http;
zen::HttpStatusService m_StatusService;
zen::HttpStatsService m_StatsService;
- std::unique_ptr<zen::CasStore> m_CasStore{zen::CreateCasStore()};
+ 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::CasGc m_Gc{*m_CasStore};
zen::CasScrubber m_Scrubber{*m_CasStore};
zen::HttpTestService m_TestService;
zen::HttpTestingService m_TestingService;
@@ -515,14 +536,22 @@ private:
zen::Ref<zen::LocalProjectService> m_LocalProjectService;
std::unique_ptr<zen::HttpProjectService> m_HttpProjectService;
std::unique_ptr<zen::HttpStructuredCacheService> m_StructuredCacheService;
- zen::HttpAdminService m_AdminService;
+ zen::HttpAdminService m_AdminService{m_GcScheduler};
zen::HttpHealthService m_HealthService;
zen::Mesh m_ZenMesh{m_IoContext};
#if ZEN_WITH_COMPUTE_SERVICES
- std::unique_ptr<zen::HttpLaunchService> m_HttpLaunchService;
- std::unique_ptr<zen::HttpFunctionService> m_HttpFunctionService;
+ std::unique_ptr<zen::HttpLaunchService> m_HttpLaunchService;
+ std::unique_ptr<zen::HttpFunctionService> m_HttpFunctionService;
+#endif
+ std::unique_ptr<zen::HttpFrontendService> m_FrontendService;
+
+#if ZEN_USE_EXEC
+ std::unique_ptr<zen::HttpLaunchService> m_HttpLaunchService;
+#endif
+
+#if ZEN_USE_NAMED_PIPES
+ zen::Ref<zen::LocalProjectService> m_LocalProjectService;
#endif
- std::unique_ptr<zen::HttpFrontendService> m_FrontendService;
bool m_DebugOptionForcedCrash = false;
};
@@ -590,6 +619,9 @@ ZenServer::InitializeState(const ZenServerOptions& ServerOptions)
}
}
+ // Release any open handles so we can overwrite the manifest
+ ManifestData = {};
+
// Handle any state wipe
if (WipeState)
@@ -639,7 +671,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_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)
@@ -744,12 +776,8 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
}
}
- m_StructuredCacheService.reset(new zen::HttpStructuredCacheService(*m_CacheStore,
- *m_CasStore,
- *m_CidStore,
- m_StatsService,
- m_StatusService,
- std::move(UpstreamCache)));
+ m_StructuredCacheService.reset(
+ new zen::HttpStructuredCacheService(*m_CacheStore, *m_CidStore, m_StatsService, m_StatusService, std::move(UpstreamCache)));
}
////////////////////////////////////////////////////////////////////////////////
@@ -757,18 +785,17 @@ ZenServer::InitializeStructuredCache(const ZenServerOptions& ServerOptions)
class ZenEntryPoint
{
public:
- ZenEntryPoint(ZenServerOptions& ServerOptions);
- ZenEntryPoint(const ZenEntryPoint&) = delete;
- ZenEntryPoint& operator = (const ZenEntryPoint&) = delete;
- int Run();
+ ZenEntryPoint(ZenServerOptions& ServerOptions);
+ ZenEntryPoint(const ZenEntryPoint&) = delete;
+ ZenEntryPoint& operator=(const ZenEntryPoint&) = delete;
+ int Run();
private:
- ZenServerOptions& m_ServerOptions;
- zen::LockFile m_LockFile;
+ ZenServerOptions& m_ServerOptions;
+ zen::LockFile m_LockFile;
};
-ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions)
-: m_ServerOptions(ServerOptions)
+ZenEntryPoint::ZenEntryPoint(ZenServerOptions& ServerOptions) : m_ServerOptions(ServerOptions)
{
}
@@ -800,8 +827,8 @@ ZenEntryPoint::Run()
auto MakeLockData = [&] {
CbObjectWriter Cbo;
- Cbo << "pid" << zen::GetCurrentProcessId() << "data" << PathToUtf8(ServerOptions.DataDir) << "port" << ServerOptions.BasePort << "session_id"
- << GetSessionId() << "ready" << IsReady;
+ Cbo << "pid" << zen::GetCurrentProcessId() << "data" << PathToUtf8(ServerOptions.DataDir) << "port" << ServerOptions.BasePort
+ << "session_id" << GetSessionId() << "ready" << IsReady;
return Cbo.Save();
};
@@ -914,10 +941,7 @@ ZenEntryPoint::Run()
class ZenWindowsService : public WindowsService
{
public:
- ZenWindowsService(ZenServerOptions& ServerOptions)
- : m_EntryPoint(ServerOptions)
- {
- }
+ ZenWindowsService(ZenServerOptions& ServerOptions) : m_EntryPoint(ServerOptions) {}
ZenWindowsService(const ZenWindowsService&) = delete;
ZenWindowsService& operator=(const ZenWindowsService&) = delete;
@@ -934,7 +958,7 @@ ZenWindowsService::Run()
return m_EntryPoint.Run();
}
-#endif // ZEN_PLATFORM_WINDOWS
+#endif // ZEN_PLATFORM_WINDOWS
////////////////////////////////////////////////////////////////////////////////
@@ -945,6 +969,7 @@ test_main(int argc, char** argv)
zen::zencore_forcelinktests();
zen::zenhttp_forcelinktests();
zen::zenstore_forcelinktests();
+ zen::z$_forcelink();
zen::logging::InitializeLogging();
@@ -993,7 +1018,7 @@ main(int argc, char* argv[])
{
TraceInit(ServerOptions.TraceFile.c_str(), TraceType::File);
}
-#endif // ZEN_WITH_TRACE
+#endif // ZEN_WITH_TRACE
#if ZEN_PLATFORM_WINDOWS
if (ServerOptions.InstallService)
@@ -1020,7 +1045,7 @@ main(int argc, char* argv[])
ZenEntryPoint App(ServerOptions);
return App.Run();
-#endif // ZEN_PLATFORM_WINDOWS
+#endif // ZEN_PLATFORM_WINDOWS
}
catch (std::exception& Ex)
{