Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: remove unused client_serial_responses from memstore #1210

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 13 additions & 12 deletions openraft/src/engine/engine_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ where C: RaftTypeConfig
self.candidate.as_mut()
}

/// Get a LeaderHandler for handling leader's operation. If it is not a leader, it send back a
/// Get a LeaderHandler for handling leader's operation. If it is not a leader, it sends back a
/// ForwardToLeader error through the tx.
///
/// If tx is None, no response will be sent.
Expand Down Expand Up @@ -294,10 +294,11 @@ where C: RaftTypeConfig
pub(crate) fn handle_vote_req(&mut self, req: VoteRequest<C>) -> VoteResponse<C> {
let now = C::now();
let lease = self.config.timer_config.leader_lease;
let vote = self.state.vote_ref();
let local_vote = self.state.vote_ref();

// Make default vote-last-modified a low enough value, that expires leader lease.
let vote_utime = self.state.vote_last_modified().unwrap_or_else(|| now - lease - Duration::from_millis(1));
let local_vote_utime =
self.state.vote_last_modified().unwrap_or_else(|| now - lease - Duration::from_millis(1));

tracing::info!(req = display(&req), "Engine::handle_vote_req");
tracing::info!(
Expand All @@ -308,21 +309,21 @@ where C: RaftTypeConfig
tracing::info!(
"now; {}, vote is updated at: {}, vote is updated before {:?}, leader lease({:?}) will expire after {:?}",
now.display(),
vote_utime.display(),
now - vote_utime,
local_vote_utime.display(),
now - local_vote_utime,
lease,
vote_utime + lease - now
local_vote_utime + lease - now
);

if vote.is_committed() {
if local_vote.is_committed() {
// Current leader lease has not yet expired, reject voting request
if now <= vote_utime + lease {
if now <= local_vote_utime + lease {
tracing::info!(
"reject vote-request: leader lease has not yet expire; now; {:?}, vote is updatd at: {:?}, leader lease({:?}) will expire after {:?}",
"reject vote-request: leader lease has not yet expire; now; {:?}, vote is update at: {:?}, leader lease({:?}) will expire after {:?}",
now,
vote_utime,
local_vote_utime,
lease,
vote_utime + lease - now
local_vote_utime + lease - now
);

return VoteResponse::new(self.state.vote_ref(), self.state.last_log_id().copied());
Expand Down Expand Up @@ -704,7 +705,7 @@ where C: RaftTypeConfig
})
}

/// When initialize, the node that accept initialize request has to be a member of the initial
/// When initialized, the node that accept initialize request has to be a member of the initial
/// config.
fn check_members_contain_me(&self, m: &Membership<C>) -> Result<(), NotInMembers<C>> {
if !m.is_voter(&self.config.id) {
Expand Down
9 changes: 0 additions & 9 deletions stores/memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ pub struct MemStoreStateMachine {

pub last_membership: StoredMembership<TypeConfig>,

/// A mapping of client IDs to their state info.
pub client_serial_responses: HashMap<String, (u64, Option<String>)>,
/// The current status of a client by ID.
pub client_status: HashMap<String, String>,
}
Expand Down Expand Up @@ -448,14 +446,7 @@ impl RaftStateMachine<TypeConfig> for Arc<MemStateMachine> {
match entry.payload {
EntryPayload::Blank => res.push(ClientResponse(None)),
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()));
continue;
}
}
let previous = sm.client_status.insert(data.client.clone(), data.status.clone());
sm.client_serial_responses.insert(data.client.clone(), (data.serial, previous.clone()));
res.push(ClientResponse(previous));
}
EntryPayload::Membership(ref mem) => {
Expand Down
Loading