erikgrinaker / toydb

Distributed SQL database in Rust, written as a learning project
Apache License 2.0
5.99k stars 555 forks source link

raft: add preVote before election #48

Closed iamazy closed 2 years ago

iamazy commented 3 years ago

@erikgrinaker Hi, I add preVote for toydb's raft. I could run cargo build but I ran cargo test failed and got error message as follow:

failures:
    client::pool::drop_rollback
    client::pool::get
    cluster::isolation::anomaly_dirty_read
    cluster::isolation::anomaly_fuzzy_read
    cluster::isolation::anomaly_phantom_read
    cluster::isolation::anomaly_read_skew
    cluster::recovery::client_commit_error
    cluster::recovery::client_disconnect_rollback

I don't know what is the relationship between the code I modified and the code reported the error. If you have free time, Can you tell me the causes of this problem so that I can correct it later. Thank you for any help you can offer.

erikgrinaker commented 3 years ago

Hi! You may want to make sure you don't have a running toydb instance on port 9605 when running the tests, as the test node will also bind to 9605 causing messages to be distributed randomly across the test node and running node. Might be a good idea to change the tests to pick other port numbers

Btw, while this is great (and pre-vote is definitely necessary for any production Raft implementation), I would like to keep toydb as minimal and simple as possible. It is mostly meant to be a simple educational database, so I think these kinds of optimizations add unnecessary complexity that may confuse readers. But you're of course free to fork it and extend it in any way you'd like. :)

iamazy commented 3 years ago

Hi! You may want to make sure you don't have a running toydb instance on port 9605 when running the tests, as the test node will also bind to 9605 causing messages to be distributed randomly across the test node and running node. Might be a good idea to change the tests to pick other port numbers

Btw, while this is great (and pre-vote is definitely necessary for any production Raft implementation), I would like to keep toydb as minimal and simple as possible. It is mostly meant to be a simple educational database, so I think these kinds of optimizations add unnecessary complexity that may confuse readers. But you're of course free to fork it and extend it in any way you'd like. :)

@erikgrinaker, thanks for replying. I am a novice rust programmer and I use this project to learn db and raft. Thanks for your work.