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

Method from_existing

src/models/wal.rs:117–140  ·  view source on GitHub ↗
(root_path: &Path, version: VersionNumber)

Source from the content-addressed store, hash-verified

115 }
116
117 pub fn from_existing(root_path: &Path, version: VersionNumber) -> Result<Self, BufIoError> {
118 let file_path: Arc<Path> = root_path.join(format!("{}.wal", *version)).into();
119
120 let mut file = OpenOptions::new().read(true).open(&file_path)?;
121
122 let bufman = FilelessBufferManager::from_file(&mut file, 8192)?;
123 let cursor = bufman.open_cursor()?;
124 let records_upserted = bufman.read_u32_with_cursor(cursor)?;
125 let records_deleted = bufman.read_u32_with_cursor(cursor)?;
126 let total_operations = bufman.read_u32_with_cursor(cursor)?;
127 bufman.seek_with_cursor(cursor, 0)?;
128 bufman.update_u32_with_cursor(cursor, records_upserted)?;
129 bufman.update_u32_with_cursor(cursor, records_deleted)?;
130 bufman.update_u32_with_cursor(cursor, total_operations)?;
131
132 Ok(Self {
133 bufman,
134 cursor,
135 read_lock: Mutex::new(()),
136 records_upserted: AtomicU32::new(records_upserted),
137 records_deleted: AtomicU32::new(records_deleted),
138 total_operations: AtomicU32::new(total_operations),
139 })
140 }
141
142 pub fn records_upserted(&self) -> u32 {
143 self.records_upserted.load(Ordering::Relaxed)

Callers

nothing calls this directly

Calls 5

open_cursorMethod · 0.80
read_u32_with_cursorMethod · 0.80
seek_with_cursorMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected