MCPcopy Create free account
hub / github.com/carsonpo/haystackdb / load_node

Method load_node

src/structures/mmap_tree/storage.rs:231–314  ·  view source on GitHub ↗
(&mut self, offset: usize)

Source from the content-addressed store, hash-verified

229 }
230
231 pub fn load_node(&mut self, offset: usize) -> io::Result<Node<K, V>> {
232 let original_offset = offset.clone();
233 let mut offset = offset.clone();
234
235 // println!("Loading node at offset: {}", offset);
236
237 let mut serialized = Vec::new();
238
239 let mut is_primary;
240
241 let mut serialized_len;
242
243 let mut bytes_read = 0;
244
245 self.acquire_block_lock(original_offset)?;
246
247 loop {
248 let block_is_primary =
249 u8::from_le_bytes(self.read_from_offset(offset, 1).try_into().unwrap());
250
251 if block_is_primary == 0 {
252 is_primary = false;
253 } else if block_is_primary == 1 {
254 is_primary = true;
255 } else {
256 return Err(io::Error::new(
257 io::ErrorKind::InvalidData,
258 "Invalid block type",
259 ));
260 }
261
262 if !is_primary && bytes_read == 0 {
263 return Err(io::Error::new(
264 io::ErrorKind::InvalidData,
265 "Primary block not found",
266 ));
267 }
268
269 offset += 1; // one for the primary byte
270
271 serialized_len = usize::from_le_bytes(
272 self.read_from_offset(offset, SIZE_OF_USIZE)
273 .try_into()
274 .unwrap(),
275 );
276
277 offset += SIZE_OF_USIZE;
278
279 // println!("Serialized len: {}", serialized_len);
280
281 let bytes_to_read = std::cmp::min(serialized_len - bytes_read, BLOCK_DATA_SIZE);
282 // println!(
283 // "Bytes read: {}, bytes to read: {}",
284 // bytes_read, bytes_to_read
285 // );
286
287 bytes_read += bytes_to_read;
288

Callers 9

insertMethod · 0.80
insert_non_fullMethod · 0.80
search_nodeMethod · 0.80
has_key_nodeMethod · 0.80
get_range_nodeMethod · 0.80
batch_insertMethod · 0.80
find_entrypointMethod · 0.80
test_store_and_load_nodeFunction · 0.80

Calls 4

cloneMethod · 0.80
acquire_block_lockMethod · 0.80
read_from_offsetMethod · 0.80
release_block_lockMethod · 0.80

Tested by 2

test_store_and_load_nodeFunction · 0.64