Skip to content

Commit

Permalink
WIP: Solving deadlock
Browse files Browse the repository at this point in the history
  • Loading branch information
eaneto committed May 5, 2024
1 parent e877210 commit 17343bb
Show file tree
Hide file tree
Showing 6 changed files with 182 additions and 94 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ bytes = { version = "1", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
bincode = "1.3.3"
rand = "0.8.5"
clokwerk = "0.4.0"
crossbeam = "0.8.4"
crossbeam-skiplist = "0.1.3"
2 changes: 1 addition & 1 deletion scripts/node1.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

export ROG_HOME=~/.rog1
RUST_LOG=trace ./target/debug/rog-server --port 7878 \
RUST_LOG=$1 ./target/debug/rog-server --port 7878 \
--id 1 --node-ids 2 --node-ids 3 \
--node-addresses "localhost:7879" \
--node-addresses "localhost:7880"
2 changes: 1 addition & 1 deletion scripts/node2.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

export ROG_HOME=~/.rog2
RUST_LOG=trace ./target/debug/rog-server --port 7879 \
RUST_LOG=$1 ./target/debug/rog-server --port 7879 \
--id 2 --node-ids 1 --node-ids 3 \
--node-addresses "localhost:7878" \
--node-addresses "localhost:7880"
2 changes: 1 addition & 1 deletion scripts/node3.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/sh

export ROG_HOME=~/.rog3
RUST_LOG=trace ./target/debug/rog-server --port 7880 \
RUST_LOG=$1 ./target/debug/rog-server --port 7880 \
--id 3 --node-ids 1 --node-ids 2 \
--node-addresses "localhost:7878" \
--node-addresses "localhost:7879"
8 changes: 4 additions & 4 deletions src/bin/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ async fn main() {
tokio::spawn(async move {
loop {
tokio::time::sleep(Duration::from_millis(100)).await;
//trace!("Broadcasting");
server_clone.lock().await.broadcast_current_log().await;
}
});
Expand All @@ -89,13 +88,14 @@ async fn main() {
tokio::time::sleep(election_timeout).await;
// TODO Check if election is needed.
// If heartbeats not received, then:
trace!("Start new election");
let mut server = server_clone.lock().await;
let time_elapsed = Instant::now() - election_timeout;
if server
.last_heartbeat()
let last_heartbeat = server.last_heartbeat().await;
if last_heartbeat
.is_some_and(|heartbeat| heartbeat.duration_since(time_elapsed) > election_timeout)
|| last_heartbeat.is_none()
{
warn!("No heartbeats from leader, starting a new election");
server.start_election().await;
}
}
Expand Down
Loading

0 comments on commit 17343bb

Please sign in to comment.