Skip to main content

uni_common/core/
snapshot.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2024-2026 Dragonscale Team
3
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Clone, Debug, Serialize, Deserialize)]
9pub struct SnapshotManifest {
10    pub snapshot_id: String,
11    pub name: Option<String>,
12    pub created_at: DateTime<Utc>,
13    pub parent_snapshot: Option<String>,
14    pub schema_version: u32,
15    pub version_high_water_mark: u64,
16    pub wal_high_water_mark: u64,
17
18    pub vertices: HashMap<String, LabelSnapshot>,
19    pub edges: HashMap<String, EdgeSnapshot>,
20}
21
22/// Snapshot counters for one entity kind (a vertex label or an edge type).
23///
24/// Labels and edge types capture the identical shape, so one struct serves
25/// both via the [`LabelSnapshot`] / [`EdgeSnapshot`] aliases — the map key
26/// (in [`SnapshotManifest::vertices`] vs `edges`) already conveys which kind.
27#[derive(Clone, Debug, Serialize, Deserialize)]
28pub struct EntitySnapshot {
29    pub version: u32,
30    pub count: u64,
31    pub lance_version: u64,
32}
33
34/// Snapshot counters for a vertex label. Alias of [`EntitySnapshot`].
35pub type LabelSnapshot = EntitySnapshot;
36
37/// Snapshot counters for an edge type. Alias of [`EntitySnapshot`].
38pub type EdgeSnapshot = EntitySnapshot;
39
40impl SnapshotManifest {
41    pub fn new(snapshot_id: String, schema_version: u32) -> Self {
42        Self {
43            snapshot_id,
44            name: None,
45            created_at: Utc::now(),
46            parent_snapshot: None,
47            schema_version,
48            version_high_water_mark: 0,
49            wal_high_water_mark: 0,
50            vertices: HashMap::new(),
51            edges: HashMap::new(),
52        }
53    }
54}