Skip to main content

ControllerHandle

Struct ControllerHandle 

Source
pub struct ControllerHandle { /* private fields */ }
Expand description

Handle returned by Controller::start.

Owns the live KraftController engine and the listener task. Drop is NOT a clean shutdown — call Self::shutdown (or Self::cancel) to drain the listener + stop the engine before the runtime is torn down.

Implementations§

Source§

impl ControllerHandle

Source

pub fn read_snapshot_range( &self, position: i64, max_bytes: i32, ) -> SnapshotRange

Read up to max_bytes of the latest metadata snapshot starting at position. Reads the engine’s .checkpoint artifacts directly (the engine writes a bare KIP-630 checkpoint, no .meta sidecar).

position and max_bytes stay the raw KIP-595 FetchSnapshot int64 and int32: both are byte offsets into an on-disk checkpoint that the broker’s handler forwards straight off the wire, so there is no domain layer between the decode and the slice index for a quantity to occupy.

Source

pub async fn fetch_snapshot( &self, version: i16, body: Bytes, ) -> Result<Bytes, RaftError>

Answer one KIP-630 FetchSnapshot request through the engine, as the controller listener answers it.

body is the request body at version, and the answer is the response body at that version. The engine follows Kafka’s KafkaRaftClient.handleFetchSnapshotRequest: it serves exactly the snapshot the request names, and refuses another topic or partition, a stale or unknown CurrentLeaderEpoch, another cluster id, and a position outside the snapshot. It also fills CurrentLeader and the leader’s endpoint. A broker listener that answered from the checkpoint directly would answer the same request differently.

§Errors

Returns RaftError::Shutdown if the engine task is gone, or if it dropped the request because the body does not decode.

Source

pub async fn trigger_snapshot(&self) -> Result<(), RaftError>

Manually trigger a metadata snapshot (KIP-630 checkpoint) on this node.

§Errors

Returns RaftError if serialization or the file write fails.

Source§

impl ControllerHandle

Source

pub async fn change_membership( &self, new_voters: BTreeSet<NodeId>, ) -> Result<(), RaftError>

Reconcile a single-node voter-set delta through the KIP-853 engine.

§Errors

Rejects multi-node batch changes; KIP-642 is a separate operation.

Source

pub fn add_learner( &self, node_id: NodeId, node: Node, ) -> Ready<Result<(), RaftError>> ⓘ

Stage a caught-up observer identity for later voter promotion.

§Errors

The observer catches up by fetching from the leader; this call does not alter quorum membership.

Source

pub async fn add_voter( &self, req: AddVoter, ) -> Result<ReconfigOutcome, RaftError>

Add a caught-up controller voter through the Raft control log.

§Errors

Returns a validation, leadership, timeout, or storage error from Raft.

Source

pub async fn check_add_voter( &self, req: AddVoter, ) -> Result<ReconfigOutcome, RaftError>

Run the leader-local admission checks of AddVoterHandler for req without contacting the candidate or appending anything.

§Errors

Returns the refusal the same request would get from Self::add_voter for a pending change, an unset high watermark, kraft.version below 1, an uncommitted voters record or a duplicate voter id.

Source

pub async fn remove_voter( &self, req: RemoveVoter, ) -> Result<ReconfigOutcome, RaftError>

Remove the exact node/directory pair through the Raft control log.

§Errors

Returns a validation, leadership, timeout, or storage error from Raft.

Source

pub async fn update_voter( &self, req: UpdateVoter, ) -> Result<ReconfigOutcome, RaftError>

Update the exact voter’s endpoint and supported feature range.

§Errors

Returns a validation, leadership, timeout, or storage error from Raft.

Source

pub async fn finalize_kraft_version( &self, version: u16, ) -> Result<ReconfigOutcome, RaftError>

Atomically append KRaftVersionRecord and the initial VotersRecord.

§Errors

Returns an unsupported-version, leadership, timeout, or storage error.

Source

pub async fn validate_kraft_version( &self, version: u16, ) -> Result<ReconfigOutcome, RaftError>

Run the checks of Self::finalize_kraft_version and write nothing.

§Errors

Returns the error finalize_kraft_version would return for the same request.

Source§

impl ControllerHandle

Source

pub async fn metadata_records( &self, fetch_offset: u64, max_size: ByteSize, ) -> MetadataFetchSlice

Read committed __cluster_metadata entries starting at fetch_offset, encoded as Kafka record batches for an observer.

Source

pub async fn fetch_metadata_from( &self, addr: SocketAddr, fetch_offset: u64, max_size: ByteSize, ) -> Result<KrabkaMetadataFetchResponse, RaftError>

Dial a controller-listener addr and issue one API_KEY_METADATA_FETCH. Used by broker-only observers to pull committed __cluster_metadata.

§Errors
Source§

impl ControllerHandle

Source

pub async fn submit_change_if_image( &self, records: Vec<MetadataRecord>, expected_image: Arc<MetadataImage>, ) -> Result<SubmitChangeResult, RaftError>

Submit a mutation admitted against this controller’s published image. The engine checks that image before appending; this method never forwards a mutation whose admission happened on a different controller.

§Errors

Returns a leadership, stale-image, uncommitted-tail, or submission error.

Source

pub async fn submit_change( &self, records: Vec<MetadataRecord>, ) -> Result<SubmitChangeResult, RaftError>

Submit a batch of metadata records. Returns Ok(()) once committed AND applied on the leader. Pre-validation lives in the engine. On a follower (NotLeader with a known leader), forwards directly to the leader’s controller listener via API_KEY_SUBMIT_CHANGE.

§Errors

Returns an error if validation, replication, or forwarding fails.

Source

pub async fn submit_delegation_token_mutations( &self, mutations: Vec<DelegationTokenMutation>, ) -> Result<SubmitChangeResult, RaftError>

Submit token mutations whose expected records are checked by the leader in the same engine turn as the append.

§Errors

Returns a leadership, transport, protocol, or mutation-rejection error.

Source

pub async fn forward_raw( &self, api_key: i16, version: i16, body: Bytes, ) -> Result<Bytes, RaftError>

Forward a raw Kafka-wire request for api_key/version to the current quorum leader’s controller listener and return its raw response bytes, unmodified.

Used by the broker’s DescribeQuorum handler: Kafka’s KafkaApis forwards DescribeQuorum from the broker listener to the active controller unconditionally (forwardToController), so a combined or controller node that is not itself the leader must reach the leader the same way a broker-only observer already does.

§Errors

RaftError::NotLeader when no leader is known or the leader’s address cannot be resolved, RaftError::Network when the dial or round trip fails.

Source§

impl ControllerHandle

Source

pub fn current_image(&self) -> Arc<MetadataImage> ⓘ

Current metadata snapshot (cheap; Arc clone).

Source

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 while this node leads. See RegistrationAdmission.

§Errors

Returns an error if a hook is already installed.

Source

pub fn controller_bound_addr(&self) -> SocketAddr

The address the controller listener actually bound to.

Source

pub fn watch_leader(&self) -> Receiver<Option<NodeId>>

Subscribe to leader-id changes.

Source

pub fn watch_fatal(&self) -> Receiver<Option<String>>

Subscribe to the controller’s fatal fault: the message of the fault that made it stop itself, and None until then.

Kafka handles such a fault (a FeatureControlManager replay of a feature level that the controller does not support) with a ProcessTerminatingFaultHandler, which halts the process. A library cannot halt its host, so the controller stops itself, publishes the message here before it does, and leaves the process to its embedder: the broker turns it into its own shutdown. The channel closes without a value when the controller is shut down for any other reason.

Source

pub fn watch_image(&self) -> Receiver<Arc<MetadataImage>>

Subscribe to metadata-image changes.

Source

pub fn quorum_state(&self) -> QuorumState

Snapshot the controller’s current quorum state. Used by the broker’s DescribeQuorum (api_key=55, KIP-595) handler. Cheap — a watch borrow of the engine’s published snapshot.

Source

pub fn quorum_snapshot(&self) -> QuorumStateSnapshot

Snapshot the full consensus state.

Source

pub fn quorum_committed_offset(&self) -> i64

Highest __cluster_metadata offset the quorum has committed, as this node last heard it, or -1 before the first committed record.

This is the offset a readiness probe compares against. It differs from QuorumState::last_applied_index on a follower that is still replaying: last_applied_index is clamped to what this node has applied, while this is what the leader said it had committed.

Source

pub fn voted_directory_id(&self) -> Option<Uuid>

Directory identity voted for in the current leader epoch, if any.

Source

pub async fn shutdown(self)

Drain the listener and stop the engine. Idempotent in practice.

Source

pub async fn cancel(&self)

Stop the engine and cancel the controller listener without consuming self. Used by BrokerHandle::shutdown where the controller is behind an Arc. Idempotent. Awaits the listener task so the OS port is released before returning.

The engine stops gracefully, before the listener does: a leader resigns, and its successor’s BeginQuorumEpoch still reaches the listener, which is how the engine learns that the handover is complete.

Source

pub async fn halt(&self)

Stop the engine at once, handing nothing over, and cancel the listener, as a halted process stops. The quorum finds out through its fetch watchdog. Idempotent.

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
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<F> FnGhost for F

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

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 primary(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Primary].

§Example
println!("{}", value.primary());
§

fn fixed(&self, color: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Fixed].

§Example
println!("{}", value.fixed(color));
§

fn rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the fg() set to [Color :: Rgb].

§Example
println!("{}", value.rgb(r, g, b));
§

fn black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Black].

§Example
println!("{}", value.black());
§

fn red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Red].

§Example
println!("{}", value.red());
§

fn green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Green].

§Example
println!("{}", value.green());
§

fn yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Yellow].

§Example
println!("{}", value.yellow());
§

fn blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Blue].

§Example
println!("{}", value.blue());
§

fn magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Magenta].

§Example
println!("{}", value.magenta());
§

fn cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: Cyan].

§Example
println!("{}", value.cyan());
§

fn white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: White].

§Example
println!("{}", value.white());
§

fn bright_black(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlack].

§Example
println!("{}", value.bright_black());
§

fn bright_red(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightRed].

§Example
println!("{}", value.bright_red());
§

fn bright_green(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightGreen].

§Example
println!("{}", value.bright_green());
§

fn bright_yellow(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightYellow].

§Example
println!("{}", value.bright_yellow());
§

fn bright_blue(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightBlue].

§Example
println!("{}", value.bright_blue());
§

fn bright_magenta(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.bright_magenta());
§

fn bright_cyan(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightCyan].

§Example
println!("{}", value.bright_cyan());
§

fn bright_white(&self) -> Painted<&T>

Returns self with the fg() set to [Color :: BrightWhite].

§Example
println!("{}", value.bright_white());
§

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>

Returns self with the bg() set to [Color :: Primary].

§Example
println!("{}", value.on_primary());
§

fn on_fixed(&self, color: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Fixed].

§Example
println!("{}", value.on_fixed(color));
§

fn on_rgb(&self, r: u8, g: u8, b: u8) -> Painted<&T>

Returns self with the bg() set to [Color :: Rgb].

§Example
println!("{}", value.on_rgb(r, g, b));
§

fn on_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Black].

§Example
println!("{}", value.on_black());
§

fn on_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Red].

§Example
println!("{}", value.on_red());
§

fn on_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Green].

§Example
println!("{}", value.on_green());
§

fn on_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Yellow].

§Example
println!("{}", value.on_yellow());
§

fn on_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Blue].

§Example
println!("{}", value.on_blue());
§

fn on_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Magenta].

§Example
println!("{}", value.on_magenta());
§

fn on_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: Cyan].

§Example
println!("{}", value.on_cyan());
§

fn on_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: White].

§Example
println!("{}", value.on_white());
§

fn on_bright_black(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlack].

§Example
println!("{}", value.on_bright_black());
§

fn on_bright_red(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightRed].

§Example
println!("{}", value.on_bright_red());
§

fn on_bright_green(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightGreen].

§Example
println!("{}", value.on_bright_green());
§

fn on_bright_yellow(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightYellow].

§Example
println!("{}", value.on_bright_yellow());
§

fn on_bright_blue(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightBlue].

§Example
println!("{}", value.on_bright_blue());
§

fn on_bright_magenta(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightMagenta].

§Example
println!("{}", value.on_bright_magenta());
§

fn on_bright_cyan(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightCyan].

§Example
println!("{}", value.on_bright_cyan());
§

fn on_bright_white(&self) -> Painted<&T>

Returns self with the bg() set to [Color :: BrightWhite].

§Example
println!("{}", value.on_bright_white());
§

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 bold(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Bold].

§Example
println!("{}", value.bold());
§

fn dim(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Dim].

§Example
println!("{}", value.dim());
§

fn italic(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Italic].

§Example
println!("{}", value.italic());
§

fn underline(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Underline].

§Example
println!("{}", value.underline());

Returns self with the attr() set to [Attribute :: Blink].

§Example
println!("{}", value.blink());

Returns self with the attr() set to [Attribute :: RapidBlink].

§Example
println!("{}", value.rapid_blink());
§

fn invert(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Invert].

§Example
println!("{}", value.invert());
§

fn conceal(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Conceal].

§Example
println!("{}", value.conceal());
§

fn strike(&self) -> Painted<&T>

Returns self with the attr() set to [Attribute :: Strike].

§Example
println!("{}", value.strike());
§

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 mask(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Mask].

§Example
println!("{}", value.mask());
§

fn wrap(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Wrap].

§Example
println!("{}", value.wrap());
§

fn linger(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Linger].

§Example
println!("{}", value.linger());
§

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.

Returns self with the quirk() set to [Quirk :: Clear].

§Example
println!("{}", value.clear());
§

fn resetting(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Resetting].

§Example
println!("{}", value.resetting());
§

fn bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: Bright].

§Example
println!("{}", value.bright());
§

fn on_bright(&self) -> Painted<&T>

Returns self with the quirk() set to [Quirk :: OnBright].

§Example
println!("{}", value.on_bright());
§

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);
§

fn new(self) -> Painted<Self>
where Self: Sized,

Create a new [Painted] with a default [Style]. Read more
§

fn paint<S>(&self, style: S) -> Painted<&Self>
where S: Into<Style>,

Apply a style wholesale to self. Any previous style is replaced. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ServiceExt for T

§

fn map_response_body<F>(self, f: F) -> MapResponseBody<Self, F>
where Self: Sized,

Apply a transformation to the response body. Read more
§

fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using HTTP status codes. Read more
§

fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>
where Self: Sized,

High level tracing that classifies responses using gRPC headers. Read more
§

fn follow_redirects(self) -> FollowRedirect<Self>
where Self: Sized,

Follow redirect resposes using the Standard policy. Read more
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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