pub struct FailoverController { /* private fields */ }Expand description
Failover Controller
Implementations§
Source§impl FailoverController
impl FailoverController
Sourcepub fn new(config: FailoverConfig) -> Self
pub fn new(config: FailoverConfig) -> Self
Create a new failover controller
Sourcepub fn with_backend_template(self, template: BackendConfig) -> Self
pub fn with_backend_template(self, template: BackendConfig) -> Self
Attach a backend-connection template so sync-wait and promotion can actually run SQL against the candidate.
Sourcepub async fn set_primary(&self, node_id: NodeId)
pub async fn set_primary(&self, node_id: NodeId)
Set the current primary
Sourcepub async fn get_primary(&self) -> Option<NodeId>
pub async fn get_primary(&self) -> Option<NodeId>
Get the current primary
Sourcepub async fn register_candidate(&self, candidate: FailoverCandidate)
pub async fn register_candidate(&self, candidate: FailoverCandidate)
Register a failover candidate (standby)
Sourcepub async fn remove_candidate(&self, node_id: &NodeId)
pub async fn remove_candidate(&self, node_id: &NodeId)
Remove a failover candidate
Sourcepub async fn update_candidate_lag(&self, node_id: &NodeId, lag_bytes: u64)
pub async fn update_candidate_lag(&self, node_id: &NodeId, lag_bytes: u64)
Update candidate lag
Sourcepub async fn state(&self) -> FailoverState
pub async fn state(&self) -> FailoverState
Get current state
Sourcepub async fn on_primary_failed(&self, node_id: NodeId) -> Result<()>
pub async fn on_primary_failed(&self, node_id: NodeId) -> Result<()>
Handle primary failure
Sourcepub async fn initiate_failover(&self) -> Result<()>
pub async fn initiate_failover(&self) -> Result<()>
Initiate failover to best candidate
Sourcepub async fn on_old_primary_recovered(&self, node_id: NodeId)
pub async fn on_old_primary_recovered(&self, node_id: NodeId)
Handle old primary recovery (split-brain prevention).
PostgreSQL has no built-in “demote the current primary” command —
re-joining as a standby requires stopping the process and
re-initialising (pg_rewind or pg_basebackup). This method
therefore cannot fully automate demotion. What it CAN do:
- Connect to the recovered node and verify whether it still
believes it is the primary (
pg_is_in_recovery() = false). - Emit
OldPrimaryRecoveredso operators (or an external orchestrator like Patroni / pg_auto_failover) can react.
This is deliberately read-only. Rewriting WAL on a live cluster without operator oversight is the canonical way to lose data; the proxy refuses to do it.
Sourcepub async fn manual_failover(&self, target: NodeId) -> Result<()>
pub async fn manual_failover(&self, target: NodeId) -> Result<()>
Manual failover to specific node
Sourcepub fn failover_count(&self) -> u64
pub fn failover_count(&self) -> u64
Get failover count
Sourcepub async fn history(&self) -> Vec<FailoverHistoryEntry>
pub async fn history(&self) -> Vec<FailoverHistoryEntry>
Get failover history
Sourcepub fn take_event_receiver(&mut self) -> Option<Receiver<FailoverEvent>>
pub fn take_event_receiver(&mut self) -> Option<Receiver<FailoverEvent>>
Take the event receiver
Sourcepub async fn coordinate_failover_replay(
&self,
journal: &TransactionJournal,
failed_node: NodeId,
new_primary_endpoint: &NodeEndpoint,
) -> Result<CoordinatedReplayResult>
pub async fn coordinate_failover_replay( &self, journal: &TransactionJournal, failed_node: NodeId, new_primary_endpoint: &NodeEndpoint, ) -> Result<CoordinatedReplayResult>
Coordinate transaction replay after failover (TR integration)
This method orchestrates the replay of in-flight transactions on a new primary after a failover event. It ensures transaction atomicity by:
- Getting all active transactions from the journal that were on the failed node
- Waiting for the new primary to catch up to the required LSN
- Replaying each transaction’s statements on the new primary
- Verifying results match the original execution (via checksums)
Auto Trait Implementations§
impl !Freeze for FailoverController
impl !RefUnwindSafe for FailoverController
impl Send for FailoverController
impl Sync for FailoverController
impl Unpin for FailoverController
impl UnsafeUnpin for FailoverController
impl !UnwindSafe for FailoverController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more