MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / scan_ids

Method scan_ids

atomic-core/src/pristine/txn/pristine.rs:295–335  ·  view source on GitHub ↗

Scan existing tables for the next available IDs. Shared implementation for `open_existing` and `open_readonly` — both skip the table-init write transaction and only need a read pass to discover the max allocated node, view, and inode IDs.

(db: PristineDatabase)

Source from the content-addressed store, hash-verified

293 /// skip the table-init write transaction and only need a read pass to
294 /// discover the max allocated node, view, and inode IDs.
295 fn scan_ids(db: PristineDatabase) -> PristineResult<Self> {
296 let read_txn = db.begin_read()?;
297
298 let next_node_id = {
299 let table = read_txn.open_table(EXTERNAL)?;
300 let mut max_id = 0u64;
301 for result in table.iter()? {
302 let (k, _) = result?;
303 max_id = max_id.max(k.value());
304 }
305 AtomicU64::new(next_id(max_id)?)
306 };
307
308 let next_view_id = {
309 let table = read_txn.open_table(VIEWS)?;
310 let mut max_id = 0u64;
311 for result in table.iter()? {
312 let (_, value) = result?;
313 let state = deserialize_view_state(value.value())?;
314 max_id = max_id.max(state.id);
315 }
316 AtomicU64::new(next_id(max_id)?)
317 };
318
319 let next_inode = {
320 let table = read_txn.open_table(INODES)?;
321 let mut max_id = 0u64;
322 for result in table.iter()? {
323 let (k, _) = result?;
324 max_id = max_id.max(k.value());
325 }
326 AtomicU64::new(next_id(max_id)?)
327 };
328
329 Ok(Self {
330 db,
331 next_node_id,
332 next_view_id,
333 next_inode,
334 })
335 }
336
337 /// Begin a read-only transaction
338 ///

Callers

nothing calls this directly

Calls 4

deserialize_view_stateFunction · 0.85
begin_readMethod · 0.80
next_idFunction · 0.70
iterMethod · 0.45

Tested by

no test coverage detected