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

Method scan_ids

atomic-core/src/pristine/txn/pristine.rs:238–278  ·  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: Database)

Source from the content-addressed store, hash-verified

236 /// skip the table-init write transaction and only need a read pass to
237 /// discover the max allocated node, view, and inode IDs.
238 fn scan_ids(db: Database) -> PristineResult<Self> {
239 let read_txn = db.begin_read()?;
240
241 let next_node_id = {
242 let table = read_txn.open_table(EXTERNAL)?;
243 let mut max_id = 0u64;
244 for result in table.iter()? {
245 let (k, _) = result?;
246 max_id = max_id.max(k.value());
247 }
248 AtomicU64::new(next_id(max_id)?)
249 };
250
251 let next_view_id = {
252 let table = read_txn.open_table(VIEWS)?;
253 let mut max_id = 0u64;
254 for result in table.iter()? {
255 let (_, value) = result?;
256 let state = deserialize_view_state(value.value())?;
257 max_id = max_id.max(state.id);
258 }
259 AtomicU64::new(next_id(max_id)?)
260 };
261
262 let next_inode = {
263 let table = read_txn.open_table(INODES)?;
264 let mut max_id = 0u64;
265 for result in table.iter()? {
266 let (k, _) = result?;
267 max_id = max_id.max(k.value());
268 }
269 AtomicU64::new(next_id(max_id)?)
270 };
271
272 Ok(Self {
273 db,
274 next_node_id,
275 next_view_id,
276 next_inode,
277 })
278 }
279
280 /// Begin a read-only transaction
281 ///

Callers

nothing calls this directly

Calls 3

deserialize_view_stateFunction · 0.85
next_idFunction · 0.70
iterMethod · 0.45

Tested by

no test coverage detected