Skip to main content

UrlUploadPipeline

UrlUploadPipeline is an abstract class designed to handle uploads using URL-based storage adapters (UrlStorageAdapter). Unlike HashUploadPipeline, this pipeline assumes that the delta plan (which chunks to upload or delete) is calculated externally and provided to the pipeline.

This pipeline is commonly used for remote storage systems where each chunk has a dedicated URL for upload or deletion.


Constructor

ParameterTypeDescription
storageArc<dyn UrlStorageAdapter>Url based storage adapter that will be used (automatically created by client).
configArc<RacDeltaConfig>Base client configuration.

Methods

MethodReturnsDescription
execute(local_index, urls, options)Result<RDIndex, PipelineError>Performs a full upload process for given urls.
upload_missing_chunks(upload_urls, options)Result<(), PipelineError>Uploads the chunks defined in uploadUrls.
upload_index(index, upload_url)Result<(), PipelineError>Uploads the RDIndex file to the given url.
delete_obsolete_chunks(delete_urls, options)Result<(), PipelineError>Deletes obsolete chunks from the storage as specified by urls.
update_progress(value, phase, speed, options)()Optional method that calls the progress callback in options.
change_state(state, options)()Optional method that calls the change_state callback in options.

UploadOptions

The UploadOptions object allows you to customize the behavior of an upload:

pub struct UploadOptions {
pub force: Option<bool>,
pub require_remote_index: Option<bool>,
pub ignore_patterns: Option<Vec<String>>,
pub on_progress: Option<Arc<dyn Fn(UploadPhase, f64, Option<f64>) + Send + Sync>>,
pub on_state_change: Option<Arc<dyn Fn(UploadState) + Send + Sync>>,
}
PropertyTypeDescription
forceOption<bool>If true, forces complete upload even if remote index exists. If false, only new and modified chunks will be uploaded.
require_remote_indexOption<bool>If true and no remote index found, abort upload. If false (default), uploads everything if no remote index found.
ignore_patternsOption<Vec<String>>Files or directories that must be ignored when creating the rd-index.json.
on_progressOption<Arc<dyn Fn(UploadPhase, f64, Option<f64>) + Send + Sync>>Optional callback to inform progress.
on_state_changeOption<Arc<dyn Fn(UploadState) + Send + Sync>>Optional callback for state changes.
pub enum UploadState {
Uploading,
Comparing,
Cleaning,
Finalizing,
Scanning,
}

pub enum UploadPhase {
Upload,
Deleting,
}

PipelineError

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

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

#[error("Delta error: {0}")]
Delta(String),

#[error("Storage error: {0}")]
Storage(String),

#[error("Index error: {0}")]
Index(String),

#[error("Invalid argument: {0}")]
InvalidArgument(String),

#[error("Operation aborted")]
Aborted,

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

Method details

execute(local_index, urls, options)

Performs the full upload process using the provided URLs for chunks and index.

Parameters

NameTypeDescription
local_indexRDIndexThe local rd-index needed to sync, required as user should have already compared both.
urls.upload_urlsHashMap<String, ChunkUrlInfo>The urls identified by hash to upload chunks. See ChunkUrlInfo below.
urls.delete_urlsOption<Vec<String>>The urls to delete remote obsolete chunks.
urls.index_urlStringThe url to upload the new rd-index.json.
optionsOption<UploadOptions>Options for the upload process. See UploadOptions above.
pub struct ChunkUrlInfo {
pub url: String,
pub offset: u64,
pub size: u64,
pub file_path: String,
}

See ChunkUrlInfo

Returns

Result<RDIndex, PipelineError>


upload_missing_chunks(upload_urls, options)

Uploads all missing chunks to their respective URLs. Chunks are read from disk based on the paths specified in ChunkUrlInfo.

Parameters

NameTypeDescription
upload_urlsHashMap<String, ChunkUrlInfo>The urls identified by hash to upload chunks. See ChunkUrlInfo.
optionsOption<UploadOptions>Options for the upload process. See UploadOptions above.

Returns

Result<(), PipelineError>


upload_index(index, upload_url)

Uploads the RDIndex file to the specified URL.

Parameters

NameTypeDescription
index&RDIndexThe index object to upload.
upload_url&strUrl to upload index.

Returns

Result<(), PipelineError>


delete_obsolete_chunks(delete_urls, options)

Deletes obsolete chunks from the remote storage using their URLs. Includes retry logic and progress tracking.

Parameters

NameTypeDescription
delete_urlsVec<String>The urls list to delete.
optionsOption<UploadOptions>Options for the upload process. See UploadOptions above.

Returns

Promise<void>

update_progress(value, phase, speed, options)

Method that will be internally used to call given on_progress callback in options.

Parameters

NameTypeDescription
valuef64Value of the progress.
phaseUploadPhaseCurrent upload phase (downloading or deleting).
speedOption<f64>Speed in bytes/s for uploading phase.
optionsOption<&UploadOptions>Options that must include the on_progress callback.

Returns ()


change_state(state, options)

Method that will be internally used to call given on_state_change callback in options.

Parameters

NameTypeDescription
stateUploadStateCurrent state of the progress.
optionsOption<&UploadOptions>Options that must include the on_state_change callback.

Returns ()