MCPcopy Create free account
hub / github.com/cosdata/cosdata / retrieve_background_version

Function retrieve_background_version

src/models/meta_persist.rs:154–177  ·  view source on GitHub ↗

retrieves the current version of a collection

(lmdb: &MetaDb)

Source from the content-addressed store, hash-verified

152
153/// retrieves the current version of a collection
154pub fn retrieve_background_version(lmdb: &MetaDb) -> Result<VersionNumber, WaCustomError> {
155 let env = lmdb.env.clone();
156 let db = lmdb.db;
157 let txn = env
158 .begin_ro_txn()
159 .map_err(|e| WaCustomError::DatabaseError(format!("Failed to begin transaction: {}", e)))?;
160 let current_version_key = key!(m:background_version);
161
162 let serialized_hash = txn.get(db, &current_version_key).map_err(|e| match e {
163 lmdb::Error::NotFound => {
164 WaCustomError::DatabaseError("Record not found: current_version".to_string())
165 }
166 _ => WaCustomError::DatabaseError(e.to_string()),
167 })?;
168
169 let bytes: [u8; 4] = serialized_hash.try_into().map_err(|_| {
170 WaCustomError::DeserializationError(
171 "Failed to deserialize Hash: length mismatch".to_string(),
172 )
173 })?;
174 let hash = VersionNumber::from(u32::from_le_bytes(bytes));
175
176 Ok(hash)
177}
178
179pub fn retrieve_values_range(lmdb: &MetaDb) -> Result<Option<(f32, f32)>, WaCustomError> {
180 let env = lmdb.env.clone();

Callers 1

loadMethod · 0.85

Calls 2

cloneMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected