diff options
Diffstat (limited to 'src/zenserver/hub/storageserverinstance.cpp')
| -rw-r--r-- | src/zenserver/hub/storageserverinstance.cpp | 174 |
1 files changed, 38 insertions, 136 deletions
diff --git a/src/zenserver/hub/storageserverinstance.cpp b/src/zenserver/hub/storageserverinstance.cpp index 99f0c29f3..6b139dbf1 100644 --- a/src/zenserver/hub/storageserverinstance.cpp +++ b/src/zenserver/hub/storageserverinstance.cpp @@ -69,177 +69,86 @@ StorageServerInstance::GetProcessMetrics(ProcessMetrics& OutMetrics) const OutMetrics.PeakPagefileUsage = m_PeakPagefileUsage.load(); } -bool +void StorageServerInstance::ProvisionLocked() { - if (m_State.load() == HubInstanceState::Provisioned) + if (m_ServerInstance.IsRunning()) { ZEN_WARN("Storage server instance for module '{}' is already provisioned", m_ModuleId); - return false; - } - - if (m_State.load() == HubInstanceState::Crashed) - { - ZEN_WARN("Storage server instance for module '{}' is in crashed state; re-provisioning from scratch", m_ModuleId); - m_State = HubInstanceState::Unprovisioned; - } - - if (m_State.load() == HubInstanceState::Hibernated) - { - return WakeLocked(); - } - - if (m_State.load() != HubInstanceState::Unprovisioned) - { - ZEN_WARN("Storage server instance for module '{}' is in unexpected state '{}', cannot provision", - m_ModuleId, - ToString(m_State.load())); - return false; + return; } ZEN_INFO("Provisioning storage server instance for module '{}', at '{}'", m_ModuleId, m_BaseDir); - - m_State = HubInstanceState::Provisioning; try { Hydrate(); SpawnServerProcess(); - m_State = HubInstanceState::Provisioned; - return true; } - catch (...) + catch (const std::exception& Ex) { - m_State = HubInstanceState::Unprovisioned; + ZEN_WARN("Failed spawning server instance for module '{}', at '{}' during provisioning. Reason: {}", + m_ModuleId, + m_BaseDir, + Ex.what()); throw; } } -bool +void StorageServerInstance::DeprovisionLocked() { - const HubInstanceState CurrentState = m_State.load(); - if (CurrentState != HubInstanceState::Provisioned && CurrentState != HubInstanceState::Crashed && - CurrentState != HubInstanceState::Hibernated) + if (m_ServerInstance.IsRunning()) { - ZEN_WARN("Attempted to deprovision storage server instance for module '{}' which is not provisioned (state: '{}')", - m_ModuleId, - ToString(CurrentState)); - return false; - } - - ZEN_INFO("Deprovisioning storage server instance for module '{}'", m_ModuleId); - - m_State = HubInstanceState::Deprovisioning; - if (CurrentState == HubInstanceState::Provisioned) - { - try - { - m_ServerInstance.Shutdown(); - } - catch (...) - { - m_State = HubInstanceState::Provisioned; // Shutdown failed; process may still be running - throw; - } + // m_ServerInstance.Shutdown() never throws. + m_ServerInstance.Shutdown(); } - // Crashed or Hibernated: process already dead; skip Shutdown + // Crashed or Hibernated: process already dead; skip Shutdown. + // Dehydrate preserves instance state for future re-provisioning. Failure means saved state + // may be stale or absent, but the process is already dead so the slot can still be released. + // Swallow the exception and proceed with cleanup rather than leaving the module stuck. try { Dehydrate(); } - catch (...) + catch (const std::exception& Ex) { - m_State = HubInstanceState::Crashed; // Dehydrate failed; process is already dead - throw; + ZEN_WARN("Dehydration of module {} failed during deprovisioning, current state not saved. Reason: {}", m_ModuleId, Ex.what()); } - - m_State = HubInstanceState::Unprovisioned; - return true; } -bool +void StorageServerInstance::HibernateLocked() { // Signal server to shut down, but keep data around for later wake - if (m_State.load() != HubInstanceState::Provisioned) - { - ZEN_WARN("Attempted to hibernate storage server instance for module '{}' which is not provisioned (state: '{}')", - m_ModuleId, - ToString(m_State.load())); - return false; - } - if (!m_ServerInstance.IsRunning()) { - ZEN_WARN("Attempted to hibernate storage server instance for module '{}' which is not running", m_ModuleId); - return false; + return; } - m_State = HubInstanceState::Hibernating; - try - { - m_ServerInstance.Shutdown(); - m_State = HubInstanceState::Hibernated; - return true; - } - catch (...) - { - m_State = HubInstanceState::Provisioned; // Shutdown failed; instance is still running - throw; - } + // m_ServerInstance.Shutdown() never throws. + m_ServerInstance.Shutdown(); } -bool +void StorageServerInstance::WakeLocked() { // Start server in-place using existing data - if (m_State.load() != HubInstanceState::Hibernated) + if (m_ServerInstance.IsRunning()) { - ZEN_WARN("Attempted to wake storage server instance for module '{}' which is not hibernated (state: '{}')", - m_ModuleId, - ToString(m_State.load())); - return false; + return; } - ZEN_ASSERT_FORMAT(!m_ServerInstance.IsRunning(), "Storage server instance for module '{}' is already running", m_ModuleId); - - m_State = HubInstanceState::Waking; try { SpawnServerProcess(); - m_State = HubInstanceState::Provisioned; - return true; - } - catch (...) - { - m_State = HubInstanceState::Hibernated; - throw; - } -} - -bool -StorageServerInstance::RecoverCrashedLocked() -{ - ZEN_ASSERT(m_State.load() == HubInstanceState::Provisioned); - ZEN_ASSERT(!m_ServerInstance.IsRunning()); - - ZEN_WARN("Storage server instance for module '{}' has crashed; attempting in-place recovery", m_ModuleId); - m_State = HubInstanceState::Recovering; - try - { - SpawnServerProcess(); - m_State = HubInstanceState::Provisioned; - ZEN_INFO("Storage server instance for module '{}' recovered successfully", m_ModuleId); - return true; } catch (const std::exception& Ex) { - ZEN_ERROR("Failed to restart module '{}': {}", m_ModuleId, Ex.what()); - m_State = HubInstanceState::Crashed; - return false; + ZEN_WARN("Failed spawning server instance for module '{}', at '{}' during waking. Reason: {}", m_ModuleId, m_BaseDir, Ex.what()); + throw; } } @@ -337,13 +246,13 @@ bool StorageServerInstance::SharedLockedPtr::IsRunning() const { ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->m_State.load() == HubInstanceState::Provisioned && m_Instance->m_ServerInstance.IsRunning(); + return m_Instance->m_ServerInstance.IsRunning(); } void StorageServerInstance::UpdateMetricsLocked() { - if (m_State.load() == HubInstanceState::Provisioned) + if (m_ServerInstance.IsRunning()) { ProcessMetrics Metrics; zen::GetProcessMetrics(m_ServerInstance.GetProcessHandle(), Metrics); @@ -436,42 +345,35 @@ bool StorageServerInstance::ExclusiveLockedPtr::IsRunning() const { ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->m_State.load() == HubInstanceState::Provisioned && m_Instance->m_ServerInstance.IsRunning(); + return m_Instance->m_ServerInstance.IsRunning(); } -bool +void StorageServerInstance::ExclusiveLockedPtr::Provision() { ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->ProvisionLocked(); + m_Instance->ProvisionLocked(); } -bool +void StorageServerInstance::ExclusiveLockedPtr::Deprovision() { ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->DeprovisionLocked(); + m_Instance->DeprovisionLocked(); } -bool +void StorageServerInstance::ExclusiveLockedPtr::Hibernate() { ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->HibernateLocked(); + m_Instance->HibernateLocked(); } -bool +void StorageServerInstance::ExclusiveLockedPtr::Wake() { ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->WakeLocked(); -} - -bool -StorageServerInstance::ExclusiveLockedPtr::RecoverFromCrash() -{ - ZEN_ASSERT(m_Instance != nullptr); - return m_Instance->RecoverCrashedLocked(); + m_Instance->WakeLocked(); } } // namespace zen |