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

Method scan_ids

atomic-core/src/pristine/txn/pristine.rs:239–279  ·  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

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

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