Skip to main content

Module resilience

Module resilience 

Source
Expand description

Storage resilience wrapper with circuit breaking.

Provides circuit breaker protection for storage backends to prevent cascade failures when backends become unhealthy.

§Circuit Breaker States

+--------+     failures >= threshold     +------+
| Closed | --------------------------->  | Open |
+--------+                               +------+
    ^                                        |
    |  success                               | timeout elapsed
    |                                        v
    +--------------------------------  +-----------+
                                       | Half-Open |
                                       +-----------+

§Usage

ⓘ
use subcog::storage::resilience::{StorageResilienceConfig, ResilientPersistenceBackend};
use subcog::storage::index::SqliteBackend;

let backend = SqliteBackend::new(db_path)?;
let config = StorageResilienceConfig::default();
let resilient = ResilientPersistenceBackend::new(backend, config, "sqlite");

// Operations are now protected by circuit breaker
resilient.store(&memory)?;

Structs§

CircuitBreaker
Circuit breaker for storage backends.
ResilientIndexBackend
Index backend wrapper with circuit breaker and retry protection.
ResilientPersistenceBackend
Persistence backend wrapper with circuit breaker and retry protection.
ResilientVectorBackend
Vector backend wrapper with circuit breaker and retry protection.
StorageResilienceConfig
Resilience configuration for storage backends.

Enums§

BreakerState 🔒
Circuit breaker state machine.

Functions§

calculate_jitter 🔒
Calculates jitter for retry backoff using system time as pseudo-random source.
calculate_retry_delay 🔒
Calculates retry delay with exponential backoff and jitter.
is_retryable_connection_error 🔒
Checks if a connection error is retryable.
is_retryable_storage_error
Checks if a storage error is retryable (transient failures that may succeed on retry).
retry_connection
Executes a connection operation with retry and exponential backoff.