pub struct KraftController { /* private fields */ }Expand description
Cheap, cloneable handle to the running engine: holds the command sender and
the watch receivers the broker/handle read.
Implementations§
Source§impl KraftController
impl KraftController
Sourcepub fn current_image(&self) -> Arc<MetadataImage> ⓘ
pub fn current_image(&self) -> Arc<MetadataImage> ⓘ
A snapshot of the latest applied MetadataImage.
Sourcepub fn finalized_features_epoch(&self) -> i64
pub fn finalized_features_epoch(&self) -> i64
The finalized-features epoch of the published MetadataImage: the
offset of the last record of the newest batch or snapshot that carried
a FeatureLevelRecord, or -1 before the first. Kafka’s controller
listener answers ApiVersions with it, from FeaturesPublisher.
The engine publishes it after the image, so a caller that reads it
before Self::current_image never gets an epoch ahead of the
features.
Sourcepub fn watch_image(&self) -> Receiver<Arc<MetadataImage>>
pub fn watch_image(&self) -> Receiver<Arc<MetadataImage>>
Watch the published MetadataImage.
Sourcepub fn watch_fault(&self) -> Receiver<Option<String>>
pub fn watch_fault(&self) -> Receiver<Option<String>>
Watch the fault that stopped the engine: None while it runs, and
the reason once it stops over a fault Kafka halts the process over.
That is the I/O error of the first write to the metadata log
directory that fails (KIP-858), or a controller activation that
failed.
Sourcepub fn watch_leader(&self) -> Receiver<Option<NodeId>>
pub fn watch_leader(&self) -> Receiver<Option<NodeId>>
Watch the current leader id.
Sourcepub fn quorum_snapshot(&self) -> QuorumStateSnapshot
pub fn quorum_snapshot(&self) -> QuorumStateSnapshot
A synchronous snapshot of consensus state (the handle’s quorum_state()
reads this without an mpsc round-trip — the engine republishes it on
every event). Cheap watch borrow + clone.
Sourcepub async fn submit_change(
&self,
records: Vec<MetadataRecord>,
) -> Result<SubmitChangeResult, RaftError>
pub async fn submit_change( &self, records: Vec<MetadataRecord>, ) -> Result<SubmitChangeResult, RaftError>
Submit a metadata change. On the leader, appends the batch at the current
leader epoch and returns once it is committed (HWM ≥ the appended end
offset) AND applied, surfacing the first per-record rejection. On a
follower, returns RaftError::NotLeader with the leader hint; the
handle layer forwards via forward_submit_to.
§Errors
RaftError::Metadataif a record failsvalidate.RaftError::NotLeaderif this node is not the leader.RaftError::Shutdownif the engine task is gone.
Sourcepub fn install_registration_admission(
&self,
admission: Arc<dyn RegistrationAdmission>,
) -> Result<(), &'static str>
pub fn install_registration_admission( &self, admission: Arc<dyn RegistrationAdmission>, ) -> Result<(), &'static str>
Install the hook every batch that registers a broker anew passes through on the leader. It can be installed once.
§Errors
Returns an error if a hook is already installed.
Sourcepub async fn submit_change_if_image(
&self,
records: Vec<MetadataRecord>,
expected_image: Arc<MetadataImage>,
) -> Result<SubmitChangeResult, RaftError>
pub async fn submit_change_if_image( &self, records: Vec<MetadataRecord>, expected_image: Arc<MetadataImage>, ) -> Result<SubmitChangeResult, RaftError>
Submit a leader-local mutation only while its admission image is current. Pending metadata must commit before a caller can plan a guarded mutation.
§Errors
Returns a leadership, stale-image, uncommitted-tail, or submission error.
Sourcepub async fn submit_delegation_token_mutations(
&self,
mutations: Vec<DelegationTokenMutation>,
) -> Result<SubmitChangeResult, RaftError>
pub async fn submit_delegation_token_mutations( &self, mutations: Vec<DelegationTokenMutation>, ) -> Result<SubmitChangeResult, RaftError>
Submit generation-bound delegation-token mutations.
§Errors
Returns a leadership, shutdown, or mutation-rejection error.
Sourcepub async fn finalize_kraft_version(
&self,
version: u16,
) -> Result<ReconfigOutcome, RaftError>
pub async fn finalize_kraft_version( &self, version: u16, ) -> Result<ReconfigOutcome, RaftError>
Atomically finalize kraft.version in the Raft control log.
§Errors
Returns an unsupported-version, leadership, timeout, or storage error.
Sourcepub async fn validate_kraft_version(
&self,
version: u16,
) -> Result<ReconfigOutcome, RaftError>
pub async fn validate_kraft_version( &self, version: u16, ) -> Result<ReconfigOutcome, RaftError>
Run the leader-side checks of Self::finalize_kraft_version and
append nothing.
§Errors
Returns the error finalize_kraft_version would return for the same
request.
Sourcepub async fn quorum_state(&self) -> Result<QuorumStateSnapshot, RaftError>
pub async fn quorum_state(&self) -> Result<QuorumStateSnapshot, RaftError>
A structured snapshot of consensus state for the broker’s
DescribeQuorum admin view.
§Errors
Returns RaftError::Shutdown if the engine task is gone.
Sourcepub async fn metadata_fetch(
&self,
fetch_offset: i64,
max_size: ByteSize,
replica: Option<ReplicaKey>,
) -> Result<MetadataFetchSlice, RaftError>
pub async fn metadata_fetch( &self, fetch_offset: i64, max_size: ByteSize, replica: Option<ReplicaKey>, ) -> Result<MetadataFetchSlice, RaftError>
Read a committed __cluster_metadata slice for an observer’s
API_KEY_METADATA_FETCH (1004). replica names the observer that asked,
when it is a replica, so a leader can track its progress.
§Errors
Returns RaftError::Shutdown if the engine task is gone.
Sourcepub async fn trigger_snapshot(&self) -> Result<(), RaftError>
pub async fn trigger_snapshot(&self) -> Result<(), RaftError>
Sourcepub async fn inject_event(&self, event: Event) -> Result<(), RaftError>
pub async fn inject_event(&self, event: Event) -> Result<(), RaftError>
Inject a raw core Event into the loop (test/driver entrypoint and the
internal feedback path for peer-RPC responses).
§Errors
Returns RaftError::Shutdown if the engine task is gone.
Sourcepub async fn deliver(&self, inbound: Inbound) -> Result<(), RaftError>
pub async fn deliver(&self, inbound: Inbound) -> Result<(), RaftError>
Deliver an inbound peer RPC to the engine.
§Errors
Returns RaftError::Shutdown if the engine task is gone.
Sourcepub async fn shutdown(&self)
pub async fn shutdown(&self)
Stop the engine task gracefully and wait for its log to close.
A leader resigns first and sends EndQuorumEpoch, and the engine keeps
taking part in the quorum until a successor is known or its graceful
shutdown window runs out, as Kafka’s KafkaRaftClient.shutdown does. A
follower or an observer stops at once.
Source§impl KraftController
impl KraftController
Sourcepub fn spawn(
config: KraftConfig,
log: KraftLog,
data_dir: PathBuf,
) -> Result<Self, RaftError>
pub fn spawn( config: KraftConfig, log: KraftLog, data_dir: PathBuf, ) -> Result<Self, RaftError>
Build the engine over an already-opened KraftLog and spawn its loop
task. Recovery (snapshot + replay + quorum-state file) is wired by
Self::open; this lower-level entrypoint takes the seed state directly
and is used by tests/drivers that supply their own KraftLog.
The returned handle’s loop runs until Self::shutdown (or all handles
drop). data_dir is where the engine writes the quorum-state file and
checkpoints.
§Errors
Returns an error if starting the engine fails. A fresh controller has no recovered downgrade boundary, so it needs no downgrade-checkpoint recovery.
Sourcepub fn open(
data_dir: PathBuf,
me: NodeId,
cluster_id: Uuid,
directory_id: Uuid,
bootstrap_voters: VoterSet,
timeouts: QuorumTimeouts,
heartbeat_interval: Option<Time>,
controller_fetch_miss_limit: ControllerFetchMissLimit,
metadata_raft_command_queue_capacity: MetadataRaftCommandQueueCapacity,
metadata_raft_fetch_max: MetadataRaftFetchMax,
peers: Arc<dyn PeerSender>,
snapshot_interval_records: u64,
max_bytes_between_snapshots: ByteSize,
max_snapshot_interval: Time,
metadata_snapshot_fetch_max: MetadataSnapshotFetchMax,
metadata_log: MetadataLogConfig,
activation: Activation,
event_queue_recorder: Arc<dyn EventQueueRecorder>,
validate_image: impl Fn(&MetadataImage) -> Result<(), RaftError>,
) -> Result<Self, RaftError>
pub fn open( data_dir: PathBuf, me: NodeId, cluster_id: Uuid, directory_id: Uuid, bootstrap_voters: VoterSet, timeouts: QuorumTimeouts, heartbeat_interval: Option<Time>, controller_fetch_miss_limit: ControllerFetchMissLimit, metadata_raft_command_queue_capacity: MetadataRaftCommandQueueCapacity, metadata_raft_fetch_max: MetadataRaftFetchMax, peers: Arc<dyn PeerSender>, snapshot_interval_records: u64, max_bytes_between_snapshots: ByteSize, max_snapshot_interval: Time, metadata_snapshot_fetch_max: MetadataSnapshotFetchMax, metadata_log: MetadataLogConfig, activation: Activation, event_queue_recorder: Arc<dyn EventQueueRecorder>, validate_image: impl Fn(&MetadataImage) -> Result<(), RaftError>, ) -> Result<Self, RaftError>
Open the engine over data_dir: recover the MetadataImage from the
latest checkpoint + replay committed log batches, and seed the durable
QuorumState from the node-local quorum-state file. The
bootstrap voter set/cluster id is used only when no quorum-state file
exists yet.
The bootstrap checkpoint, at offset 0 and epoch 0, is not a snapshot
of the log. The engine takes its KIP-853 control state, but it does
not apply its metadata records to the image. Those records replace
the bootstrap records of activation when there are any, and the
leader writes them to an empty log, as Kafka’s
QuorumController.handleLoadBootstrap keeps them for its activation.
§Errors
Returns RaftError if the log/checkpoint cannot be opened or read, or
validate_image refuses the committed image, or that image with every
feature level the log holds above its high watermark, before
checkpoint repair or an engine task can start.
Trait Implementations§
Source§impl Clone for KraftController
impl Clone for KraftController
Source§fn clone(&self) -> KraftController
fn clone(&self) -> KraftController
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for KraftController
impl !UnwindSafe for KraftController
impl Freeze for KraftController
impl Send for KraftController
impl Sync for KraftController
impl Unpin for KraftController
impl UnsafeUnpin for KraftController
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<F> FnGhost for F
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);