diff options
| author | Stefan Boberg <[email protected]> | 2025-10-13 12:01:55 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-10-13 12:01:55 +0200 |
| commit | d86ca9ac1c76e2841c44ede6b39930b6f934ef93 (patch) | |
| tree | ec2c6a936229d343c843ac5f1962cb2ba96c8db0 /src/zenserver/zenserver.h | |
| parent | hide http.sys options when unavailable (#568) (diff) | |
| download | zen-d86ca9ac1c76e2841c44ede6b39930b6f934ef93.tar.xz zen-d86ca9ac1c76e2841c44ede6b39930b6f934ef93.zip | |
move service common code into base class (#567)
Separates storage server code and generic server code into two classes.
This is a change to prepare for different services to be implemented using the same framework, into the same executable
Diffstat (limited to 'src/zenserver/zenserver.h')
| -rw-r--r-- | src/zenserver/zenserver.h | 163 |
1 files changed, 101 insertions, 62 deletions
diff --git a/src/zenserver/zenserver.h b/src/zenserver/zenserver.h index ba76c5fff..5447158ab 100644 --- a/src/zenserver/zenserver.h +++ b/src/zenserver/zenserver.h @@ -43,84 +43,129 @@ ZEN_THIRD_PARTY_INCLUDES_END namespace zen { -struct ZenServerOptions; +struct ZenStorageServerOptions; -class ZenServer : public IHttpStatusProvider +class ZenServerBase : public IHttpStatusProvider { - ZenServer& operator=(ZenServer&&) = delete; - ZenServer(ZenServer&&) = delete; + ZenServerBase& operator=(ZenServerBase&&) = delete; + ZenServerBase(ZenServerBase&&) = delete; public: - ZenServer(); - ~ZenServer(); + ZenServerBase(); + ~ZenServerBase(); + void RequestExit(int ExitCode); + + void SetIsReadyFunc(std::function<void()>&& IsReadyFunc) { m_IsReadyFunc = std::move(IsReadyFunc); } + +protected: int Initialize(const ZenServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry); - void InitializeState(const ZenServerOptions& ServerOptions); - void InitializeStructuredCache(const ZenServerOptions& ServerOptions); + void Finalize(); - void Run(); - void RequestExit(int ExitCode); - void Cleanup(); +protected: + NamedMutex m_ServerMutex; + ZenServerState::ZenServerEntry* m_ServerEntry = nullptr; + bool m_UseSentry = false; + bool m_IsPowerCycle = false; - void SetDedicatedMode(bool State) { m_IsDedicatedMode = State; } - void SetTestMode(bool State) { m_TestMode = State; } - void SetDataRoot(std::filesystem::path Root) { m_DataRoot = Root; } - void SetContentRoot(std::filesystem::path Root) { m_ContentRoot = Root; } + std::thread m_IoRunner; + asio::io_context m_IoContext; + void EnsureIoRunner(); + + enum ServerState + { + kInitializing, + kRunning, + kShuttingDown + } m_CurrentState = kInitializing; + + inline void SetNewState(ServerState NewState) { m_CurrentState = NewState; } + static std::string_view ToString(ServerState Value); std::function<void()> m_IsReadyFunc; - void SetIsReadyFunc(std::function<void()>&& IsReadyFunc) { m_IsReadyFunc = std::move(IsReadyFunc); } void OnReady(); - void EnsureIoRunner(); + Ref<HttpServer> m_Http; + HttpHealthService m_HealthService; + HttpStatusService m_StatusService; + + // Stats reporting + + StatsReporter m_StatsReporter; + asio::steady_timer m_StatsReportingTimer{m_IoContext}; + void EnqueueStatsReportingTimer(); + + // Process Monitoring + + void CheckOwnerPid(); + bool UpdateProcessMonitor(); void EnqueueProcessMonitorTimer(); - void EnqueueStateMarkerTimer(); - void EnqueueSigIntTimer(); + + ProcessMonitor m_ProcessMonitor; + asio::steady_timer m_PidCheckTimer{m_IoContext}; + bool m_FoundNoActiveSponsors = false; + + // Server state exit signaling + + asio::steady_timer m_StateExitFlagTimer{m_IoContext}; + void EnqueueStateExitFlagTimer(); - void EnqueueStatsReportingTimer(); - void CheckStateMarker(); - void CheckSigInt(); void CheckStateExitFlag(); - void CheckOwnerPid(); - bool UpdateProcessMonitor(); - void Flush(); + // SIGINT handling + + void EnqueueSigIntTimer(); + void CheckSigInt(); + asio::steady_timer m_SigIntTimer{m_IoContext}; + + // IHttpStatusProvider virtual void HandleStatusRequest(HttpServerRequest& Request) override; +}; + +class ZenStorageServer : public ZenServerBase +{ + ZenStorageServer& operator=(ZenStorageServer&&) = delete; + ZenStorageServer(ZenStorageServer&&) = delete; + +public: + ZenStorageServer(); + ~ZenStorageServer(); + + void SetDedicatedMode(bool State) { m_IsDedicatedMode = State; } + void SetTestMode(bool State) { m_TestMode = State; } + void SetDataRoot(std::filesystem::path Root) { m_DataRoot = Root; } + void SetContentRoot(std::filesystem::path Root) { m_ContentRoot = Root; } + + int Initialize(const ZenStorageServerOptions& ServerOptions, ZenServerState::ZenServerEntry* ServerEntry); + void Run(); + void Cleanup(); private: - ZenServerState::ZenServerEntry* m_ServerEntry = nullptr; - bool m_IsDedicatedMode = false; - bool m_TestMode = false; - bool m_IsPowerCycle = false; - CbObject m_RootManifest; - std::filesystem::path m_DataRoot; - std::filesystem::path m_ContentRoot; - std::thread m_IoRunner; - asio::io_context m_IoContext; - asio::steady_timer m_PidCheckTimer{m_IoContext}; - asio::steady_timer m_StateMakerTimer{m_IoContext}; - asio::steady_timer m_StateExitFlagTimer{m_IoContext}; - asio::steady_timer m_SigIntTimer{m_IoContext}; - asio::steady_timer m_StatsReportingTimer{m_IoContext}; - ProcessMonitor m_ProcessMonitor; - NamedMutex m_ServerMutex; - bool m_FoundNoActiveSponsors = false; + void InitializeState(const ZenStorageServerOptions& ServerOptions); + void InitializeStructuredCache(const ZenStorageServerOptions& ServerOptions); + void Flush(); - enum ServerState - { - kInitializing, - kRunning, - kShuttingDown - } m_CurrentState = kInitializing; + bool m_IsDedicatedMode = false; + bool m_TestMode = false; + bool m_DebugOptionForcedCrash = false; + std::string m_StartupScrubOptions; + CbObject m_RootManifest; + std::filesystem::path m_DataRoot; + std::filesystem::path m_ContentRoot; + asio::steady_timer m_StateMarkerTimer{m_IoContext}; - inline void SetNewState(ServerState NewState) { m_CurrentState = NewState; } - static std::string_view ToString(ServerState Value); + void EnqueueStateMarkerTimer(); + void CheckStateMarker(); + + std::unique_ptr<AuthMgr> m_AuthMgr; + std::unique_ptr<HttpAuthService> m_AuthService; + void InitializeAuthentication(const ZenStorageServerOptions& ServerOptions); + + void InitializeServices(const ZenStorageServerOptions& ServerOptions); + void RegisterServices(); - StatsReporter m_StatsReporter; - Ref<HttpServer> m_Http; - std::unique_ptr<AuthMgr> m_AuthMgr; - std::unique_ptr<HttpAuthService> m_AuthService; - HttpStatusService m_StatusService; HttpStatsService m_StatsService; + std::unique_ptr<JobQueue> m_JobQueue; GcManager m_GcManager; GcScheduler m_GcScheduler{m_GcManager}; std::unique_ptr<CidStore> m_CidStore; @@ -133,6 +178,7 @@ private: #if ZEN_WITH_TESTS HttpTestingService m_TestingService; #endif + RefPtr<ProjectStore> m_ProjectStore; std::unique_ptr<VfsServiceImpl> m_VfsServiceImpl; std::unique_ptr<HttpProjectService> m_HttpProjectService; @@ -141,18 +187,11 @@ private: std::unique_ptr<UpstreamCache> m_UpstreamCache; std::unique_ptr<HttpUpstreamService> m_UpstreamService; std::unique_ptr<HttpStructuredCacheService> m_StructuredCacheService; - HttpHealthService m_HealthService; std::unique_ptr<HttpFrontendService> m_FrontendService; std::unique_ptr<HttpObjectStoreService> m_ObjStoreService; std::unique_ptr<HttpBuildStoreService> m_BuildStoreService; std::unique_ptr<VfsService> m_VfsService; - std::unique_ptr<JobQueue> m_JobQueue; std::unique_ptr<HttpAdminService> m_AdminService; - - bool m_DebugOptionForcedCrash = false; - bool m_UseSentry = false; - - std::string m_StartupScrubOptions; }; void zenserver_forcelinktests(); |