Skip to main content

PartitionDriver

Struct PartitionDriver 

Source
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

Source

pub fn new() -> Self

Source

pub fn primary_id(&self) -> Option<ReplicaId>

Source

pub fn epoch(&self) -> Epoch

Source

pub fn replica_ids(&self) -> Vec<ReplicaId>

Source

pub fn handle(&self, id: ReplicaId) -> Option<&dyn ReplicaHandle>

Source

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.

Source

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:

  1. Open all replicators
  2. Assign primary role (replicator first)
  3. Assign idle role to secondaries
  4. build_replica for each secondary
  5. Promote each secondary to active
  6. Update configuration incrementally
  7. Set access status
Source

pub async fn delete_partition(&mut self) -> Result<()>

Gracefully shut down all replicas.

Source

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:

  1. Remove failed primary, increment epoch
  2. Select new primary by highest current_progress (Phase 1: GetLSN)
  3. Promote new primary with new epoch (Phase 4: Activate)
  4. Reconfigure quorum — epoch distributed to secondaries as part of the new configuration (best-effort, skip unreachable)
Source

pub async fn switchover(&mut self, target_id: ReplicaId) -> Result<()>

Graceful primary change to a specific target secondary.

Matches SF’s SwapPrimary reconfiguration:

  1. Revoke write status on old primary (SF Phase 0: Demote)
  2. Demote old primary → ActiveSecondary
  3. Promote target → Primary (SF Phase 4: Activate)
  4. Distribute epoch to other secondaries (best-effort)
  5. Reconfigure quorum + catchup
Source

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.

  1. Verify not removing primary, and above min count
  2. Reconfigure without the target replica
  3. Change role to None + close the removed replica
  4. Remove from driver
Source

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:

  1. Open + set epoch + assign idle role
  2. build_replica on primary (copies state via data plane)
  3. Promote idle → active
  4. Reconfigure quorum (must_catch_up on the new replica)
Source

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§

Source§

impl Default for PartitionDriver

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more