Skip to main content

oxgraph_postgres/
rebuild.rs

1//! Catalog-validated snapshot rebuild orchestration.
2
3use alloc::vec::Vec;
4
5use crate::{
6    build::{DualTopologySnapshot, EdgeRow},
7    catalog::Catalog,
8    error::PostgresGraphError,
9};
10
11/// Orchestrates relational snapshot rebuild from registration metadata and edge rows.
12#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
13pub struct SnapshotRebuild;
14
15impl SnapshotRebuild {
16    /// Validates catalog registration, then exports dual-topology OXGTOPO bytes.
17    ///
18    /// Topology is derived from `edges` only; the catalog guards non-empty registration.
19    ///
20    /// # Errors
21    ///
22    /// Returns [`PostgresGraphError::Catalog`] or [`PostgresGraphError::Build`] on failure.
23    ///
24    /// # Performance
25    ///
26    /// This function is `O(n log n + m)` where `n` is distinct nodes and `m` is edge rows.
27    pub fn from_catalog_and_edges(
28        catalog: &Catalog,
29        edges: &[EdgeRow],
30        built_at_unix: u64,
31    ) -> Result<Vec<u8>, PostgresGraphError> {
32        catalog.validate_for_build()?;
33        DualTopologySnapshot::from_edge_rows(edges, built_at_unix)
34    }
35}