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

[#62]Make first_known_log_id default impl #65

Merged
merged 2 commits into from
Jan 5, 2022
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
11 changes: 0 additions & 11 deletions memstore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,17 +243,6 @@ impl RaftStorage<ClientRequest, ClientResponse> for MemStore {
Ok(first)
}

async fn first_known_log_id(&self) -> Result<LogId, StorageError> {
let first = self.first_id_in_log().await?;
let (last_applied, _) = self.last_applied_state().await?;

if let Some(x) = first {
return Ok(std::cmp::min(x, last_applied));
}

Ok(last_applied)
}

async fn last_id_in_log(&self) -> Result<LogId, StorageError> {
let log = self.log.read().await;
let last = log.iter().last().map(|(_, ent)| ent.log_id).unwrap_or_default();
Expand Down
11 changes: 10 additions & 1 deletion openraft/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,16 @@ where
/// The impl should not consider the applied log id in state machine.
async fn first_id_in_log(&self) -> Result<Option<LogId>, StorageError>;

async fn first_known_log_id(&self) -> Result<LogId, StorageError>;
async fn first_known_log_id(&self) -> Result<LogId, StorageError> {
let first = self.first_id_in_log().await?;
let (last_applied, _) = self.last_applied_state().await?;

if let Some(x) = first {
return Ok(std::cmp::min(x, last_applied));
}

Ok(last_applied)
}

/// Returns the last log id in log.
///
Expand Down