1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2026 Nowledge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//! Narrow crate-internal access used by `crate::logical_dump`.
//!
//! The logical dump reads one pinned read transaction and writes a fresh,
//! unpublished import target. It needs the snapshot's catalog and store, and
//! an id-preserving graph batch import on the target; nothing else.
use super::{Database, DatabaseReadTransaction, Result};
use crate::schema::Catalog;
use crate::store::{GraphSnapshotNodeImport, GraphSnapshotRelationshipImport, GraphStore};
impl DatabaseReadTransaction {
/// The pinned catalog and store of this read transaction.
pub(crate) fn logical_dump_source(&self) -> (&Catalog, &GraphStore) {
(&self.catalog, &self.store)
}
/// The configured per-statement read payload budget.
pub(crate) fn logical_dump_payload_budget(&self) -> Option<usize> {
self.config.max_read_result_payload_bytes
}
/// Name of the branch this transaction reads, when the database has a
/// branch catalog.
pub(crate) fn logical_dump_branch_name(&self) -> Option<String> {
self.current_branch
.as_ref()
.map(|branch| branch.info.name.clone())
}
}
impl Database {
/// Commits one bounded batch of graph rows with their original ids.
/// See `GraphStore::import_graph_rows_batch`.
pub(crate) fn logical_dump_import_graph_batch(
&mut self,
nodes: Vec<GraphSnapshotNodeImport>,
relationships: Vec<GraphSnapshotRelationshipImport>,
) -> Result<()> {
self.ensure_writable()?;
let mut branch_runtime_access = self.runtime.get_mut()?;
let branch_runtime = &mut *branch_runtime_access;
branch_runtime.store.import_graph_rows_batch(
&mut branch_runtime.catalog,
nodes,
relationships,
)
}
/// Node and relationship counts, and the user-visible relational tables
/// of the current head.
pub(crate) fn logical_dump_target_state(&self) -> Result<(u64, u64, Vec<String>)> {
let runtime = self.runtime.get()?;
let statistics = runtime.store.basic_statistics();
let tables = runtime
.store
.relational_state()
.table_schemas()
.map(|schema| schema.name.clone())
.collect();
Ok((statistics.node_count, statistics.relationship_count, tables))
}
}