NeoGraph 0.10.0
A C++17 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
grpc_checkpoint.h
1// neograph::grpc — remote CheckpointStore over gRPC.
2//
3// Ported from the predecessor NexaGraph (src/nexagraph/grpc_checkpoint
4// .{h,cpp}), which already inherited neograph::graph::CheckpointStore.
5// Two halves:
6//
7// * GrpcCheckpointStore — a CheckpointStore the engine SETS; every
8// save/load round-trips to a remote gRPC CheckpointService instead
9// of a local DB. The agent process carries no DB driver.
10// * CheckpointServiceImpl + run_checkpoint_server — the SERVER side:
11// wraps any real CheckpointStore (InMemory/Sqlite/Postgres) and
12// exposes it over gRPC. Lives in a separate process, owns the DB.
13//
14// Opt-in (NEOGRAPH_BUILD_GRPC=ON, default OFF). Whole header behind
15// NEOGRAPH_HAVE_GRPC so the umbrella include never pulls grpc++.
16
17#pragma once
18
19#ifdef NEOGRAPH_HAVE_GRPC
20
21#include <memory>
22#include <optional>
23#include <string>
24#include <vector>
25
27
28namespace neograph::grpc {
29
30// ── Client side ──────────────────────────────────────────────────────
31//
32// Set this on the engine just like SqliteCheckpointStore:
33// auto store = std::make_shared<neograph::grpc::GrpcCheckpointStore>(
34// "checkpoint-host:50071");
35// auto engine = GraphEngine::compile(def, ctx, store);
36//
37// Every checkpoint then save/loads over gRPC. Only the 5 sync core
38// virtuals are overridden; the async peers inherit the base facade
39// (run_sync over the sync impl), and pending-writes stay the no-op
40// default — same surface NexaGraph shipped.
41class NEOGRAPH_API GrpcCheckpointStore : public neograph::graph::CheckpointStore {
42public:
46 explicit GrpcCheckpointStore(const std::string& target);
47 ~GrpcCheckpointStore() override;
48
49 void save(const neograph::graph::Checkpoint& cp) override;
50 std::optional<neograph::graph::Checkpoint>
51 load_latest(const std::string& thread_id) override;
52 std::optional<neograph::graph::Checkpoint>
53 load_by_id(const std::string& id) override;
54 std::vector<neograph::graph::Checkpoint>
55 list(const std::string& thread_id, int limit = 100) override;
56 void delete_thread(const std::string& thread_id) override;
57
58private:
59 struct Impl;
60 std::unique_ptr<Impl> impl_;
61};
62
63// ── Server side ──────────────────────────────────────────────────────
64//
65// Build + run a blocking gRPC CheckpointService backed by `backend`
66// (e.g. a SqliteCheckpointStore) on `address` ("0.0.0.0:50071"), until
67// the process is signalled. Insecure credentials — front with mTLS in
68// prod via your own ServerBuilder if needed.
69NEOGRAPH_API void run_checkpoint_server(
70 const std::string& address,
71 std::shared_ptr<neograph::graph::CheckpointStore> backend);
72
73// ── Serialization (exposed for tests / payload-size measurement) ─────
74//
75// Full Checkpoint ⇄ JSON. Handles the fields NexaGraph's flat mapping
76// didn't: next_nodes (vector), interrupt_phase (enum via to_string /
77// parse_checkpoint_phase), barrier_state (nested map), schema_version.
78NEOGRAPH_API std::string checkpoint_to_json(
80NEOGRAPH_API neograph::graph::Checkpoint checkpoint_from_json(
81 const std::string& s);
82
83} // namespace neograph::grpc
84
85#endif // NEOGRAPH_HAVE_GRPC
Checkpoint system for graph execution state persistence and time-travel.
Abstract interface for checkpoint persistence backends.
Definition checkpoint.h:207
Serialized snapshot of graph execution state at a single super-step.
Definition checkpoint.h:83