Skip to main content

ClayCode

Struct ClayCode 

Source
pub struct ClayCode {
    pub k: usize,
    pub m: usize,
    pub n: usize,
    pub d: usize,
    pub q: usize,
    pub t: usize,
    pub nu: usize,
    pub sub_chunk_no: usize,
    pub beta: usize,
    /* private fields */
}
Expand description

Clay (Coupled-Layer) erasure code

Fields§

§k: usize

Number of data chunks

§m: usize

Number of parity chunks

§n: usize

Total nodes (k + m)

§d: usize

Number of helper nodes for repair (k <= d <= n-1)

§q: usize

Coupling factor: q = d - k + 1

§t: usize

Number of y-sections: t = (n + nu) / q

§nu: usize

Shortening parameter: makes (k + m + nu) divisible by q

§sub_chunk_no: usize

Sub-packetization level: α = q^t (sub-chunks per chunk)

§beta: usize

Sub-chunks needed from each helper during repair: β = α / q

Implementations§

Source§

impl ClayCode

Source

pub fn new(k: usize, m: usize, d: usize) -> Result<Self, ClayError>

Create a new Clay code with parameters (k, m, d)

§Parameters
  • k: Number of data chunks (systematic nodes)
  • m: Number of parity chunks
  • d: Number of helper nodes for repair
§Returns

Result with ClayCode or error if parameters are invalid

Source

pub fn new_default(k: usize, m: usize) -> Result<Self, ClayError>

Create with default d = k + m - 1 (maximum helpers)

Source

pub fn encode(&self, data: &[u8]) -> Vec<Vec<u8>>

Encode data into n chunks

§Parameters
  • data: Raw data bytes to encode
§Returns

Vector of n chunks, each containing α sub-chunks

Source

pub fn chunk_size(&self, data_len: usize) -> usize

Bytes in each chunk an encode of data_len bytes produces

Source

pub fn encode_into( &self, data: &[u8], chunks: &mut [&mut [u8]], ) -> Result<(), ClayError>

Encode data into n caller-owned chunks of chunk_size(data.len()) bytes each

The allocation-free form of encode: the data goes straight into the first k chunks and the parity into the last m, so a caller that encodes into its own buffers holds no second copy of the coded bytes.

Source

pub fn decode( &self, available: &HashMap<usize, Vec<u8>>, erasures: &[usize], ) -> Result<Vec<u8>, ClayError>

Decode data from available chunks

§Parameters
  • available: Map from chunk index to chunk data
  • erasures: Set of erased chunk indices
§Returns

Recovered original data, or error if decoding fails

Source

pub fn decode_rows( &self, chunks: &[Option<&[u8]>], ) -> Result<Vec<u8>, ClayError>

Recover original data from chunks indexed by node, None for erasures

The zero-copy form of decode. The caller lends the chunks it already holds instead of building a map of owned buffers. Needs exactly n slots.

Source

pub fn plan_repair( &self, lost_node: usize, available: &[usize], ) -> Result<Vec<(usize, Vec<usize>)>, ClayError>

Plan the sub-chunks that repair a lost node from the available nodes

§Parameters
  • lost_node: Index of the lost node (0 to n-1)
  • available: Nodes that can send sub-chunks, in the caller’s order of preference
§Returns

Each chosen helper with the sub-chunk indices it sends, in order.

The plan takes every available node in the lost node’s y-section and the first k available nodes of the other y-sections. With all of them available, each of the d helpers sends β sub-chunks. When a node of the lost node’s y-section is missing, the other-section helpers send β more sub-chunks each in its place. When fewer than k other-section nodes are available, the first same-section nodes in the caller’s order make up the difference by sending more sub-chunks. Each missing same-section node, and each one that makes up the difference, adds (k − 1)·β sub-chunks to the plan’s d·β. The call errors when fewer than k nodes are available.

When n isn’t a multiple of q, the code adds virtual nodes, and a y-section can hold some. A lost node whose y-section holds v virtual nodes needs every real node of its section and the first k + v available nodes of the other sections. The call errors when a real node of that section is missing or fewer than k + v other-section nodes are available.

Source

pub fn repair( &self, lost_node: usize, plan: &[(usize, Vec<usize>)], helpers: &[Option<&[u8]>], chunk_size: usize, ) -> Result<Vec<u8>, ClayError>

Repair a lost chunk from the sub-chunks a plan asked for

§Parameters
  • lost_node: Index of the lost node (0 to n-1)
  • plan: The plan plan_repair returned for this lost node
  • helpers: One slot per node. Each planned helper’s slot holds its sub-chunks concatenated in the plan’s order, and other slots are ignored.
  • chunk_size: Full chunk size
§Returns

The recovered full chunk, or error if the plan or the data don’t fit

Source

pub fn normalized_repair_bandwidth(&self) -> f64

Calculate normalized repair bandwidth

This is the ratio of data downloaded for repair to the size of the repaired chunk. For Clay codes, this is d / (k * q).

Trait Implementations§

Source§

impl Clone for ClayCode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ClayCode

Source§

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

Formats the value using the given formatter. 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.