MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / open

Method open

nodedb/src/engine/array/store/catalog.rs:62–101  ·  view source on GitHub ↗

Open or create the array store. Loads the manifest if present; mmap's every referenced segment and validates schema_hash.

(
        root: PathBuf,
        schema: Arc<ArraySchema>,
        schema_hash: u64,
    )

Source from the content-addressed store, hash-verified

60 /// Open or create the array store. Loads the manifest if present;
61 /// mmap's every referenced segment and validates schema_hash.
62 pub fn open(
63 root: PathBuf,
64 schema: Arc<ArraySchema>,
65 schema_hash: u64,
66 ) -> Result<Self, ArrayStoreError> {
67 std::fs::create_dir_all(&root).map_err(|e| ArrayStoreError::Io {
68 detail: format!("mkdir {root:?}: {e}"),
69 })?;
70 let manifest = Manifest::load_or_new(&root, schema_hash)?;
71 if manifest.schema_hash != schema_hash && !manifest.segments.is_empty() {
72 return Err(ArrayStoreError::SchemaHashMismatch {
73 store: manifest.schema_hash,
74 new: schema_hash,
75 });
76 }
77 let mut segments = HashMap::with_capacity(manifest.segments.len());
78 let mut max_seq: u64 = 0;
79 for seg in &manifest.segments {
80 let h = SegmentHandle::open(
81 &segment_path(&root, &seg.id),
82 seg.id.clone(),
83 schema_hash,
84 None,
85 )?;
86 if let Some(seq) = parse_segment_seq(&seg.id) {
87 max_seq = max_seq.max(seq);
88 }
89 segments.insert(seg.id.clone(), h);
90 }
91 Ok(Self {
92 root,
93 schema,
94 schema_hash,
95 manifest,
96 memtable: Memtable::new(),
97 segments,
98 next_segment_seq: max_seq + 1,
99 kek: None,
100 })
101 }
102
103 /// Install the at-rest encryption key for SEGA segment envelopes.
104 ///

Callers

nothing calls this directly

Calls 7

parse_segment_seqFunction · 0.85
segment_pathFunction · 0.70
openFunction · 0.50
is_emptyMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected