Skip to main content

ReconstructionService

ReconstructionService defines the primary interface responsible for reconstructing files from their chunks, either on disk or as a stream.
This service communicates directly with a ChunkSource to obtain the required data and reassemble the file.

It serves as the core component of the restoration process within rac-delta.


Methods

MethodReturnsDescription
reconstruct_file(entry, output_path, chunk_source, options, cb)Result<(), ReconstructionError>Reconstruct a single file in disk.
reconstruct_all(plan, output_dir, chunk_source, options)Result<(), ReconstructionError>Reconstruct all files from a DeltaPlan in disk.
reconstruct_to_stream(entry, chunk_source)Result<Pin<Box<dyn AsyncRead + Send + Sync>>, ReconstructionError>Reconstruct a file in memory and returns it as a Readable stream.

ReconstructionError

Custom error enum for results of ReconstructionService. (Uses thiserror)

pub enum ReconstructionError {
#[error("I/O error: {0}")]
Io(#[from] std::io::Error),

#[error("Chunk '{0}' not found")]
ChunkNotFound(String),

#[error("Hash mismatch for file '{0}'")]
HashMismatch(String),

#[error("Failed to read chunk '{0}'")]
ChunkReadError(String),

#[error("Reconstruction failed: {0}")]
Other(String),
}

ReconstructionOptions

Options for the reconstruction progress:

pub struct ReconstructionOptions {
pub force_rebuild: Option<bool>,
pub verify_after_rebuild: Option<bool>,
pub in_place_reconstruction_threshold: Option<u64>,
pub file_concurrency: Option<usize>,
pub on_progress: Option<Arc<dyn Fn(f64, usize, Option<f64>, Option<usize>) + Send + Sync>>,
}
ParameterTypeDescription
force_rebuildOption<bool>Force to rebuild even if hash file matches.
verify_after_rebuildOption<bool>Verifies the reconstructed file hash after finishing. If hash does not match, an error is thrown.
in_place_reconstruction_thresholdOption<u64>Minimum file size (in bytes) required to perform an in-place reconstruction instead of using a temporary file.
file_concurrencyOption<usize>How many files will reconstruct concurrently (default value is 5).
on_progressOption<Arc<dyn Fn(f64, usize, Option<f64>, Option<usize>) + Send + Sync>>Callback that returns disk usage and optional network speed (only for storage chunk sources via streaming download-reconstruction).

Method Details

reconstruct_file(entry, output_path, chunk_source, options, cb)

Reconstruct a single file from a FileEntry in disk.

Parameters:

NameTypeDescription
entry&FileEntryThe FileEntry containing the list of chunks and path of the file.
outputPath&PathThe path where the file will be reconstructed.
chunkSource&dyn ChunkSourceThe chunk source implementation where the chunks will be retrieved.
optionsOption<&ReconstructionOptions>Options for reconstruction.
cbOption<FileProgressCallback>Optional callback for progress.
pub type FileProgressCallback = Arc<dyn Fn(f64, usize, Option<usize>) + Send + Sync>;

Returns: Result<(), ReconstructionError


reconstruct_all(plan, output_dir, chunk_source, options)

Reconstruct all files from given DeltaPlan in disk.

Parameters:

NameTypeDescription
plan&DeltaPlanThe DeltaPlan containing the files to be reconstructed.
output_dir&PathThe path where the files will be reconstructed.
chunk_sourceArc<dyn ChunkSource>The chunk source implementation where the chunks will be retrieved.
optionsOption<&ReconstructionOptions>Options for reconstruction.

Returns: Result<(), ReconstructionError>


reconstruct_to_stream(entry, chunk_source)

Reconstruct a file in memory and returns it as a stream.

Parameters:

NameTypeDescription
entryFileEntryThe FileEntry containing the list of chunks and path of the file.
chunk_sourceArc<dyn ChunkSource + Send + Sync>The chunk source implementation where the chunks will be retrieved.

Returns: Result<Pin<Box<dyn AsyncRead + Send + Sync>>, ReconstructionError>