Here we have an incomplete implementation of a distributed calculator. This program has some HTTP POST APIs to receive addition, subtraction, and multiplication commands, as well as an HTTP GET API to return the current replicated result. It also has a web-based dashboard to facilitate issuing these commands and seeing the result on each node.
The requirement is syncing these commands with the other nodes in an asynchronous and fault-resilient way, with the Raft consensus algorithm.
You can run the nodes manually and use the web-based dashboards to test your implementation.
python3 node.py -i 50 -m 10101 -o 10103 10102 -p 9010
python3 node.py -i 50 -m 10102 -o 10103 10101 -p 9020
python3 node.py -i 50 -m 10103 -o 10102 10101 -p 9030This homework has three sections:
- You should use the raft protocol and complete the
consensus.pyfile to pass all test cases. There is no need to change other files.- There are some test cases provided in the
test.pyfile. You can run them withpython3 test.py.
- There are some test cases provided in the
- Explain in the Raft terminology, how nodes interact with each other in the
test_failure_and_recoverytest case. - Explain in the Raft terminology, why
test_weirdpasses.
Note that:
- Usage of the third-party packages is permitted.
- If you want to solve this homework with another programming language, you can write your own
nodeprogram and still usepython3 test.pyto test it. In this case, you should changeRUN_PREFIXin thetest.pyfile to address the executable of yournodeprogram. - You should not change the
test.pyfile unless you need to change thePYTHON_ADDRorRUN_PREFIXconstants. - You should not store/retrieve anything on/from the persistent storage. All communication between the
nodesshould be network-based. - You should not use
time.sleepin theconsensus.pyfile if you use the third-party packages.
