Skip to main content

confluent_kafka/admin/
replica_info.rs

1// Copyright 2025 Confluent Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! A description of a replica on a particular broker.
16
17/// A description of a replica on a particular broker.
18#[derive(Clone, Debug)]
19#[doc(alias = "org.apache.kafka.clients.admin.ReplicaInfo")]
20pub struct ReplicaInfo {
21    size: i64,
22    offset_lag: i64,
23    is_future: bool,
24}
25
26impl ReplicaInfo {
27    /// Creates a new `ReplicaInfo`.
28    ///
29    /// # Arguments
30    ///
31    /// - `size` - the total size of the log segments in this replica in bytes.
32    /// - `offset_lag` - the lag of the log's LEO with respect to the partition's high watermark.
33    /// - `is_future` - whether this replica has been created by an `AlterReplicaLogDirsRequest`.
34    #[doc(alias = "org.apache.kafka.clients.admin.ReplicaInfo#ReplicaInfo")]
35    pub fn new(size: i64, offset_lag: i64, is_future: bool) -> Self {
36        Self { size, offset_lag, is_future }
37    }
38
39    /// Returns the total size of the log segments in this replica in bytes.
40    ///
41    /// This value does not include the size of data stored in remote storage.
42    #[doc(alias = "org.apache.kafka.clients.admin.ReplicaInfo#size")]
43    pub fn size(&self) -> i64 {
44        self.size
45    }
46
47    /// Returns the lag of the log's LEO with respect to the partition's high watermark
48    /// (if it is the current log for the partition) or the current replica's LEO
49    /// (if it is the future log for the partition).
50    #[doc(alias = "org.apache.kafka.clients.admin.ReplicaInfo#offsetLag")]
51    pub fn offset_lag(&self) -> i64 {
52        self.offset_lag
53    }
54
55    /// Whether this replica has been created by an `AlterReplicaLogDirsRequest`
56    /// but has not yet replaced the current replica on the broker.
57    ///
58    /// # Returns
59    ///
60    /// true if this log is created by AlterReplicaLogDirsRequest and will replace the current log
61    /// of the replica at some time in the future.
62    #[doc(alias = "org.apache.kafka.clients.admin.ReplicaInfo#isFuture")]
63    pub fn is_future(&self) -> bool {
64        self.is_future
65    }
66}
67
68impl std::fmt::Display for ReplicaInfo {
69    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70        write!(
71            f,
72            "ReplicaInfo(size={}, offsetLag={}, isFuture={})",
73            self.size, self.offset_lag, self.is_future
74        )
75    }
76}
77
78#[cfg(test)]
79mod tests {
80    use super::*;
81
82    #[test]
83    fn accessors_and_display() {
84        let info = ReplicaInfo::new(1234, 24, true);
85        assert_eq!(info.size(), 1234);
86        assert_eq!(info.offset_lag(), 24);
87        assert!(info.is_future());
88        assert_eq!(info.to_string(), "ReplicaInfo(size=1234, offsetLag=24, isFuture=true)");
89    }
90}