repository.rs

Overview

This file implements the management and lifecycle of BlockState instances through the BlockStateRepository. It provides facilities for loading, caching, saving, and accessing block state data identified by BlockIdentifier. The key responsibility is to maintain a weakly referenced cache of block states, preventing duplication and enabling efficient state sharing across the system. The file also defines the BlockState wrapper struct that encapsulates shared ownership and deferred saving logic for individual block states.

Core Structures

BlockState

A cloneable handle representing the state of a particular block in the system.

BlockStateRepository

Manages a collection of BlockState objects and provides access, caching, and persistence support.

Important Implementation Details

Interaction With Other Modules

Diagram: Structure of repository.rs

classDiagram
class BlockState {
+block_identifier: BlockIdentifier
+inner: Arc<BlockStateInner>
+save_sender: Arc<InstrumentedSender>
+block_identifier()
+drop()
}
class BlockStateRepository {
+block_state_repo_data_dir: PathBuf
+map: Arc<RwLock<WeakValueHashMap<BlockIdentifier, Weak<BlockStateInner>>>>
+notifications: Notification
+save_service_sender: Arc<InstrumentedSender>
+new()
+get()
+notifications()
+touch()
}
BlockStateRepository "1" *-- "*" BlockState : manages >
BlockState "1" *-- "1" BlockStateInner : owns >
BlockStateRepository "1" o-- "1" Notification : holds >
BlockStateRepository "1" o-- "1" InstrumentedSender : holds >
BlockState "1" o-- "1" InstrumentedSender : holds >

This diagram shows the main entities and their relationships: the BlockStateRepository manages multiple BlockState instances, each wrapping a shared BlockStateInner. Both BlockState and BlockStateRepository hold references to a shared InstrumentedSender for saving state asynchronously. The repository also maintains a notification mechanism.


Note: For further details on the BlockIdentifier type and state internals, see the BlockIdentifier and BlockStateInner topics. For the notification mechanism, refer to Notification. The asynchronous saving mechanism is detailed under [InstrumentedSender and MPSC Channels](/instrumented-sender).