ReloadableApplications: versioned checkpoint migration

This commit is contained in:
faumaray committed 2026-12-04 00:51:26 +03:00
1 parent d73a34d622
commit 41e8c9c6ab
4 files changed
+305

No files matched your search

@@ -0,0 +1,40 @@
#pragma once
#include <Void/Functional/Result.hpp>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string>
#include <vector>
namespace ReloadableHost
{
inline constexpr std::uint32_t kCurrentCheckpointVersion{3};
/// Durable workflow state carried across releases.
struct CheckpointState {
std::uint64_t counter{0};
std::string workflow;
std::uint64_t generation{0};
};
struct CheckpointLimits {
std::size_t max_bytes{64ULL * 1024ULL};
std::size_t max_workflow_bytes{4ULL * 1024ULL};
};
/// Encode the current checkpoint schema (bounded).
[[nodiscard]] Void::Result::Result<std::vector<std::byte>>
encode_checkpoint(const CheckpointState& state,
CheckpointLimits limits = {});
/// Decode a supported checkpoint and migrate it to the current schema.
///
/// v1 (counter) and v2 (counter + workflow) are migrated forward with
/// defaults for fields they did not have. Corrupt magic, truncation,
/// oversized payloads and unknown newer versions are rejected.
[[nodiscard]] Void::Result::Result<CheckpointState>
decode_checkpoint(std::span<const std::byte> bytes,
CheckpointLimits limits = {});
} // namespace ReloadableHost