spacewalkhq / raft-rs

An understandable, fast and scalable Raft Consensus implementation
MIT License
129 stars 21 forks source link

add raft add_node example #29

Closed dierbei closed 3 months ago

dierbei commented 3 months ago

Submitted out of the blue, sorry; I don't want to miss out on this learning experience.

Perhaps there will be a better way to organize this, so please help me review it, thanks;

Fixed #24

vaibhawvipul commented 3 months ago

@dierbei Can you please run this and attach a screenshot?

Ideally it should run with - cargo run --example simulate_add_node

dierbei commented 3 months ago

@dierbei Can you please run this and attach a screenshot?

Ideally it should run with - cargo run --example simulate_add_node

This is the log of the running program:

raft-rs git:(add-node) cargo run --example simulate_add_node
   Compiling raft_rs v0.1.0 (/cloudide/workspace/raft-rs)
    Finished dev [unoptimized + debuginfo] target(s) in 3.27s
     Running `target/debug/examples/simulate_add_node`
2024-08-07 08:02:31 INFO No log entries found on disk, id: 1, default leader: 1, port: 5001, address: 127.0.0.1
2024-08-07 08:02:31 INFO Server 1 is a follower, id: 1, default leader: 1, port: 5001, address: 127.0.0.1
2024-08-07 08:02:31 INFO Server 1 is the leader, id: 1, default leader: 1, port: 5001, address: 127.0.0.1
2024-08-07 08:02:31 INFO No log entries found on disk, id: 2, default leader: 1, port: 5002, address: 127.0.0.1
2024-08-07 08:02:31 INFO No log entries found on disk, id: 3, default leader: 1, port: 5003, address: 127.0.0.1
2024-08-07 08:02:31 INFO Server 2 is a follower, id: 2, default leader: 1, port: 5002, address: 127.0.0.1
2024-08-07 08:02:31 INFO Server 3 is a follower, id: 3, default leader: 1, port: 5003, address: 127.0.0.1
2024-08-07 08:02:31 INFO No log entries found on disk, id: 4, default leader: 1, port: 5004, address: 127.0.0.1
2024-08-07 08:02:31 INFO No log entries found on disk, id: 5, default leader: 1, port: 5005, address: 127.0.0.1
2024-08-07 08:02:31 INFO Server 4 is a follower, id: 4, default leader: 1, port: 5004, address: 127.0.0.1
2024-08-07 08:02:31 INFO Server 5 is a follower, id: 5, default leader: 1, port: 5005, address: 127.0.0.1
2024-08-07 08:02:41 INFO No log entries found on disk, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:41 INFO Server 6 is a follower, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:43 INFO Server 6 is a candidate, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:43 INFO Starting election, id: 6, term: 2, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:43 INFO Candidate address not found, id: 2, default leader: 1, port: 5002, address: 127.0.0.1
2024-08-07 08:02:43 INFO Candidate address not found, id: 4, default leader: 1, port: 5004, address: 127.0.0.1
2024-08-07 08:02:43 INFO Candidate address not found, id: 5, default leader: 1, port: 5005, address: 127.0.0.1
2024-08-07 08:02:43 INFO Candidate address not found, id: 3, default leader: 1, port: 5003, address: 127.0.0.1
2024-08-07 08:02:44 INFO Election timeout, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:44 INFO No log entries found on disk, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:44 INFO Server 6 is a follower, id: 6, default leader: 1, port: 5006, address: 127.0.0.1
2024-08-07 08:02:44 INFO Received join request: "\0\0\0\u{6}\0\0\0\0\0\0\0\n127.0.0.1:5006", id: 1, default leader: 1, port: 5001, address: 127.0.0.1
2024-08-07 08:02:44 INFO Current cluster nodes: ["127.0.0.1:5004", "127.0.0.1:5003", "127.0.0.1:5005", "127.0.0.1:5001", "127.0.0.1:5002"], want join node: 127.0.0.1:5006, id: 1, default leader: 1, port: 5001, address: 127.0.0.1
2024-08-07 08:02:44 INFO Joined the cluster with leader: 1, own id: 6, id: 6, default leader: 1, port: 5006, address: 127.0.0.1