NetworkedApplications: live config generations and durable backup/restore (P-NETWORKED-05)
This commit is contained in:
1 parent
3010b8a913
commit
03542d0d2f
7 files changed
+256
-4
No files matched your search
@@ -95,11 +95,34 @@ namespace NetworkedKv
|
||||
{
|
||||
return m_config;
|
||||
}
|
||||
/// Generation of the live configuration (starts at 1 after the first
|
||||
/// successful start; incremented by each applied reload).
|
||||
[[nodiscard]] std::uint64_t config_generation() const noexcept
|
||||
{
|
||||
return m_generation;
|
||||
}
|
||||
/// Parse/validate a complete candidate and apply the live-reloadable
|
||||
/// parts atomically: the bearer token and readiness gating. Listener
|
||||
/// addresses, backend selection, storage path and limits require a
|
||||
/// restart and are rejected with a conflict error while the
|
||||
/// application is running, leaving the old generation untouched.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
reload(NetworkedConfig candidate);
|
||||
/// Port the HTTP listener actually bound (0 when not listening).
|
||||
[[nodiscard]] std::uint16_t bound_port() const noexcept;
|
||||
/// Port the administrative listener bound (0 when not listening).
|
||||
[[nodiscard]] std::uint16_t admin_bound_port() const noexcept;
|
||||
|
||||
/// Consistent operator backup of the durable profile. Fails when
|
||||
/// the in-memory profile is active.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
backup_storage(const std::string& destination);
|
||||
|
||||
/// Restore the durable profile from a backup. Quiesce clients first;
|
||||
/// the caller owns re-validation before routing traffic again.
|
||||
[[nodiscard]] Void::Result::Result<void>
|
||||
restore_storage(const std::string& source);
|
||||
|
||||
private:
|
||||
|
||||
NetworkedApplication() = default;
|
||||
@@ -115,5 +138,6 @@ namespace NetworkedKv
|
||||
std::unique_ptr<Void::Net::HttpServer> m_server{};
|
||||
std::unique_ptr<Void::Net::HttpServer> m_admin_server{};
|
||||
ApplicationState m_state{ApplicationState::Created};
|
||||
std::uint64_t m_generation{0};
|
||||
};
|
||||
} // namespace NetworkedKv
|
||||
@@ -7,6 +7,7 @@
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
@@ -61,6 +62,14 @@ namespace NetworkedKv
|
||||
|
||||
void set_ready(bool ready) noexcept { m_ready = ready; }
|
||||
|
||||
/// Atomically replace the live-reloadable bearer token. In-flight
|
||||
/// requests read either the old or the new token, never a torn mix.
|
||||
void set_bearer_token(std::string token)
|
||||
{
|
||||
std::lock_guard lock{m_config_mutex};
|
||||
m_config.bearer_token = std::move(token);
|
||||
}
|
||||
|
||||
[[nodiscard]] ApiMetrics metrics() const noexcept { return m_metrics; }
|
||||
|
||||
private:
|
||||
@@ -78,6 +87,7 @@ namespace NetworkedKv
|
||||
|
||||
KvStore& m_store;
|
||||
ApiConfig m_config;
|
||||
mutable std::mutex m_config_mutex;
|
||||
bool m_ready{true};
|
||||
ApiMetrics m_metrics;
|
||||
};
|
||||
|
||||
@@ -49,6 +49,17 @@ namespace NetworkedKv
|
||||
return m_limits;
|
||||
}
|
||||
|
||||
/// Consistent operator backup through SQLite's online backup API.
|
||||
/// `destination` must not be the live database file.
|
||||
[[nodiscard]] Void::Result::Result<Void::Sqlite::BackupReport>
|
||||
backup_to(const std::filesystem::path& destination);
|
||||
|
||||
/// Restore this connection from a verified backup file. Callers
|
||||
/// must quiesce application traffic first; run domain checks before
|
||||
/// routing traffic to the restored contents.
|
||||
[[nodiscard]] Void::Result::Result<Void::Sqlite::BackupReport>
|
||||
restore_from(const std::filesystem::path& source);
|
||||
|
||||
private:
|
||||
|
||||
SqliteKvStore(Void::Sqlite::Database database, Limits limits);
|
||||
|
||||
Reference in new issue
Block a user