NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
graph_migration.h
Go to the documentation of this file.
1
5#pragma once
6
7#include <neograph/api.h>
12
13#include <cstdint>
14#include <memory>
15#include <optional>
16#include <string>
17#include <string_view>
18#include <vector>
19
20namespace neograph::program {
21
22namespace detail {
23class RunControl;
24}
25
26class MigrationPlan;
27struct ProgramEvent;
28struct ProgramJournalRecord;
29class ProgramRunGeneration;
30class ProgramRunLineage;
31class ProgramRunRecord;
32struct ProgramTransitionPublication;
33
35NEOGRAPH_PROGRAM_API std::string program_root_core_thread_id(
36 std::string_view run_id,
37 std::string_view core_generation_id);
38
40NEOGRAPH_PROGRAM_API std::string graph_migration_checkpoint_content_id(
41 const graph::Checkpoint& checkpoint);
42
43struct ProgramExecutionLeaseData {
44 std::string owner_scope;
45 std::string run_id;
46 std::uint64_t attempt = 0;
47 std::string program_version_id;
48 std::string bundle_id;
49 std::string core_name;
50 std::string core_generation_id;
51 std::string core_thread_id;
52 std::string holder_id;
53 std::int64_t acquired_at_ms = 0;
54 std::int64_t expires_at_ms = 0;
55};
56
58class NEOGRAPH_PROGRAM_API ProgramExecutionLease final {
59public:
60 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
61
62 explicit ProgramExecutionLease(ProgramExecutionLeaseData data);
63 static ProgramExecutionLease parse(std::string_view stored_bytes);
64
65 const std::string& id() const noexcept;
66 const std::string& owner_scope() const noexcept;
67 const std::string& run_id() const noexcept;
68 std::uint64_t attempt() const noexcept;
69 const std::string& program_version_id() const noexcept;
70 const std::string& bundle_id() const noexcept;
71 const std::string& core_name() const noexcept;
72 const std::string& core_generation_id() const noexcept;
73 const std::string& core_thread_id() const noexcept;
74 const std::string& holder_id() const noexcept;
75 std::int64_t acquired_at_ms() const noexcept;
76 std::int64_t expires_at_ms() const noexcept;
77 std::string serialize_canonical() const;
78
79private:
80 struct Impl;
81 explicit ProgramExecutionLease(std::shared_ptr<const Impl> impl);
82 std::shared_ptr<const Impl> impl_;
83};
84
86NEOGRAPH_PROGRAM_API bool does_program_execution_lease_bind(
87 const ProgramExecutionLease& lease,
88 const ProgramTransitionPublication& publication,
89 const ProgramExecutionLease* expected_lease) noexcept;
90
92class NEOGRAPH_PROGRAM_API ProgramGraphSafePointEvidence final {
93public:
94 const ProgramBundle& bundle() const noexcept;
95 const ProgramVersion& version() const noexcept;
96 const graph::GraphSafePoint& safe_point() const noexcept;
97
98private:
99 ProgramGraphSafePointEvidence(ProgramBundle bundle,
100 ProgramVersion version,
101 graph::GraphSafePoint safe_point);
102 struct Impl;
103 std::shared_ptr<const Impl> impl_;
104
105 friend class detail::RunControl;
106};
107
114class NEOGRAPH_PROGRAM_API GraphMigrationCapsule final {
115public:
116 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
117
118 static GraphMigrationCapsule seal(
119 const ProgramRunGeneration& generation,
120 const ProgramRunLineage& lineage,
121 const ProgramVersion& version,
122 const graph::GraphSafePoint& safe_point);
123 static GraphMigrationCapsule parse(std::string_view stored_bytes);
124
125 const std::string& id() const noexcept;
126 const std::string& owner_scope() const noexcept;
127 const std::string& lineage_id() const noexcept;
128 std::uint64_t source_generation() const noexcept;
129 const std::string& source_generation_id() const noexcept;
130 const std::string& source_lineage_head_id() const noexcept;
131 const std::string& source_run_id() const noexcept;
132 const std::string& source_program_version_id() const noexcept;
133 const std::string& source_bundle_id() const noexcept;
134 const CoreCheckpointIdentity& core_checkpoint() const noexcept;
135 const graph::Checkpoint& checkpoint() const noexcept;
136 std::string serialize_canonical() const;
137
138private:
139 struct Impl;
140 explicit GraphMigrationCapsule(std::shared_ptr<const Impl> impl);
141 std::shared_ptr<const Impl> impl_;
142};
143
147 std::string kind;
149 std::string json_pointer;
150
151 bool operator==(const GraphMetadataChange&) const = default;
152};
153
163class NEOGRAPH_PROGRAM_API GraphSemanticMigrationAdapter final {
164public:
165 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 1;
166
167 static GraphSemanticMigrationAdapter prepare(const ProgramVersion& source_version,
168 const ProgramBundle& source_bundle,
169 const ProgramVersion& target_version,
170 const ProgramBundle& target_bundle);
171 static GraphSemanticMigrationAdapter parse(std::string_view stored_bytes);
172
173 const std::string& id() const noexcept;
174 const std::string& owner_scope() const noexcept;
175 const std::string& source_program_version_id() const noexcept;
176 const std::string& source_bundle_id() const noexcept;
177 const std::string& target_program_version_id() const noexcept;
178 const std::string& target_bundle_id() const noexcept;
179 const std::string& source_core_name() const noexcept;
180 const std::string& target_core_name() const noexcept;
181 const std::string& source_core_generation_id() const noexcept;
182 const std::string& target_core_generation_id() const noexcept;
183 const std::string& topology_shape_id() const noexcept;
191 const std::vector<GraphMetadataChange>& metadata_changes() const noexcept;
192
194 bool binds(const ProgramVersion& source_version, const ProgramBundle& source_bundle,
195 const ProgramVersion& target_version, const ProgramBundle& target_bundle) const;
200 graph::Checkpoint project(const GraphMigrationCapsule& capsule) const;
202 MigrationPlan migration_plan(const ProgramVersion& source_version,
203 const ProgramBundle& source_bundle,
204 const ProgramVersion& target_version,
205 const ProgramBundle& target_bundle) const;
206 std::string serialize_canonical() const;
207
208private:
209 struct Impl;
210 explicit GraphSemanticMigrationAdapter(std::shared_ptr<const Impl> impl);
211 std::shared_ptr<const Impl> impl_;
212};
213
214struct ProgramGraphMigrationReceiptData {
215 GraphMigrationCapsule capsule;
216 ProgramBundle source_bundle;
217 ProgramVersion source_version;
218 ProgramBundle target_bundle;
219 ProgramVersion target_version;
220 std::string migration_plan_id;
221 std::uint64_t target_generation = 0;
222 std::string target_run_id;
223 std::string target_program_version_id;
224 std::string target_bundle_id;
225 std::string target_invocation_id;
226 std::string target_binding_fingerprint;
227 std::string target_initial_run_record_id;
228 std::string target_initial_journal_head;
229 CoreCheckpointIdentity target_core_checkpoint;
230 graph::Checkpoint target_checkpoint;
231 std::optional<GraphSemanticMigrationAdapter> semantic_adapter;
232};
233
235class NEOGRAPH_PROGRAM_API ProgramGraphMigrationReceipt final {
236public:
237 static constexpr std::uint32_t STORAGE_SCHEMA_VERSION = 2;
238 static constexpr std::uint32_t PREVIOUS_STORAGE_SCHEMA_VERSION = 1;
239
240 explicit ProgramGraphMigrationReceipt(ProgramGraphMigrationReceiptData data);
241 static ProgramGraphMigrationReceipt parse(std::string_view stored_bytes);
242
243 const std::string& id() const noexcept;
244 const GraphMigrationCapsule& capsule() const noexcept;
245 const ProgramBundle& source_bundle() const noexcept;
246 const ProgramVersion& source_version() const noexcept;
247 const ProgramBundle& target_bundle() const noexcept;
248 const ProgramVersion& target_version() const noexcept;
249 const std::optional<GraphSemanticMigrationAdapter>& semantic_adapter() const noexcept;
250 const std::string& migration_plan_id() const noexcept;
251 std::uint64_t target_generation() const noexcept;
252 const std::string& target_run_id() const noexcept;
253 const std::string& target_program_version_id() const noexcept;
254 const std::string& target_bundle_id() const noexcept;
255 const std::string& target_invocation_id() const noexcept;
256 const std::string& target_binding_fingerprint() const noexcept;
257 const std::string& target_initial_run_record_id() const noexcept;
258 const std::string& target_initial_journal_head() const noexcept;
259 const CoreCheckpointIdentity& target_core_checkpoint() const noexcept;
260 const graph::Checkpoint& target_checkpoint() const noexcept;
261 std::string serialize_canonical() const;
262
263private:
264 struct Impl;
265 explicit ProgramGraphMigrationReceipt(std::shared_ptr<const Impl> impl);
266 std::shared_ptr<const Impl> impl_;
267};
268
271 const ProgramRunGeneration& predecessor,
272 const ProgramRunLineage& previous_lineage,
273 const ProgramRunRecord& source,
274 const GraphMigrationCapsule& durable_capsule,
275 const MigrationPlan& migration_plan,
276 const ProgramRunGeneration& successor,
277 const ProgramRunLineage& next_lineage,
278 const ProgramRunRecord& target) noexcept;
279
282 const ProgramEvent& event,
283 const ProgramRunRecord& target) noexcept;
284
287 const ProgramRunRecord& previous,
288 const ProgramJournalRecord& previous_journal,
289 const ProgramTransitionPublication& publication,
290 const ProgramGraphSafePointEvidence& evidence,
291 const GraphMigrationCapsule& capsule,
292 const ProgramExecutionLease& execution_lease) noexcept;
293
294} // namespace neograph::program
NEOGRAPH_API export/import macro for shared-library builds.
Immutable, content-addressed Program compilation artifacts.
Immutable snapshot exposed only after a completed super-step is durable.
Definition safe_point.h:28
Exact, content-addressed source evidence captured at a durable Core boundary.
Host-admitted P1 semantic bridge for an immutable control-free Core successor.
const std::vector< GraphMetadataChange > & metadata_changes() const noexcept
Graph metadata differences between the source and target definitions, sorted by pointer.
Immutable proof of whether an admitted run may move to another version.
Definition migration.h:161
Backend-global ownership of one migration-capable root Core dispatch.
Immutable evidence admitted with one same-lineage GraphEngine successor.
Host-only, non-serializable evidence for one running safe-point publication.
Immutable identity of one admitted topology generation in a run lineage.
Definition lineage.h:102
Immutable content-addressed head of one stable run lineage.
Definition lineage.h:150
Deep-owned, content-addressed run snapshot used for reconnect and CAS publication.
Definition run_record.h:119
NEOGRAPH_PROGRAM_API std::string graph_migration_checkpoint_content_id(const graph::Checkpoint &checkpoint)
Content identity of exact checkpoint bytes published under a source head.
NEOGRAPH_PROGRAM_API bool is_valid_program_graph_safe_point_transition(const ProgramRunRecord &previous, const ProgramJournalRecord &previous_journal, const ProgramTransitionPublication &publication, const ProgramGraphSafePointEvidence &evidence, const GraphMigrationCapsule &capsule, const ProgramExecutionLease &execution_lease) noexcept
Restricted same-generation publication of one host-captured Core safe point.
NEOGRAPH_PROGRAM_API bool does_program_graph_migration_started_event_bind(const ProgramEvent &event, const ProgramRunRecord &target) noexcept
Exact initial event required for a graph-migration successor publication.
NEOGRAPH_PROGRAM_API bool does_program_execution_lease_bind(const ProgramExecutionLease &lease, const ProgramTransitionPublication &publication, const ProgramExecutionLease *expected_lease) noexcept
Shared publication binding; expected_lease must first match the durable lease CAS.
NEOGRAPH_PROGRAM_API std::string program_root_core_thread_id(std::string_view run_id, std::string_view core_generation_id)
Exact root Core thread identity used by ProgramRuntime.
NEOGRAPH_PROGRAM_API bool is_valid_program_graph_migration_transition(const ProgramRunGeneration &predecessor, const ProgramRunLineage &previous_lineage, const ProgramRunRecord &source, const GraphMigrationCapsule &durable_capsule, const MigrationPlan &migration_plan, const ProgramRunGeneration &successor, const ProgramRunLineage &next_lineage, const ProgramRunRecord &target) noexcept
Shared fail-closed validator used by every atomic transition backend.
Immutable outcome of one Program run attempt.
Host-owned capture of one durably completed graph super-step.
Serialized snapshot of graph execution state at a single super-step.
Definition checkpoint.h:173
One difference between the source and target graph metadata (#362).
std::string kind
"added", "removed" or "changed".
std::string json_pointer
RFC 6901 pointer into the Core definition, e.g. "/metadata/owner".
Deep-owned stored journal value.
Definition journal.h:62
Immutable stored binding between a Program bundle and admission receipts.