Skip to main content

SequentialReadBuffer

Struct SequentialReadBuffer 

Source
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

Source

pub fn new() -> Self

Create a new empty buffer with default 8-slot prefetch window

Source

pub fn with_prefetch_window(prefetch_window: usize) -> Self

Create buffer with custom prefetch window (for testing)

Source

pub fn get(&self, node_id: NativeNodeId) -> Option<&NodeRecordV2>

Get node from buffer, returns None if not cached

Source

pub fn contains(&self, node_id: NativeNodeId) -> bool

Check if node is in buffer

Source

pub fn len(&self) -> usize

Get number of nodes currently cached

Source

pub fn is_empty(&self) -> bool

Check if buffer is empty

Source

pub fn insert_batch(&mut self, nodes: Vec<NodeRecordV2>)

Insert a batch of decoded nodes into buffer

Source

pub fn insert(&mut self, node: NodeRecordV2)

Insert a single node into buffer

Source

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 operations
  • start_node_id: First node ID to prefetch
§Errors

Returns error if batch read fails (file I/O, decoding errors)

Source

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 operations
  • start_node_id: First node ID to prefetch
§How it works
  1. First calls prefetch_from() to get node slots with cluster metadata
  2. For each buffered node with non-zero cluster offsets, prefetches cluster data
  3. For non-sequential clusters (typical case), does individual prefetches but caches them
  4. 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)

Source

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 cached
  • None if cluster not in cache (caller should fall back to file I/O)
Source

pub fn has_cluster(&self, cluster_offset: u64) -> bool

Check if cluster data is cached

§Parameters
  • cluster_offset: The file offset of the cluster (from NodeRecordV2)
§Returns
  • true if cluster is cached, false otherwise
Source

pub fn cluster_cache_len(&self) -> usize

Get the number of clusters currently cached (for testing)

Source

pub fn next_prefetch_start(&self) -> Option<NativeNodeId>

Get the next prefetch start ID (for testing/monitoring)

Source

pub fn prefetch_window(&self) -> usize

Get the current prefetch window size (for testing)

Source

pub fn clear(&mut self)

Clear all cached nodes and clusters

Trait Implementations§

Source§

impl Default for SequentialReadBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V