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

Method open_array

nodedb/src/engine/array/engine.rs:95–116  ·  view source on GitHub ↗

Open or attach to an array. Idempotent: if the array is already open with the same `schema_hash`, this is a no-op so SQL read handlers can call `open_array` lazily on every request without losing state. If the array is open with a *different* schema_hash, returns [`ArrayEngineError::SchemaMismatch`].

(
        &mut self,
        id: ArrayId,
        schema: Arc<ArraySchema>,
        schema_hash: u64,
    )

Source from the content-addressed store, hash-verified

93 /// If the array is open with a *different* schema_hash, returns
94 /// [`ArrayEngineError::SchemaMismatch`].
95 pub fn open_array(
96 &mut self,
97 id: ArrayId,
98 schema: Arc<ArraySchema>,
99 schema_hash: u64,
100 ) -> ArrayEngineResult<()> {
101 if let Some(existing) = self.arrays.get(&id) {
102 if existing.schema_hash() == schema_hash {
103 return Ok(());
104 }
105 return Err(ArrayEngineError::SchemaMismatch {
106 name: id.name.clone(),
107 });
108 }
109 let dir = array_dir(&self.cfg.root, &id);
110 let mut store = ArrayStore::open(dir, schema, schema_hash)?;
111 if let Some(kek) = &self.cfg.kek {
112 store.set_kek(kek.clone());
113 }
114 self.arrays.insert(id, store);
115 Ok(())
116 }
117
118 pub fn array_ids(&self) -> impl Iterator<Item = &ArrayId> {
119 self.arrays.keys()

Calls 7

array_dirFunction · 0.85
openFunction · 0.50
getMethod · 0.45
schema_hashMethod · 0.45
cloneMethod · 0.45
set_kekMethod · 0.45
insertMethod · 0.45