block-manager.rs

Overview

This file serves as the main entry point for the block manager application. It is responsible for initializing the application environment, setting up logging and panic handling, managing inter-thread communication, handling OS signals, and launching the asynchronous runtime where the core block management logic executes. The file orchestrates the startup sequence and lifecycle of the block manager, ensuring that all components are correctly initialized and any critical failures are logged and gracefully handled.


Main Components and Functions

main() -> Result<(), std::io::Error>


tokio_main(cmd_tx: mpsc::Sender<WorkerCommand>, cmd_rx: mpsc::Receiver<WorkerCommand>) -> anyhow::Result<()>


Important Implementation Details


Interaction With Other Parts of the System


Visual Diagram: Structure and Workflow

flowchart TD
A["main()"] --> B[Load .env & Init Tracing]
B --> C[Set Panic Hook]
C --> D["Create mpsc channel (cmd_tx, cmd_rx)"]
D --> E["Initialize Signals (init_signals)"]
E --> F[Spawn "tokio_main" Thread]
F --> G["tokio_main() - Async Runtime"]
G --> H["block_manager::executor::execute()"]
E --> I[Signal Handler Thread]
F --> J[Join Tokio Thread]
I --> K[Join Signal Handler Thread]
J --> L{Thread Panic?}
K --> M{Thread Panic?}
L -->|Yes| N["Log Error & exit(1)"]
M -->|Yes| O["Log Error & exit(2)"]
L -->|No| P["exit(0)"]
M -->|No| P

Summary of Key Entities

Entity

Description

WorkerCommand

Enum representing commands for worker threads.

Args

CLI arguments parsed from user input.

init_signals()

Function setting up OS signal handlers.

execute()

Async function executing block manager logic.

cmd_tx, cmd_rx

Channels for inter-thread command communication.


For more information on asynchronous Rust programming and channels, see Asynchronous Programming and Channels & Message Passing. For details on signal handling in Rust, refer to Signal Handling. For logging and tracing, consult Logging & Tracing.