Skip to content

Commit

Permalink
Improve Debug output for common new types
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmedSoliman committed Jan 29, 2025
1 parent 4761e69 commit 6ed8dae
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 10 deletions.
6 changes: 4 additions & 2 deletions crates/types/src/identifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ use crate::time::MillisSinceEpoch;

/// Identifying the leader epoch of a partition processor
#[derive(
Debug,
PartialEq,
Eq,
Ord,
Expand All @@ -46,10 +45,12 @@ use crate::time::MillisSinceEpoch;
derive_more::From,
derive_more::Into,
derive_more::Display,
derive_more::Debug,
serde::Serialize,
serde::Deserialize,
)]
#[display("e{}", _0)]
#[debug("e{}", _0)]
pub struct LeaderEpoch(u64);
impl LeaderEpoch {
pub const INITIAL: Self = Self(1);
Expand Down Expand Up @@ -82,7 +83,6 @@ impl From<LeaderEpoch> for crate::protobuf::common::LeaderEpoch {
#[derive(
Copy,
Clone,
Debug,
PartialEq,
Eq,
Hash,
Expand All @@ -93,12 +93,14 @@ impl From<LeaderEpoch> for crate::protobuf::common::LeaderEpoch {
derive_more::Into,
derive_more::Add,
derive_more::Display,
derive_more::Debug,
derive_more::FromStr,
serde::Serialize,
serde::Deserialize,
)]
#[repr(transparent)]
#[serde(transparent)]
#[debug("{}", _0)]
pub struct PartitionId(u16);

impl From<PartitionId> for u32 {
Expand Down
6 changes: 4 additions & 2 deletions crates/types/src/logs/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,17 @@ use crate::{flexbuffers_storage_encode_decode, Version, Versioned};
PartialEq,
Ord,
PartialOrd,
Debug,
Hash,
Serialize,
Deserialize,
derive_more::From,
derive_more::Into,
derive_more::Display,
derive_more::Debug,
)]
#[repr(transparent)]
#[serde(transparent)]
#[debug("{}", _0)]
pub struct SegmentIndex(pub(crate) u32);

impl SegmentIndex {
Expand Down Expand Up @@ -218,11 +219,12 @@ pub struct LogsConfiguration {
pub default_provider: ProviderConfiguration,
}

#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
#[derive(derive_more::Debug, Clone, serde::Serialize, serde::Deserialize)]
#[serde(try_from = "LogsSerde", into = "LogsSerde")]
pub struct Logs {
pub(super) version: Version,
pub(super) logs: HashMap<LogId, Chain>,
#[debug(skip)]
pub(super) lookup_index: LookupIndex,
pub(super) config: LogsConfiguration,
}
Expand Down
3 changes: 2 additions & 1 deletion crates/types/src/logs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ pub use record_cache::RecordCache;
pub use tail::*;

#[derive(
Debug,
Clone,
Copy,
Eq,
PartialEq,
Hash,
Ord,
PartialOrd,
derive_more::Debug,
derive_more::Display,
derive_more::From,
derive_more::Into,
Serialize,
Deserialize,
)]
#[debug("{}", _0)]
pub struct LogId(u32);

impl LogId {
Expand Down
8 changes: 5 additions & 3 deletions crates/types/src/node_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use bytes::{Buf, BufMut, BytesMut};
/// must be also generational and the generations must match. If you are only interested in
/// checking the id part, then compare using `x.id() == y.id()` instead of `x == y`.
#[derive(
Debug,
PartialEq,
Eq,
Clone,
Copy,
Hash,
derive_more::From,
derive_more::Display,
derive_more::Debug,
derive_more::IsVariant,
serde::Serialize,
serde::Deserialize,
Expand All @@ -38,7 +38,6 @@ pub enum NodeId {
}

#[derive(
Debug,
PartialEq,
Eq,
PartialOrd,
Expand All @@ -48,10 +47,12 @@ pub enum NodeId {
Hash,
derive_more::From,
derive_more::Display,
derive_more::Debug,
serde::Serialize,
serde::Deserialize,
)]
#[display("{}:{}", _0, _1)]
#[debug("{}:{}", _0, _1)]
pub struct GenerationalNodeId(PlainNodeId, u32);

#[derive(Debug, thiserror::Error)]
Expand Down Expand Up @@ -120,7 +121,6 @@ impl From<u64> for GenerationalNodeId {
}

#[derive(
Debug,
Default,
PartialEq,
Eq,
Expand All @@ -132,12 +132,14 @@ impl From<u64> for GenerationalNodeId {
derive_more::From,
derive_more::Into,
derive_more::Display,
derive_more::Debug,
serde::Serialize,
serde::Deserialize,
)]
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
#[cfg_attr(feature = "schemars", schemars(transparent))]
#[display("N{}", _0)]
#[debug("N{}", _0)]
pub struct PlainNodeId(u32);

impl FromStr for PlainNodeId {
Expand Down
8 changes: 7 additions & 1 deletion crates/types/src/replication/replication_property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static REPLICATION_PROPERTY_EXTRACTOR: LazyLock<Regex> = LazyLock::new(|| {
pub struct ReplicationPropertyError(String);

/// The replication policy for appends
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, Eq, PartialEq)]
#[derive(serde::Serialize, serde::Deserialize, Clone, Eq, PartialEq)]
pub struct ReplicationProperty(BTreeMap<LocationScope, u8>);

impl ReplicationProperty {
Expand Down Expand Up @@ -151,6 +151,12 @@ impl ReplicationProperty {
}
}

impl std::fmt::Debug for ReplicationProperty {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self)
}
}

impl Display for ReplicationProperty {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "{{")?;
Expand Down
3 changes: 2 additions & 1 deletion crates/types/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

/// A type used for versioned metadata.
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Expand All @@ -20,11 +19,13 @@
derive_more::Display,
derive_more::From,
derive_more::Into,
derive_more::Debug,
derive_more::AddAssign,
serde::Serialize,
serde::Deserialize,
)]
#[display("v{}", _0)]
#[debug("v{}", _0)]
pub struct Version(u32);

impl Version {
Expand Down

0 comments on commit 6ed8dae

Please sign in to comment.