pub struct PartitionDriver { /* private fields */ }Expand description
Workflow driver that encodes the correct SF-style lifecycle sequences
for a partition. Operates on ReplicaHandle trait objects — agnostic
to whether replicas are in-process or remote.
Mirrors StatefulServicePartitionDriver from service-fabric-rs.
Implementations§
Source§impl PartitionDriver
impl PartitionDriver
pub fn new() -> Self
pub fn primary_id(&self) -> Option<ReplicaId>
pub fn epoch(&self) -> Epoch
pub fn replica_ids(&self) -> Vec<ReplicaId> ⓘ
pub fn handle(&self, id: ReplicaId) -> Option<&dyn ReplicaHandle>
Sourcepub fn remove_replica_from_driver(
&mut self,
id: ReplicaId,
) -> Option<Box<dyn ReplicaHandle>>
pub fn remove_replica_from_driver( &mut self, id: ReplicaId, ) -> Option<Box<dyn ReplicaHandle>>
Remove a replica from the driver’s tracking without notifying the primary’s replicator. Used when the reconciler detects a pod is permanently dead before failover. Returns the handle for cleanup.
Sourcepub async fn create_partition(
&mut self,
handles: Vec<Box<dyn ReplicaHandle>>,
) -> Result<()>
pub async fn create_partition( &mut self, handles: Vec<Box<dyn ReplicaHandle>>, ) -> Result<()>
Create a partition from pre-created replica handles. The first handle becomes primary; the rest become secondaries.
Follows the exact SF workflow:
- Open all replicators
- Assign primary role (replicator first)
- Assign idle role to secondaries
- build_replica for each secondary
- Promote each secondary to active
- Update configuration incrementally
- Set access status
Sourcepub async fn delete_partition(&mut self) -> Result<()>
pub async fn delete_partition(&mut self) -> Result<()>
Gracefully shut down all replicas.
Sourcepub async fn failover(&mut self, failed_primary_id: ReplicaId) -> Result<()>
pub async fn failover(&mut self, failed_primary_id: ReplicaId) -> Result<()>
Failover after the primary has failed. The failed primary’s handle may be unreachable — the driver does not call it.
Matches SF’s reconfiguration phases:
- Remove failed primary, increment epoch
- Select new primary by highest current_progress (Phase 1: GetLSN)
- Promote new primary with new epoch (Phase 4: Activate)
- Reconfigure quorum — epoch distributed to secondaries as part of the new configuration (best-effort, skip unreachable)
Sourcepub async fn switchover(&mut self, target_id: ReplicaId) -> Result<()>
pub async fn switchover(&mut self, target_id: ReplicaId) -> Result<()>
Graceful primary change to a specific target secondary.
Matches SF’s SwapPrimary reconfiguration:
- Revoke write status on old primary (SF Phase 0: Demote)
- Demote old primary → ActiveSecondary
- Promote target → Primary (SF Phase 4: Activate)
- Distribute epoch to other secondaries (best-effort)
- Reconfigure quorum + catchup
Sourcepub async fn remove_secondary(
&mut self,
secondary_id: ReplicaId,
min_replicas: usize,
) -> Result<()>
pub async fn remove_secondary( &mut self, secondary_id: ReplicaId, min_replicas: usize, ) -> Result<()>
Remove a secondary from the partition. Config-first: the configuration is updated before the replica is closed, maintaining write quorum.
- Verify not removing primary, and above min count
- Reconfigure without the target replica
- Change role to None + close the removed replica
- Remove from driver
Sourcepub async fn add_replica(
&mut self,
handle: Box<dyn ReplicaHandle>,
) -> Result<()>
pub async fn add_replica( &mut self, handle: Box<dyn ReplicaHandle>, ) -> Result<()>
Add a new replica to the partition. The primary builds it via the copy protocol, then it joins the quorum configuration.
Used for:
- Scale-up: operator creates a new pod, calls add_replica
- Restart: restart_secondary calls this after closing the old handle
Flow:
- Open + set epoch + assign idle role
- build_replica on primary (copies state via data plane)
- Promote idle → active
- Reconfigure quorum (must_catch_up on the new replica)
Sourcepub async fn restart_secondary(
&mut self,
secondary_id: ReplicaId,
new_handle: Box<dyn ReplicaHandle>,
) -> Result<()>
pub async fn restart_secondary( &mut self, secondary_id: ReplicaId, new_handle: Box<dyn ReplicaHandle>, ) -> Result<()>
Restart a secondary replica. The old handle is replaced with a new one (simulating pod restart with fresh state). The primary rebuilds it via the copy protocol.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for PartitionDriver
impl !RefUnwindSafe for PartitionDriver
impl Send for PartitionDriver
impl Sync for PartitionDriver
impl Unpin for PartitionDriver
impl UnsafeUnpin for PartitionDriver
impl !UnwindSafe for PartitionDriver
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request