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