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: usizeNumber of data chunks
m: usizeNumber of parity chunks
n: usizeTotal nodes (k + m)
d: usizeNumber of helper nodes for repair (k <= d <= n-1)
q: usizeCoupling factor: q = d - k + 1
t: usizeNumber of y-sections: t = (n + nu) / q
nu: usizeShortening parameter: makes (k + m + nu) divisible by q
sub_chunk_no: usizeSub-packetization level: α = q^t (sub-chunks per chunk)
beta: usizeSub-chunks needed from each helper during repair: β = α / q
Implementations§
Source§impl ClayCode
impl ClayCode
Sourcepub fn new_default(k: usize, m: usize) -> Result<Self, ClayError>
pub fn new_default(k: usize, m: usize) -> Result<Self, ClayError>
Create with default d = k + m - 1 (maximum helpers)
Sourcepub fn chunk_size(&self, data_len: usize) -> usize
pub fn chunk_size(&self, data_len: usize) -> usize
Bytes in each chunk an encode of data_len bytes produces
Sourcepub fn encode_into(
&self,
data: &[u8],
chunks: &mut [&mut [u8]],
) -> Result<(), ClayError>
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.
Sourcepub fn decode(
&self,
available: &HashMap<usize, Vec<u8>>,
erasures: &[usize],
) -> Result<Vec<u8>, ClayError>
pub fn decode( &self, available: &HashMap<usize, Vec<u8>>, erasures: &[usize], ) -> Result<Vec<u8>, ClayError>
Sourcepub fn decode_rows(
&self,
chunks: &[Option<&[u8]>],
) -> Result<Vec<u8>, ClayError>
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.
Sourcepub fn plan_repair(
&self,
lost_node: usize,
available: &[usize],
) -> Result<Vec<(usize, Vec<usize>)>, ClayError>
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.
Sourcepub fn repair(
&self,
lost_node: usize,
plan: &[(usize, Vec<usize>)],
helpers: &[Option<&[u8]>],
chunk_size: usize,
) -> Result<Vec<u8>, ClayError>
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 planplan_repairreturned for this lost nodehelpers: 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
Sourcepub fn normalized_repair_bandwidth(&self) -> f64
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).