Configuration class for managing multiple database connections in a resilient and fail-safe manner. Attributes: databases_config: A list of database configurations. client_class: The client class used to manage database connections. command_retry: Retry strategy for
| 95 | |
| 96 | @dataclass |
| 97 | class MultiDbConfig: |
| 98 | """ |
| 99 | Configuration class for managing multiple database connections in a resilient and fail-safe manner. |
| 100 | |
| 101 | Attributes: |
| 102 | databases_config: A list of database configurations. |
| 103 | client_class: The client class used to manage database connections. |
| 104 | command_retry: Retry strategy for executing database commands. |
| 105 | failure_detectors: Optional list of additional failure detectors for monitoring database failures. |
| 106 | min_num_failures: Minimal count of failures required for failover |
| 107 | failure_rate_threshold: Percentage of failures required for failover |
| 108 | failures_detection_window: Time interval for tracking database failures. |
| 109 | health_checks: Optional list of additional health checks performed on databases. |
| 110 | health_check_interval: Time interval for executing health checks. |
| 111 | health_check_probes: Number of attempts to evaluate the health of a database. |
| 112 | health_check_delay: Delay between health check attempts. |
| 113 | health_check_timeout: Timeout for the full health check operation (including all probes). |
| 114 | health_check_policy: Policy for determining database health based on health checks. |
| 115 | failover_strategy: Optional strategy for handling database failover scenarios. |
| 116 | failover_attempts: Number of retries allowed for failover operations. |
| 117 | failover_delay: Delay between failover attempts. |
| 118 | auto_fallback_interval: Time interval to trigger automatic fallback. |
| 119 | event_dispatcher: Interface for dispatching events related to database operations. |
| 120 | initial_health_check_policy: Defines the policy used to determine whether the databases setup is |
| 121 | healthy during the initial health check. |
| 122 | |
| 123 | Methods: |
| 124 | databases: |
| 125 | Retrieves a collection of database clients managed by weighted configurations. |
| 126 | Initializes database clients based on the provided configuration and removes |
| 127 | redundant retry objects for lower-level clients to rely on global retry logic. |
| 128 | |
| 129 | default_failure_detectors: |
| 130 | Returns the default list of failure detectors used to monitor database failures. |
| 131 | |
| 132 | default_health_checks: |
| 133 | Returns the default list of health checks used to monitor database health |
| 134 | with specific retry and backoff strategies. |
| 135 | |
| 136 | default_failover_strategy: |
| 137 | Provides the default failover strategy used for handling failover scenarios |
| 138 | with defined retry and backoff configurations. |
| 139 | """ |
| 140 | |
| 141 | databases_config: List[DatabaseConfig] |
| 142 | client_class: Type[Union[Redis, RedisCluster]] = Redis |
| 143 | command_retry: Retry = Retry( |
| 144 | backoff=ExponentialWithJitterBackoff( |
| 145 | base=DEFAULT_RETRY_BASE, cap=DEFAULT_RETRY_CAP |
| 146 | ), |
| 147 | retries=DEFAULT_RETRY_COUNT, |
| 148 | ) |
| 149 | failure_detectors: Optional[List[FailureDetector]] = None |
| 150 | min_num_failures: int = DEFAULT_MIN_NUM_FAILURES |
| 151 | failure_rate_threshold: float = DEFAULT_FAILURE_RATE_THRESHOLD |
| 152 | failures_detection_window: float = DEFAULT_FAILURES_DETECTION_WINDOW |
| 153 | health_checks: Optional[List[HealthCheck]] = None |
| 154 | health_check_interval: float = DEFAULT_HEALTH_CHECK_INTERVAL |