Skip to content

Commit

Permalink
chore: update alarm str in status response
Browse files Browse the repository at this point in the history
Signed-off-by: themanforfree <[email protected]>
  • Loading branch information
themanforfree authored and mergify[bot] committed Jan 12, 2024
1 parent fb0ab6b commit 3cddc58
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion curp/src/server/curp_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ impl<C: Command, RC: RoleChange> CurpNode<C, RC> {
}

/// Get `RawCurp`
pub(super) fn curp(&self) -> Arc<RawCurp<C, RC>> {
pub(super) fn raw_curp(&self) -> Arc<RawCurp<C, RC>> {
Arc::clone(&self.curp)
}
}
Expand Down
2 changes: 1 addition & 1 deletion curp/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,6 @@ impl<C: Command, RC: RoleChange> Rpc<C, RC> {
#[inline]
#[must_use]
pub fn raw_curp(&self) -> Arc<RawCurp<C, RC>> {
self.inner.curp()
self.inner.raw_curp()
}
}
1 change: 1 addition & 0 deletions curp/src/server/raw_curp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub struct RawCurp<C: Command, RC: RoleChange> {
}

impl<C: Command, RC: RoleChange> Debug for RawCurp<C, RC> {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RawCurp")
.field("st", &self.st)
Expand Down
4 changes: 2 additions & 2 deletions xline/src/server/maintenance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,10 @@ where
})?;
let mut errors = vec![];
if leader.is_none() {
errors.push("no leader".to_owned());
errors.push("etcdserver: no leader".to_owned());
}
for a in self.alarm_store.get_all_alarms() {
errors.push(format!("{a:?}"));
errors.push(a.to_string());
}
let response = StatusResponse {
header: Some(self.header_gen.gen_header()),
Expand Down
20 changes: 20 additions & 0 deletions xlineapi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ mod errorpb {
tonic::include_proto!("errorpb");
}

use std::fmt::Display;

use curp_external_api::cmd::PbSerializeError;
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -674,6 +676,17 @@ impl AlarmMember {
}
}

impl Display for AlarmMember {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let alarm = AlarmType::from_i32(self.alarm).unwrap_or_else(|| panic!("invalid alarm"));
let alarm_str = match alarm {
AlarmType::Nospace => "NOSPACE",
AlarmType::Corrupt => "CORRUPT",
AlarmType::None => "NONE",
};
write!(f, "memberID:{} alarm:{} ", self.member_id, alarm_str)
}
}
#[cfg(test)]
mod test {
use super::*;
Expand Down Expand Up @@ -828,4 +841,11 @@ mod test {

assert!(!mixed_nested_txn_req.is_serializable());
}

#[test]
fn test_alarm_member_display() {
let am = AlarmMember::new(10276657743932975437, AlarmType::Nospace);
let expect = "memberID:10276657743932975437 alarm:NOSPACE ";
assert_eq!(expect, am.to_string());
}
}

0 comments on commit 3cddc58

Please sign in to comment.