Skip to content

Commit

Permalink
Remove StatusRef (#351)
Browse files Browse the repository at this point in the history
This effectively reverts part of 065c37d. Because it is not necessary after b86e9e0. Normal Status also uses borrow.

Signed-off-by: Haibo Huang <[email protected]>
  • Loading branch information
hhbti authored Mar 24, 2020
1 parent c82696c commit 040b8b9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ pub use self::raft::{vote_resp_msg_type, Raft, SoftState, StateRole, INVALID_ID,
pub use self::raft_log::{RaftLog, NO_LIMIT};
pub use self::raw_node::{is_empty_snap, Peer, RawNode, Ready, SnapshotStatus};
pub use self::read_only::{ReadOnlyOption, ReadState};
pub use self::status::{Status, StatusRef};
pub use self::status::Status;
pub use self::storage::{RaftState, Storage};
pub use self::util::{majority, QuorumFn};
pub use raft_proto::eraftpb;
Expand Down Expand Up @@ -524,7 +524,7 @@ pub mod prelude {

pub use crate::progress::Progress;

pub use crate::status::{Status, StatusRef};
pub use crate::status::Status;

pub use crate::read_only::{ReadOnlyOption, ReadState};
}
Expand Down
9 changes: 1 addition & 8 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::eraftpb::{
};
use crate::errors::{Error, Result};
use crate::read_only::ReadState;
use crate::{QuorumFn, Raft, SoftState, Status, StatusRef, Storage, INVALID_ID};
use crate::{QuorumFn, Raft, SoftState, Status, Storage, INVALID_ID};
use slog::Logger;

/// Represents a Peer node in the cluster.
Expand Down Expand Up @@ -435,13 +435,6 @@ impl<T: Storage> RawNode<T> {
Status::new(&self.raft)
}

/// Returns the current status of the given group.
///
/// It's borrows the internal progress set instead of copying.
pub fn status_ref(&self) -> StatusRef {
StatusRef::new(&self.raft)
}

/// ReportUnreachable reports the given node is not reachable for the last send.
pub fn report_unreachable(&mut self, id: u64) {
let mut m = Message::default();
Expand Down
32 changes: 0 additions & 32 deletions src/status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,3 @@ impl<'a> Status<'a> {
s
}
}

/// Represents the current status of the raft
#[derive(Default)]
pub struct StatusRef<'a> {
/// The ID of the current node.
pub id: u64,
/// The hardstate of the raft, representing voted state.
pub hs: HardState,
/// The softstate of the raft, representing proposed state.
pub ss: SoftState,
/// The index of the last entry to have been applied.
pub applied: u64,
/// The progress towards catching up and applying logs.
pub progress: Option<&'a ProgressSet>,
}

impl<'a> StatusRef<'a> {
/// Gets the current raft status.
pub fn new<T: Storage>(raft: &'a Raft<T>) -> StatusRef<'a> {
let mut s = StatusRef {
id: raft.id,
..Default::default()
};
s.hs = raft.hard_state();
s.ss = raft.soft_state();
s.applied = raft.raft_log.applied();
if s.ss.raft_state == StateRole::Leader {
s.progress = Some(raft.prs());
}
s
}
}

0 comments on commit 040b8b9

Please sign in to comment.