OpenSWMM Engine  6.0.0-alpha.4
Data-oriented, plugin-extensible SWMM Engine (6.0.0-alpha.4)
Loading...
Searching...
No Matches
CheckpointOutputPublication.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Caleb Buahin
3
12
13#pragma once
14#include <filesystem>
15#include <cstdio>
16#include <string>
17#include <vector>
18#include <cstdint>
19#include <cstddef>
20
21namespace openswmm::io {
29int checkpointFileDescriptor(FILE* stream) noexcept;
46void checkpointReadOutput(int descriptor, uint64_t offset, char* data, std::size_t bytes);
47// Create exclusively, or reopen without truncation, with rename sharing.
58FILE* checkpointOpenOutput(const std::filesystem::path& path, bool existing = false);
59// Internal checkpoint publication. Writers remain on their old handles until
60// every rename succeeds. This is not an atomic view for external readers or a
61// power-loss transaction. A failed rollback retains its backup for recovery.
63public:
64 struct Output {
65 std::filesystem::path staging, destination;
66 std::string fresh_header;
68 };
69
82 explicit CheckpointOutputPublication(std::vector<Output>);
103 void publish();
104
105private:
106 struct Entry {
107 Output output;
108 std::filesystem::path backup;
109 bool published = false, retain = false;
110 };
111 std::vector<Entry> entries_;
117 void cleanup() noexcept;
118};
119}
void publish()
Replace all validated fresh outputs, rolling back on a rename failure.
Definition CheckpointOutputPublication.cpp:292
CheckpointOutputPublication(std::vector< Output >)
Validate output pairs and reserve rollback headers before publication.
Definition CheckpointOutputPublication.cpp:235
CheckpointOutputPublication & operator=(const CheckpointOutputPublication &)=delete
CheckpointOutputPublication(const CheckpointOutputPublication &)=delete
~CheckpointOutputPublication()
Remove reserved backup headers unless needed for failed rollback recovery.
Definition CheckpointOutputPublication.cpp:280
Definition AtomicOutputFile.hpp:25
FILE * checkpointOpenOutput(const std::filesystem::path &path, bool existing)
Open a writable binary output for checkpoint restoration.
Definition CheckpointOutputPublication.cpp:43
void checkpointReadOutput(int descriptor, uint64_t offset, char *data, std::size_t bytes)
Read an exact output range through a borrowed seekable writer descriptor.
Definition CheckpointOutputPublication.cpp:73
int checkpointFileDescriptor(FILE *stream) noexcept
Obtain a borrowed platform descriptor for a C stream.
Definition CheckpointOutputPublication.cpp:66
Definition CheckpointOutputPublication.hpp:64
std::filesystem::path staging
Definition CheckpointOutputPublication.hpp:65
std::string fresh_header
Definition CheckpointOutputPublication.hpp:66
std::filesystem::path destination
Definition CheckpointOutputPublication.hpp:65
int original_descriptor
Definition CheckpointOutputPublication.hpp:67