NetworkedApplications: live config generations and durable backup/restore (P-NETWORKED-05)

This commit is contained in:
faumaray committed 2026-12-04 10:13:31 +03:00
1 parent 3010b8a913
commit 03542d0d2f
7 files changed
+256 -4

No files matched your search

@@ -340,6 +340,39 @@ namespace NetworkedKv
m_admin_server = std::move(admin);
}
m_state = ApplicationState::Running;
++m_generation;
return {};
}
Void::Result::Result<void>
NetworkedApplication::reload(NetworkedConfig candidate)
{
if (auto valid = candidate.validate(); !valid) {
return valid;
}
if (m_state != ApplicationState::Running) {
return std::unexpected{state_error(
"NetworkedApplication: reload requires a running application")};
}
// Only policy that can change without rebinding listeners or reopening
// the backend is applied live. Everything else is a restart decision.
if (candidate.listen_address != m_config.listen_address ||
candidate.admin_address != m_config.admin_address ||
candidate.storage_path != m_config.storage_path ||
candidate.max_connections != m_config.max_connections ||
candidate.max_request_bytes != m_config.max_request_bytes ||
candidate.max_scan_page != m_config.max_scan_page) {
return std::unexpected{state_error(
"NetworkedApplication: listener, storage and limit changes "
"require a restart")};
}
// Publish the immutable generation only after every step succeeded.
// The API token swap is the single live mutation; there is no second
// listener to fail after it.
m_api->set_bearer_token(candidate.bearer_token);
m_config = std::move(candidate);
++m_generation;
return {};
}
@@ -401,6 +434,42 @@ namespace NetworkedKv
return m_admin_server ? m_admin_server->bound_port() : 0;
}
Void::Result::Result<void>
NetworkedApplication::backup_storage(const std::string& destination)
{
auto* durable = dynamic_cast<SqliteKvStore*>(m_store.get());
if (durable == nullptr) {
return std::unexpected{state_error(
"NetworkedApplication: backup requires the durable profile")};
}
if (destination.empty()) {
return std::unexpected{
config_error("NetworkedApplication: backup destination is empty")};
}
if (auto backed_up = durable->backup_to(destination); !backed_up) {
return std::unexpected{std::move(backed_up).error()};
}
return {};
}
Void::Result::Result<void>
NetworkedApplication::restore_storage(const std::string& source)
{
auto* durable = dynamic_cast<SqliteKvStore*>(m_store.get());
if (durable == nullptr) {
return std::unexpected{state_error(
"NetworkedApplication: restore requires the durable profile")};
}
if (source.empty()) {
return std::unexpected{
config_error("NetworkedApplication: restore source is empty")};
}
if (auto restored = durable->restore_from(source); !restored) {
return std::unexpected{std::move(restored).error()};
}
return {};
}
void NetworkedApplication::stop_owned_host() noexcept
{
if (m_resources.ownership != ResourceOwnership::Managed ||