pub struct DistributedStateManager { /* private fields */ }Expand description
The main distributed state manager that coordinates state across stream processors.
Provides:
- Periodic state checkpointing via operator snapshots
- Exactly-once semantics via sequence-number deduplication
- State migration when processors join or leave the cluster
Implementations§
Source§impl DistributedStateManager
impl DistributedStateManager
Sourcepub fn new(
node_id: impl Into<String>,
checkpoint_config: CheckpointConfig,
dedup_config: DeduplicationConfig,
) -> Self
pub fn new( node_id: impl Into<String>, checkpoint_config: CheckpointConfig, dedup_config: DeduplicationConfig, ) -> Self
Creates a new distributed state manager.
Sourcepub fn register_processor(&self, node_id: impl Into<String>)
pub fn register_processor(&self, node_id: impl Into<String>)
Registers a processor node as active.
Sourcepub fn remove_processor(&self, node_id: &str)
pub fn remove_processor(&self, node_id: &str)
Removes a processor node.
Sourcepub fn assign_partition(&self, assignment: PartitionAssignment)
pub fn assign_partition(&self, assignment: PartitionAssignment)
Assigns a partition to a processor.
Sourcepub fn check_exactly_once(&self, source_id: &str, sequence_number: u64) -> bool
pub fn check_exactly_once(&self, source_id: &str, sequence_number: u64) -> bool
Checks and records a message for exactly-once processing.
Returns true if the message is new and should be processed.
Sourcepub fn high_watermark(&self, source_id: &str) -> u64
pub fn high_watermark(&self, source_id: &str) -> u64
Returns the high watermark for a source.
Sourcepub fn take_checkpoint(
&self,
operator_states: HashMap<String, Vec<u8>>,
) -> StateResult<StateCheckpoint>
pub fn take_checkpoint( &self, operator_states: HashMap<String, Vec<u8>>, ) -> StateResult<StateCheckpoint>
Takes a checkpoint of the given operator states.
Returns the checkpoint if successful.
Sourcepub fn restore_from_latest(&self) -> Option<HashMap<String, Vec<u8>>>
pub fn restore_from_latest(&self) -> Option<HashMap<String, Vec<u8>>>
Restores state from the latest checkpoint.
Returns the operator states map if a checkpoint exists.
Sourcepub fn checkpoints(&self) -> Vec<StateCheckpoint>
pub fn checkpoints(&self) -> Vec<StateCheckpoint>
Returns all stored checkpoints (most recent first).
Sourcepub fn is_checkpoint_due(&self) -> bool
pub fn is_checkpoint_due(&self) -> bool
Returns whether a checkpoint is due based on the configured interval.
Sourcepub fn plan_migration(&self, reason: MigrationReason) -> Option<MigrationPlan>
pub fn plan_migration(&self, reason: MigrationReason) -> Option<MigrationPlan>
Plans a migration based on the current partition assignments and processor set.
Returns None if no migration is needed.
Sourcepub fn execute_migration(&self, plan: &MigrationPlan) -> usize
pub fn execute_migration(&self, plan: &MigrationPlan) -> usize
Executes a migration plan by updating partition assignments.
Returns the number of partitions migrated.
Sourcepub fn handle_node_joined(&self, node_id: &str) -> Option<MigrationPlan>
pub fn handle_node_joined(&self, node_id: &str) -> Option<MigrationPlan>
Handles a node joining the cluster: registers it and optionally migrates.
Sourcepub fn handle_node_left(&self, node_id: &str) -> Option<MigrationPlan>
pub fn handle_node_left(&self, node_id: &str) -> Option<MigrationPlan>
Handles a node leaving the cluster: reassigns its partitions.
Sourcepub fn partition_assignments(&self) -> Vec<PartitionAssignment>
pub fn partition_assignments(&self) -> Vec<PartitionAssignment>
Returns current partition assignments.
Sourcepub fn active_processors(&self) -> Vec<String>
pub fn active_processors(&self) -> Vec<String>
Returns active processor node IDs.
Sourcepub fn migration_history(&self) -> Vec<MigrationPlan>
pub fn migration_history(&self) -> Vec<MigrationPlan>
Returns migration history.
Sourcepub fn stats(&self) -> DistributedStateManagerStats
pub fn stats(&self) -> DistributedStateManagerStats
Returns comprehensive statistics.
Auto Trait Implementations§
impl Freeze for DistributedStateManager
impl !RefUnwindSafe for DistributedStateManager
impl Send for DistributedStateManager
impl Sync for DistributedStateManager
impl Unpin for DistributedStateManager
impl UnsafeUnpin for DistributedStateManager
impl !UnwindSafe for DistributedStateManager
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.