pub struct SequentialReadBuffer { /* private fields */ }Expand description
Per-traversal buffer for sequential I/O optimization
§Design
- Scoped to single traversal (evaporates when function returns)
- Prefetches 8 slots (32KB) after LinearDetector confirms linear pattern
- Stores decoded NodeRecordV2 for rapid access without re-decoding
- Caches edge cluster data to eliminate per-node cluster I/O
§MVCC Safety
Buffer is stack-allocated per traversal. No cross-traversal data sharing means no stale data across transactions.
Implementations§
Source§impl SequentialReadBuffer
impl SequentialReadBuffer
Sourcepub fn with_prefetch_window(prefetch_window: usize) -> Self
pub fn with_prefetch_window(prefetch_window: usize) -> Self
Create buffer with custom prefetch window (for testing)
Sourcepub fn get(&self, node_id: NativeNodeId) -> Option<&NodeRecordV2>
pub fn get(&self, node_id: NativeNodeId) -> Option<&NodeRecordV2>
Get node from buffer, returns None if not cached
Sourcepub fn contains(&self, node_id: NativeNodeId) -> bool
pub fn contains(&self, node_id: NativeNodeId) -> bool
Check if node is in buffer
Sourcepub fn insert_batch(&mut self, nodes: Vec<NodeRecordV2>)
pub fn insert_batch(&mut self, nodes: Vec<NodeRecordV2>)
Insert a batch of decoded nodes into buffer
Sourcepub fn insert(&mut self, node: NodeRecordV2)
pub fn insert(&mut self, node: NodeRecordV2)
Insert a single node into buffer
Sourcepub fn prefetch_from(
&mut self,
graph_file: &mut GraphFile,
start_node_id: NativeNodeId,
) -> NativeResult<()>
pub fn prefetch_from( &mut self, graph_file: &mut GraphFile, start_node_id: NativeNodeId, ) -> NativeResult<()>
Prefetch sequential slots starting from start_node_id
Reads prefetch_window slots (default 8) using NodeStore::read_slots_batch()
and caches the decoded NodeRecordV2 instances.
§Parameters
graph_file: Mutable borrow for I/O operationsstart_node_id: First node ID to prefetch
§Errors
Returns error if batch read fails (file I/O, decoding errors)
Sourcepub fn prefetch_clusters_from(
&mut self,
graph_file: &mut GraphFile,
start_node_id: NativeNodeId,
) -> NativeResult<()>
pub fn prefetch_clusters_from( &mut self, graph_file: &mut GraphFile, start_node_id: NativeNodeId, ) -> NativeResult<()>
Prefetch sequential slots AND their edge clusters starting from start_node_id
This extends prefetch_from() by also prefetching edge cluster data for all
buffered nodes. For each node with a non-zero cluster offset, the cluster data
is read and cached, eliminating per-node cluster I/O during traversal.
§Parameters
graph_file: Mutable borrow for I/O operationsstart_node_id: First node ID to prefetch
§How it works
- First calls
prefetch_from()to get node slots with cluster metadata - For each buffered node with non-zero cluster offsets, prefetches cluster data
- For non-sequential clusters (typical case), does individual prefetches but caches them
- Stores raw bytes in cluster_cache indexed by cluster_offset
§Benefits
- Chain traversals visit each node once, so prefetch happens once per node
- Buffer covers 8 nodes ahead, so cluster I/O is done in anticipation of need
- Eliminates per-node
graph_file.read_bytes(cluster_offset, ...)calls during traversal
§Errors
Returns error if batch read or cluster prefetch fails (file I/O, decoding errors)
Sourcepub fn get_cluster(&self, cluster_offset: u64) -> Option<&[u8]>
pub fn get_cluster(&self, cluster_offset: u64) -> Option<&[u8]>
Get cached cluster data by cluster_offset
Returns a reference to the cached cluster bytes if available, None if the cluster is not in the cache.
§Parameters
cluster_offset: The file offset of the cluster (from NodeRecordV2)
§Returns
Some(&[u8])if cluster is cachedNoneif cluster not in cache (caller should fall back to file I/O)
Sourcepub fn has_cluster(&self, cluster_offset: u64) -> bool
pub fn has_cluster(&self, cluster_offset: u64) -> bool
Sourcepub fn cluster_cache_len(&self) -> usize
pub fn cluster_cache_len(&self) -> usize
Get the number of clusters currently cached (for testing)
Sourcepub fn next_prefetch_start(&self) -> Option<NativeNodeId>
pub fn next_prefetch_start(&self) -> Option<NativeNodeId>
Get the next prefetch start ID (for testing/monitoring)
Sourcepub fn prefetch_window(&self) -> usize
pub fn prefetch_window(&self) -> usize
Get the current prefetch window size (for testing)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SequentialReadBuffer
impl RefUnwindSafe for SequentialReadBuffer
impl Send for SequentialReadBuffer
impl Sync for SequentialReadBuffer
impl Unpin for SequentialReadBuffer
impl UnwindSafe for SequentialReadBuffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more