Skip to content

Commit

Permalink
Merge pull request #65 from GrapeBaBa/issue_62
Browse files Browse the repository at this point in the history
[#62]Make first_known_log_id default impl
  • Loading branch information
mergify[bot] committed Jan 5, 2022
2 parents 512b3b5 + 1dfdeab commit 0552ffb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
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

0 comments on commit 0552ffb

Please sign in to comment.