Expand description
Peer connection management.
Manages Redis connections to peer nodes with automatic reconnection, circuit breaker protection, and Merkle root caching.
§Connection Lifecycle
Disconnected → Connecting → Connected
↑ ↓ ↓
└─── Backoff ←┴─────────────┘Connections are lazy: they’re only established when first needed
(via PeerConnection::ensure_connected()). If a connection fails,
the peer enters PeerState::Backoff state with exponential backoff.
§Circuit Breaker
Each peer has a circuit breaker to prevent cascade failures:
- Closed: Normal operation, requests pass through
- Open: Too many consecutive failures, requests rejected immediately
The circuit opens after circuit_failure_threshold consecutive failures
and resets after circuit_reset_timeout_sec seconds.
§Merkle Root Caching
To reduce load during cold path repair, Merkle roots are cached for
5 seconds (see MERKLE_ROOT_CACHE_TTL). This prevents hammering peers
when checking consistency.
§Example
use replication_engine::peer::PeerConnection;
use replication_engine::config::PeerConfig;
let config = PeerConfig::for_testing("peer-1", "redis://localhost:6379");
let peer = PeerConnection::new(config);
// Connection is lazy - this triggers the actual connect
peer.ensure_connected().await?;
// Use the connection
let conn = peer.connection().await;Structs§
- Peer
Connection - A managed connection to a peer’s Redis.
- Peer
Manager - Manager for all peer connections.
Enums§
- Peer
Circuit State - Circuit breaker state for peer connections.
- Peer
State - State of a peer connection.