Skip to content

Commit

Permalink
change: remove EntryNormal
Browse files Browse the repository at this point in the history
drmingdrmer committed Dec 23, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent e8c6674 commit 6625484
Showing 4 changed files with 22 additions and 39 deletions.
14 changes: 4 additions & 10 deletions async-raft/src/raft.rs
Original file line number Diff line number Diff line change
@@ -591,9 +591,11 @@ impl<D: AppData> MessageSummary for &[&Entry<D>] {
pub enum EntryPayload<D: AppData> {
/// An empty payload committed by a new cluster leader.
Blank,

/// A normal log entry.
#[serde(bound = "D: AppData")]
Normal(EntryNormal<D>),
Normal(D),

/// A config change log entry.
Membership(EntryMembership),
}
@@ -610,14 +612,6 @@ impl<D: AppData> MessageSummary for EntryPayload<D> {
}
}

/// A normal log entry.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EntryNormal<D: AppData> {
/// The contents of this entry.
#[serde(bound = "D: AppData")]
pub data: D,
}

/// A log entry holding a config change.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct EntryMembership {
@@ -800,7 +794,7 @@ impl<D: AppData> MessageSummary for ClientWriteRequest<D> {
impl<D: AppData> ClientWriteRequest<D> {
/// Create a new client payload instance with a normal entry type.
pub fn new(entry: D) -> Self {
Self::new_base(EntryPayload::Normal(EntryNormal { data: entry }))
Self::new_base(EntryPayload::Normal(entry))
}

/// Create a new instance.
11 changes: 4 additions & 7 deletions async-raft/tests/conflict_with_empty_entries.rs
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ use anyhow::Result;
use async_raft::raft::AppendEntriesRequest;
use async_raft::raft::ConflictOpt;
use async_raft::raft::Entry;
use async_raft::raft::EntryNormal;
use async_raft::raft::EntryPayload;
use async_raft::Config;
use async_raft::LogId;
@@ -81,12 +80,10 @@ async fn conflict_with_empty_entries() -> Result<()> {
},
Entry {
log_id: (1, 2).into(),
payload: EntryPayload::Normal(EntryNormal {
data: ClientRequest {
client: "foo".to_string(),
serial: 1,
status: "bar".to_string(),
},
payload: EntryPayload::Normal(ClientRequest {
client: "foo".to_string(),
serial: 1,
status: "bar".to_string(),
}),
},
],
3 changes: 1 addition & 2 deletions memstore/src/lib.rs
Original file line number Diff line number Diff line change
@@ -714,8 +714,7 @@ impl RaftStorage<ClientRequest, ClientResponse> for MemStore {

match entry.payload {
EntryPayload::Blank => res.push(ClientResponse(None)),
EntryPayload::Normal(ref norm) => {
let data = &norm.data;
EntryPayload::Normal(ref data) => {
if let Some((serial, r)) = sm.client_serial_responses.get(&data.client) {
if serial == &data.serial {
res.push(ClientResponse(r.clone()));
33 changes: 13 additions & 20 deletions memstore/src/test.rs
Original file line number Diff line number Diff line change
@@ -2,7 +2,6 @@ use std::future::Future;
use std::marker::PhantomData;

use async_raft::raft::EntryMembership;
use async_raft::raft::EntryNormal;
use async_trait::async_trait;
use maplit::btreeset;

@@ -828,12 +827,10 @@ where
let entry = Entry {
log_id: LogId { term: 3, index: 1 },

payload: EntryPayload::Normal(EntryNormal {
data: ClientRequest {
client: "0".into(),
serial: 0,
status: "lit".into(),
},
payload: EntryPayload::Normal(ClientRequest {
client: "0".into(),
serial: 0,
status: "lit".into(),
}),
};

@@ -888,7 +885,7 @@ where
.into_iter()
.map(|(id, req)| Entry {
log_id: *id,
payload: EntryPayload::Normal(EntryNormal { data: req.clone() }),
payload: EntryPayload::Normal(req.clone()),
})
.collect::<Vec<_>>();

@@ -1573,12 +1570,10 @@ where
let entry = Entry {
log_id: LogId { term: 3, index: 1 },

payload: EntryPayload::Normal(EntryNormal {
data: ClientRequest {
client: "0".into(),
serial: 0,
status: "lit".into(),
},
payload: EntryPayload::Normal(ClientRequest {
client: "0".into(),
serial: 0,
status: "lit".into(),
}),
};

@@ -1604,12 +1599,10 @@ where
let entry = Entry {
log_id: LogId { term: 3, index: 3 },

payload: EntryPayload::Normal(EntryNormal {
data: ClientRequest {
client: "0".into(),
serial: 0,
status: "lit".into(),
},
payload: EntryPayload::Normal(ClientRequest {
client: "0".into(),
serial: 0,
status: "lit".into(),
}),
};
let res = store.apply_to_state_machine(&[&entry]).await;

0 comments on commit 6625484

Please sign in to comment.