diff --git a/openraft/src/engine/engine_impl.rs b/openraft/src/engine/engine_impl.rs index 05d2c5af7..01f76218c 100644 --- a/openraft/src/engine/engine_impl.rs +++ b/openraft/src/engine/engine_impl.rs @@ -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; @@ -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 }); diff --git a/openraft/src/engine/initialize_test.rs b/openraft/src/engine/initialize_test.rs index 97c394e3c..35e79205e 100644 --- a/openraft/src/engine/initialize_test.rs +++ b/openraft/src/engine/initialize_test.rs @@ -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; @@ -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::::Blank; - let mut entries = [EntryRef::new(&payload)]; - - assert_eq!( - Err(InitializeError::NotAMembershipEntry(NotAMembershipEntry {})), - eng.initialize(&mut entries) - ); - } - Ok(()) } diff --git a/openraft/src/error.rs b/openraft/src/error.rs index 464a37b75..fd582d84a 100644 --- a/openraft/src/error.rs +++ b/openraft/src/error.rs @@ -171,9 +171,6 @@ where #[error(transparent)] NotInMembers(#[from] NotInMembers), - #[error(transparent)] - NotAMembershipEntry(#[from] NotAMembershipEntry), - #[error(transparent)] Fatal(#[from] Fatal), } @@ -424,11 +421,6 @@ where pub membership: Membership, } -#[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")]