Skip to main content

kafka_client_engine/transaction/initialization/
control_error.rs

1//! Stable public rejection categories for transactional lifecycle control.
2
3use core::fmt;
4
5use super::TransactionToken;
6
7/// Stable reason a transactional lifecycle control operation was rejected.
8#[derive(Clone, Copy, Debug, Eq, PartialEq)]
9pub enum TransactionControlErrorKind {
10    /// The requested timeout cannot form one positive absolute deadline.
11    InvalidDeadline,
12    /// The bounded transaction shard is currently owned by another caller.
13    Contended,
14    /// Shutdown has closed transaction control.
15    Closed,
16    /// The supplied initialized owner is no longer installed.
17    StaleOwner,
18    /// The initialized owner already has an active transaction.
19    AlreadyActive,
20    /// The initialized owner has no active transaction.
21    NotActive,
22    /// The supplied transaction token does not name the active epoch.
23    StaleTransaction,
24    /// Accepted transactional operations still require settlement.
25    OutstandingOperations,
26    /// Prior execution uncertainty requires abort rather than commit.
27    AbortRequired,
28    /// Commit, abort, or owner-loss cleanup is already in progress.
29    EndInProgress,
30    /// Transaction execution has permanently fenced this owner.
31    Fenced,
32    /// Bounded completion capacity is unavailable.
33    Backpressure,
34    /// A nonreused internal identity domain is exhausted.
35    IdentityExhausted,
36    /// An internal transaction invariant made the host unavailable.
37    HostUnavailable,
38}
39
40/// Rejection of a transaction begin operation.
41#[derive(Clone, Copy, Debug, Eq, PartialEq)]
42pub struct TransactionControlError {
43    kind: TransactionControlErrorKind,
44}
45
46impl TransactionControlError {
47    pub(super) const fn new(kind: TransactionControlErrorKind) -> Self {
48        Self { kind }
49    }
50
51    /// Returns the stable rejection category.
52    pub const fn kind(self) -> TransactionControlErrorKind {
53        self.kind
54    }
55}
56
57impl fmt::Display for TransactionControlError {
58    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
59        write!(formatter, "transaction control rejected: {:?}", self.kind)
60    }
61}
62
63impl std::error::Error for TransactionControlError {}
64
65/// Rejected commit or abort retaining the exact active transaction token.
66#[must_use = "transaction end rejection retains the active transaction token"]
67pub struct TransactionEndAdmissionError<'owner> {
68    kind: TransactionControlErrorKind,
69    transaction: TransactionToken<'owner>,
70}
71
72impl<'owner> TransactionEndAdmissionError<'owner> {
73    pub(super) const fn new(
74        kind: TransactionControlErrorKind,
75        transaction: TransactionToken<'owner>,
76    ) -> Self {
77        Self { kind, transaction }
78    }
79
80    /// Returns the stable rejection category.
81    pub const fn kind(&self) -> TransactionControlErrorKind {
82        self.kind
83    }
84
85    /// Returns the exact active transaction token rejected before driver ownership.
86    pub fn into_transaction(self) -> TransactionToken<'owner> {
87        self.transaction
88    }
89}
90
91impl fmt::Debug for TransactionEndAdmissionError<'_> {
92    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
93        formatter
94            .debug_struct("TransactionEndAdmissionError")
95            .field("kind", &self.kind)
96            .finish_non_exhaustive()
97    }
98}
99
100impl fmt::Display for TransactionEndAdmissionError<'_> {
101    fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
102        write!(formatter, "transaction end rejected: {:?}", self.kind)
103    }
104}
105
106impl std::error::Error for TransactionEndAdmissionError<'_> {}