Skip to main content

kafka_client_engine/consumer/assigned_host/
control_result.rs

1//! Stable synchronous acceptance and rejection values for position control.
2
3use super::{
4    control_error::control_error_kind,
5    result::{
6        AssignedConsumerAccepted, AssignedConsumerPortAcceptedFaultKind, AssignedConsumerPortError,
7    },
8};
9
10/// Accepted pause, resume, or seek and any advisory post-commit wake fault.
11#[must_use = "control acceptance and wake diagnostics must be inspected"]
12#[derive(Clone, Copy, Debug, Eq, PartialEq)]
13pub struct AssignedConsumerControlAccepted {
14    fault: Option<super::AssignedConsumerAcceptedFaultKind>,
15}
16
17impl AssignedConsumerControlAccepted {
18    /// Returns post-acceptance degradation without revoking the control change.
19    pub const fn fault(&self) -> Option<super::AssignedConsumerAcceptedFaultKind> {
20        self.fault
21    }
22
23    pub(super) fn from_port(accepted: AssignedConsumerAccepted<()>) -> Self {
24        let fault = accepted.fault().map(|fault| match fault {
25            AssignedConsumerPortAcceptedFaultKind::Wake => {
26                super::AssignedConsumerAcceptedFaultKind::Wake
27            }
28        });
29        let () = accepted.into_value();
30        Self { fault }
31    }
32}
33
34/// Stable reason pause, resume, or seek did not cross admission.
35#[derive(Clone, Copy, Debug, Eq, PartialEq)]
36pub enum AssignedConsumerControlErrorKind {
37    /// Another caller or the host currently owns the assigned-consumer shard.
38    Contended,
39    /// Assigned-consumer admission is permanently closed.
40    Closed,
41    /// Earlier accepted effects must be interpreted before control admission.
42    Pending,
43    /// No direct assignment has been accepted.
44    NoAssignment,
45    /// The supplied opaque assignment generation has been superseded.
46    StaleAssignment,
47    /// The named topic-partition is not in the active assignment.
48    UnknownPartition,
49    /// An explicit seek offset was negative.
50    NegativeOffset,
51    /// The requested timeout cannot become one absolute deadline.
52    DeadlineOverflow,
53    /// A bounded claim, allocation, or identity domain is exhausted.
54    ResourceExhausted,
55    /// The synchronized host can no longer execute new assigned-consumer work.
56    HostUnavailable,
57    /// A non-semantic engine mechanism violated its ownership contract.
58    InternalInvariant,
59}
60
61/// Immediate position-control rejection before ownership crossed.
62#[derive(Clone, Copy, Debug, Eq, PartialEq)]
63pub struct AssignedConsumerControlError {
64    kind: AssignedConsumerControlErrorKind,
65}
66
67impl AssignedConsumerControlError {
68    /// Returns the stable rejection category.
69    pub const fn kind(&self) -> AssignedConsumerControlErrorKind {
70        self.kind
71    }
72
73    pub(super) const fn from_port(error: &AssignedConsumerPortError) -> Self {
74        Self {
75            kind: control_error_kind(error),
76        }
77    }
78}
79
80impl std::fmt::Display for AssignedConsumerControlError {
81    fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
82        write!(
83            formatter,
84            "assigned-consumer position control failed: {:?}",
85            self.kind
86        )
87    }
88}
89
90impl std::error::Error for AssignedConsumerControlError {}