Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
akiradeveloper committed May 24, 2024
1 parent 45aca8e commit 12e0533
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lolraft/src/process/command_log/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Inner {

// If the same snapshot already exists, we can skip the insertion.
if new_snapshot_index == cur_snapshot_index {
return Ok(())
return Ok(());
}

self.storage.insert_entry(new_snapshot_index, e).await?;
Expand Down
11 changes: 4 additions & 7 deletions lolraft/src/process/peer_svc/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl PeerSvc {
})
}

pub async fn advance_replication(&self, follower_id: NodeId) -> Result<bool> {
pub async fn advance_replication(&self, follower_id: NodeId) -> Result<()> {
let peer_context = self
.peer_contexts
.read()
Expand All @@ -43,10 +43,7 @@ impl PeerSvc {
let cur_last_log_index = self.command_log.get_log_last_index().await?;

// More entries to send?
let should_send = old_progress.next_index <= cur_last_log_index;
if !should_send {
return Ok(false);
}
ensure!(old_progress.next_index <= cur_last_log_index);

// The entries to be sent may be deleted due to a previous compaction.
// In this case, replication will reset from the current snapshot index.
Expand All @@ -62,7 +59,7 @@ impl PeerSvc {
.get_mut(&follower_id)
.context(Error::PeerNotFound(follower_id.clone()))?
.progress = new_progress;
return Ok(true);
return Ok(());
}

let n_max_possible = cur_last_log_index - old_progress.next_index + 1;
Expand Down Expand Up @@ -107,6 +104,6 @@ impl PeerSvc {
.context(Error::PeerNotFound(follower_id.clone()))?
.progress = new_progress;

Ok(true)
Ok(())
}
}
5 changes: 2 additions & 3 deletions lolraft/src/process/thread/replication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ impl Thread {
return Ok(false);
}

let cont = self
.peers
self.peers
.advance_replication(self.follower_id.clone())
.await?;

Ok(cont)
Ok(true)
}

fn do_loop(self) -> ThreadHandle {
Expand Down
2 changes: 1 addition & 1 deletion tests/env/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ async fn drop_env() -> Result<()> {
}

Ok(())
}
}
3 changes: 1 addition & 2 deletions tests/lol-tests/tests/multi_raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@ async fn N3_L100_K3_multi_raft_cluster() -> Result<()> {
futs.push(fut);
}
futures::future::try_join_all(futs).await?;

Ok(())
}


#[serial]
#[tokio::test(flavor = "multi_thread")]
async fn N1_L100_K3_multi_raft_io() -> Result<()> {
Expand Down
4 changes: 1 addition & 3 deletions tests/testapp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ impl Client {
use tokio_retry::Retry;

// 200ms, 400, 800, 1600, 3200
let strategy = ExponentialBackoff::from_millis(2)
.factor(100)
.take(8);
let strategy = ExponentialBackoff::from_millis(2).factor(100).take(8);

let fut = Retry::spawn(strategy, || {
let mut cli = self.cli.clone();
Expand Down

0 comments on commit 12e0533

Please sign in to comment.