external_fileshares_based.rs

Overview

This file implements a state synchronization mechanism for a distributed system based on external file shares. It provides functionality to save the application state for sharing and to load state snapshots from multiple external storage URLs, including distributed nodes discovered via a gossip protocol. The core component is the ExternalFileSharesBased struct, which integrates with a blob synchronization service to download state snapshots from configured static storages and dynamic sources discovered through gossip.

The file relies on concurrent task execution and synchronization primitives to manage state loading in the background. It also tracks download retries, timeouts, and error reporting during state synchronization.


Structs and Implementations

ExternalFileSharesBased

A struct that implements the StateSyncService trait to handle state synchronization using external file shares.

Fields

Methods

new(blob_sync: ServiceInterface, file_saving_service: FileSavingService, chitchat: ChitchatRef, bk_set_rx: tokio::sync::watch::Receiver<ApiBkSet>) -> Self

Creates a new instance of ExternalFileSharesBased with default retry and timeout configurations. The static storage list is initially empty.

Usage example:

let service = ExternalFileSharesBased::new(blob_sync, file_saving_service, chitchat, bk_set_rx);

Private Function: get_node_id_and_download_url_from_gossip

Parses a chitchat::NodeState entry to extract the node identifier and the URL advertised for API access.


Trait Implementation: StateSyncService for ExternalFileSharesBased

This implementation allows the struct to participate in state synchronization workflows.

Associated Types

Methods

save_state_for_sharing(&self, state: Arc<OptimisticStateImpl>) -> anyhow::Result<()>

Saves the current optimistic state to persistent storage for sharing with other nodes.

service.save_state_for_sharing(state)?;

reset_sync(&self)

Resets the synchronization process by dropping the current background state loading thread, if any.

add_load_state_task(&mut self, resource_address: BTreeMap<ThreadIdentifier, BlockIdentifier>, repository: RepositoryImpl, output: InstrumentedSender<anyhow::Result<BTreeMap<ThreadIdentifier, BlockIdentifier>>>) -> anyhow::Result<()>

Starts asynchronous tasks to load state snapshots for the specified resource addresses from external sources.

service.add_load_state_task(resource_address, repository, output_sender)?;

Important Implementation Details


Interactions with Other Parts of the System


Mermaid Diagram: ExternalFileSharesBased Structure and Workflow

classDiagram
class ExternalFileSharesBased {
+static_storages: Vec<Url>
+max_download_tries: u8
+retry_download_timeout: Duration
+download_deadline_timeout: Duration
-blob_sync: ServiceInterface
-file_saving_service: FileSavingService
-state_load_thread: Arc<Mutex<Option<JoinHandle<()>>>>
-chitchat: ChitchatRef
-bk_set_rx: tokio::sync::watch::Receiver<ApiBkSet>
+new()
+save_state_for_sharing()
+reset_sync()
+add_load_state_task()
}
class RepositoryImpl {
+get_metrics()
+set_state_from_snapshot()
}
class FileSavingService {
+save_object()
}
class ServiceInterface {
+load_blob()
}
ExternalFileSharesBased --> ServiceInterface : uses
ExternalFileSharesBased --> FileSavingService : uses
ExternalFileSharesBased --> ChitchatRef : uses
ExternalFileSharesBased --> RepositoryImpl : interacts with
ExternalFileSharesBased --> "State Load Thread" : manages
note for ExternalFileSharesBased "Downloads state snapshots\nfrom static and dynamic URLs\nand applies them to repository"

References to Related Topics