Skip to content

Commit

Permalink
Change: remove InitializeError::NotAMembershipEntry error
Browse files Browse the repository at this point in the history
Such an error can only be caused by internal calls. An application do
not need to handle it.
  • Loading branch information
drmingdrmer committed Feb 12, 2023
1 parent ea214cf commit 77e87a3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 36 deletions.
24 changes: 10 additions & 14 deletions openraft/src/engine/engine_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::engine::handler::vote_handler::VoteHandler;
use crate::engine::Command;
use crate::entry::RaftEntry;
use crate::error::InitializeError;
use crate::error::NotAMembershipEntry;
use crate::error::NotAllowed;
use crate::error::NotInMembers;
use crate::internal_server_state::InternalServerState;
Expand Down Expand Up @@ -183,21 +182,18 @@ where
self.output.push_command(Command::AppendInputEntries { range: 0..l });

let entry = &mut entries[0];
if let Some(m) = entry.get_membership() {
self.check_members_contain_me(m)?;
} else {
Err(NotAMembershipEntry {})?;
}
let m = entry.get_membership().expect("the only log entry for initializing has to be membership log");
self.check_members_contain_me(m)?;

if let Some(m) = entry.get_membership() {
let log_id = entry.get_log_id();
tracing::debug!("update effective membership: log_id:{} {}", log_id, m.summary());
let log_id = entry.get_log_id();
tracing::debug!("update effective membership: log_id:{} {}", log_id, m.summary());

let em = EffectiveMembership::new_arc(Some(*log_id), m.clone());
self.state.membership_state.append(em.clone());
self.output.push_command(Command::UpdateMembership { membership: em });
self.server_state_handler().update_server_state_if_changed();
}
let em = EffectiveMembership::new_arc(Some(*log_id), m.clone());
self.state.membership_state.append(em.clone());

self.output.push_command(Command::UpdateMembership { membership: em });

self.server_state_handler().update_server_state_if_changed();

self.output.push_command(Command::MoveInputCursorBy { n: l });

Expand Down
14 changes: 0 additions & 14 deletions openraft/src/engine/initialize_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::engine::Engine;
use crate::engine::LogIdList;
use crate::entry::EntryRef;
use crate::error::InitializeError;
use crate::error::NotAMembershipEntry;
use crate::error::NotAllowed;
use crate::error::NotInMembers;
use crate::raft::VoteRequest;
Expand Down Expand Up @@ -243,18 +242,5 @@ fn test_initialize() -> anyhow::Result<()> {
);
}

tracing::info!("--- log entry is not a membership entry");
{
let mut eng = eng();

let payload = EntryPayload::<Config>::Blank;
let mut entries = [EntryRef::new(&payload)];

assert_eq!(
Err(InitializeError::NotAMembershipEntry(NotAMembershipEntry {})),
eng.initialize(&mut entries)
);
}

Ok(())
}
8 changes: 0 additions & 8 deletions openraft/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,6 @@ where
#[error(transparent)]
NotInMembers(#[from] NotInMembers<NID, N>),

#[error(transparent)]
NotAMembershipEntry(#[from] NotAMembershipEntry),

#[error(transparent)]
Fatal(#[from] Fatal<NID>),
}
Expand Down Expand Up @@ -424,11 +421,6 @@ where
pub membership: Membership<NID, N>,
}

#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize), serde(bound = ""))]
#[error("initializing log entry has to be a membership config entry")]
pub struct NotAMembershipEntry {}

#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
#[error("new membership can not be empty")]
Expand Down

0 comments on commit 77e87a3

Please sign in to comment.