Implement M5.7 local world publication and recovery
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
#pragma once
|
||||
|
||||
#include "evo/world/chunks.hpp"
|
||||
#include <cstdint>
|
||||
#include <expected>
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <span>
|
||||
|
||||
namespace evo::world {
|
||||
enum class LocalFileError : std::uint8_t {
|
||||
invalid_identity,
|
||||
busy,
|
||||
empty,
|
||||
corrupt_manifest,
|
||||
corrupt_payload,
|
||||
identity_mismatch,
|
||||
invalid_snapshot,
|
||||
invalid_journal,
|
||||
stale_checkpoint,
|
||||
journal_already_published,
|
||||
generation_exhausted,
|
||||
io,
|
||||
interrupted,
|
||||
poisoned
|
||||
};
|
||||
enum class PublicationInterruption : std::uint8_t {
|
||||
none,
|
||||
after_payload_sync,
|
||||
after_manifest_sync,
|
||||
after_manifest_publish
|
||||
};
|
||||
struct FileCommit {
|
||||
std::uint64_t generation{}, covered_command{}, snapshot_checksum{};
|
||||
bool has_journal{};
|
||||
auto operator<=>(const FileCommit&) const = default;
|
||||
};
|
||||
class LocalWorldFiles {
|
||||
public:
|
||||
[[nodiscard]] static std::expected<std::unique_ptr<LocalWorldFiles>, LocalFileError>
|
||||
open(const std::filesystem::path& trusted_root, WorldIdentity identity, std::size_t byte_budget,
|
||||
PublicationInterruption interrupt_once = PublicationInterruption::none);
|
||||
LocalWorldFiles(const LocalWorldFiles&) = delete;
|
||||
LocalWorldFiles& operator=(const LocalWorldFiles&) = delete;
|
||||
LocalWorldFiles(LocalWorldFiles&&) = delete;
|
||||
LocalWorldFiles& operator=(LocalWorldFiles&&) = delete;
|
||||
~LocalWorldFiles();
|
||||
[[nodiscard]] std::expected<std::unique_ptr<ChunkStore>, LocalFileError> recover() const;
|
||||
[[nodiscard]] std::expected<FileCommit, LocalFileError> checkpoint(const ChunkStore& store);
|
||||
[[nodiscard]] std::expected<FileCommit, LocalFileError>
|
||||
publish_journal(std::span<const std::uint8_t> checkpoint,
|
||||
std::span<const std::uint8_t> journal);
|
||||
[[nodiscard]] std::optional<FileCommit> current() const noexcept;
|
||||
|
||||
private:
|
||||
struct Lock;
|
||||
struct Manifest {
|
||||
std::uint64_t generation{}, snapshot_checksum{}, covered_command{};
|
||||
std::uint64_t journal_checksum{}, journal_end{};
|
||||
bool has_journal{};
|
||||
};
|
||||
LocalWorldFiles(std::filesystem::path directory, WorldIdentity identity, std::size_t budget,
|
||||
PublicationInterruption interruption, std::unique_ptr<Lock> lock);
|
||||
[[nodiscard]] std::expected<FileCommit, LocalFileError>
|
||||
publish(std::span<const std::uint8_t> payload, bool journal, std::uint64_t covered,
|
||||
std::uint64_t payload_checksum);
|
||||
std::filesystem::path directory_;
|
||||
WorldIdentity identity_;
|
||||
std::size_t budget_;
|
||||
PublicationInterruption interruption_;
|
||||
std::unique_ptr<Lock> lock_;
|
||||
std::optional<Manifest> manifest_;
|
||||
std::size_t active_slot_{};
|
||||
std::uint64_t generation_high_water_{};
|
||||
bool poisoned_{};
|
||||
};
|
||||
} // namespace evo::world
|
||||
Reference in New Issue
Block a user