Skip to main content

ChunkTreeCache

Struct ChunkTreeCache 

Source
pub struct ChunkTreeCache { /* private fields */ }
Expand description

Cache of chunk tree mappings for resolving logical to physical addresses.

Keyed by logical start address. Uses a BTreeMap for efficient range lookups.

Implementations§

Source§

impl ChunkTreeCache

Source

pub fn insert(&mut self, mapping: ChunkMapping)

Insert a chunk mapping into the cache.

Source

pub fn lookup(&self, logical: u64) -> Option<&ChunkMapping>

Look up the chunk mapping that contains the given logical address.

Source

pub fn resolve(&self, logical: u64) -> Option<(u64, u64)>

Resolve a logical address to (devid, physical) for the first stripe.

For read-only access the first stripe is sufficient on SINGLE, DUP, and any mirroring profile. RAID0/5/6/10 striping would need stripe index calculation, but for tree blocks (always nodesize <= stripe_len) the whole block lives in one stripe slot, so this works for the common case.

Callers using a multi-device BlockReader look up the device handle by devid; single-device callers ignore it.

Source

pub fn resolve_all(&self, logical: u64) -> Option<Vec<(u64, u64)>>

Resolve a logical address to (devid, physical) for every stripe.

For DUP, RAID1, RAID1C3, and RAID1C4, a single logical address maps to multiple physical copies. Write operations must update all copies to maintain consistency.

Use plan_write for actual write routing. resolve_all ignores the chunk’s RAID profile and assumes every stripe should receive the same bytes; that is correct for DUP / RAID1* but wrong for RAID0 (each row goes to one device only) and RAID10 (each row goes to one mirror pair, not all pairs). Kept for diagnostics and read-only callers that only need a list of stripe locations.

Source

pub fn plan_write(&self, logical: u64, len: usize) -> Option<WritePlan>

Plan the per-device writes needed to land len bytes at the logical address logical, accounting for the chunk’s RAID profile and stripe length.

Returns a WritePlan: a Plain variant (a flat vec of StripePlacements) for non-parity profiles, and a Parity variant (ParityPlan) for RAID5/RAID6.

Per-profile fan-out for a single row of a non-parity profile:

  • SINGLE: one placement (column 0).
  • DUP / RAID1 / RAID1C3 / RAID1C4: num_stripes placements (every stripe gets the same bytes).
  • RAID0: one placement (column = stripe_nr % num_stripes).
  • RAID10: sub_stripes placements (the mirror pair for the row).

For RAID5/RAID6 the plan instead names every data column slot of every touched physical row plus the rotating parity column(s); the caller must run a parity executor that prereads the data slots, mixes in caller bytes, computes parity, then writes data

  • parity to the device.

Buffers larger than stripe_len - stripe_offset span multiple rows; each row’s placements are appended in order.

Returns None if logical is unmapped or if logical + len exceeds the chunk.

Source

pub fn plan_read( &self, logical: u64, len: usize, ) -> Option<Vec<StripePlacement>>

Plan the per-device reads needed to fetch len bytes from the logical address logical. Returns exactly one placement per row (the first stripe of each row, or the row’s data column for RAID5/RAID6) — the caller assembles the bytes in order.

Reads on RAID5/RAID6 ignore parity columns: the data column owning each row’s bytes is read directly. Degraded reads (reconstructing a missing data column from parity) are out of scope.

Returns None if logical is unmapped or if logical + len exceeds the chunk.

Source

pub fn len(&self) -> usize

Return the number of cached chunk mappings.

Source

pub fn is_empty(&self) -> bool

Return true if the cache is empty.

Source

pub fn iter(&self) -> impl Iterator<Item = &ChunkMapping>

Iterate over all chunk mappings in logical address order.

Trait Implementations§

Source§

impl Debug for ChunkTreeCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ChunkTreeCache

Source§

fn default() -> ChunkTreeCache

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> Same for T

Source§

type Output = T

Should always be Self
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.