diff --git a/floyd/src/floyd_impl.cc b/floyd/src/floyd_impl.cc index 1547e54..5e74be7 100644 --- a/floyd/src/floyd_impl.cc +++ b/floyd/src/floyd_impl.cc @@ -587,6 +587,13 @@ void FloydImpl::ReplyRequestVote(const CmdRequest& request, CmdResponse* respons CmdRequest_RequestVote request_vote = request.request_vote(); LOGV(DEBUG_LEVEL, info_log_, "FloydImpl::ReplyRequestVote: my_term=%lu request.term=%lu", context_->current_term, request_vote.term()); + /* + * If RPC request or response contains term T > currentTerm: set currentTerm = T, convert to follower (ยง5.1) + */ + if (request_vote.term() > context_->current_term) { + context_->BecomeFollower(request_vote.term()); + raft_meta_->SetCurrentTerm(context_->current_term); + } // if caller's term smaller than my term, then I will notice him if (request_vote.term() < context_->current_term) { LOGV(INFO_LEVEL, info_log_, "FloydImpl::ReplyRequestVote: Leader %s:%d term %lu is smaller than my %s:%d current term %lu", diff --git a/floyd/test/start_all.sh b/floyd/test/start_all.sh deleted file mode 100755 index c244f4a..0000000 --- a/floyd/test/start_all.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -server=../example/server/output/bin/floyd_node -client=../example/sdk/floyd_client - -# Start example/server group with 3 nodes -nohup ./$server --servers 127.0.0.1:9100,127.0.0.1:9101,127.0.0.1:9102 --local_ip 127.0.0.1 --local_port 9100 --sdk_port 8900 --data_path ./node1/data --log_path ./node1/log > node1.out 2>&1 & -nohup sleep 3; -nohup ./$server --servers 127.0.0.1:9100,127.0.0.1:9101,127.0.0.1:9102 --local_ip 127.0.0.1 --local_port 9101 --sdk_port 8901 --data_path ./node2/data --log_path ./node2/log > node2.out 2>&1 & -nohup ./$server --servers 127.0.0.1:9100,127.0.0.1:9101,127.0.0.1:9102 --local_ip 127.0.0.1 --local_port 9102 --sdk_port 8902 --data_path ./node3/data --log_path ./node3/log > node3.out 2>&1 & - -sleep 2; -./$client --server 127.0.0.1:8900 --cmd status --begin 0 --end 1 diff --git a/floyd/test/stop_all.sh b/floyd/test/stop_all.sh deleted file mode 100755 index 09e0125..0000000 --- a/floyd/test/stop_all.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash -server=../example/server/output/bin/floyd_node -client=../example/sdk/floyd_client - -# Start example/server group with 3 nodes -ps aux|grep "floyd_node" | awk '{print $2}' | xargs kill -9 -rm -rf *out *tmp node* *log diff --git a/floyd/test/test0.sh b/floyd/test/test0.sh deleted file mode 100755 index 443fc84..0000000 --- a/floyd/test/test0.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/bin/bash - -# Step 0, start example/server group with 3 nodes -sh start_all.sh - -## 1. Normal case Write Test: -log_file=./0.log -size=30 -client=../example/sdk/floyd_client - -./$client --server 127.0.0.1:8900 --cmd status --begin 0 --end 1 2> $log_file - -###################### -### Write a follower -###################### -./$client --server 127.0.0.1:8902 --cmd write --begin 0 --end $size 2>> $log_file - -./$client --server 127.0.0.1:8900 --cmd dirtyread --begin 0 --end $size 2> tmp0 -./$client --server 127.0.0.1:8901 --cmd dirtyread --begin 0 --end $size 2> tmp1 -./$client --server 127.0.0.1:8902 --cmd dirtyread --begin 0 --end $size 2> tmp2 - -echo "[Test 0] Normal Write/Delete\n" -diff tmp0 tmp1 -if [ $? -ne 0 ]; then - echo "0.0 different value after DirtyRead in tmp0 tmp1" -fi - -diff tmp0 tmp2 -if [ $? -ne 0 ]; then - echo "0.1 different value after DirtyRead in tmp0 tmp2" -fi - -###################### -### Write leader -###################### -end=$(( $size + $size )) -./$client --server 127.0.0.1:8900 --cmd write --begin $size --end $end 2>> $log_file - -./$client --server 127.0.0.1:8900 --cmd dirtyread --begin $size --end $end 2> tmp0 -./$client --server 127.0.0.1:8901 --cmd dirtyread --begin $size --end $end 2> tmp1 -./$client --server 127.0.0.1:8902 --cmd dirtyread --begin $size --end $end 2> tmp2 - -diff tmp0 tmp1 -if [ $? -ne 0 ]; then - echo "0.2 different value after DirtyRead in tmp0 tmp1" -fi - -diff tmp0 tmp2 -if [ $? -ne 0 ]; then - echo "0.3 different value after DirtyRead in tmp0 tmp2" -fi - - -## 2. Normal case Delete Test: -./$client --server 127.0.0.1:8902 --cmd delete --begin 0 --end $size 2>> $log_file -./$client --server 127.0.0.1:8900 --cmd dirtyread --begin 0 --end $size 2> del.tmp diff --git a/floyd/test/test1.sh b/floyd/test/test1.sh deleted file mode 100755 index 6da0186..0000000 --- a/floyd/test/test1.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/bash - -# Step 0, start example/server group with 3 nodes if needed -#sh start_all.sh - -## 1. Leader Crash -log_file=./0.log -size=30 -client=../example/sdk/floyd_client -server=../example/server/output/bin/floyd_node - -echo "[Test 1] Leader Crash\n" - -ps aux|grep "node1" | awk '{print $2}' | xargs kill -9 -sleep 1 -./$client --server 127.0.0.1:8902 --cmd write --begin 0 --end $size - -./$client --server 127.0.0.1:8901 --cmd dirtyread --begin 0 --end $size 2> tmp1 -./$client --server 127.0.0.1:8902 --cmd dirtyread --begin 0 --end $size 2> tmp2 - -diff tmp1 tmp2 -if [ $? -ne 0 ]; then - echo "1.0 different value after DirtyRead in tmp1 tmp2" -fi - -## 2. Restart Node1 -nohup ./$server --servers 127.0.0.1:9100,127.0.0.1:9101,127.0.0.1:9102 --local_ip 127.0.0.1 --local_port 9100 --sdk_port 8900 --data_path ./node1/data --log_path ./node1/log > node1.out 2>&1 & -sleep 1 -end=$(( $size + $size )) -./$client --server 127.0.0.1:8900 --cmd write --begin $size --end $end 2>> $log_file - -./$client --server 127.0.0.1:8900 --cmd dirtyread --begin $size --end $end 2> tmp0 -./$client --server 127.0.0.1:8901 --cmd dirtyread --begin $size --end $end 2> tmp1 -./$client --server 127.0.0.1:8902 --cmd dirtyread --begin $size --end $end 2> tmp2 - -diff tmp0 tmp1 -if [ $? -ne 0 ]; then - echo "1.2 different value after DirtyRead in tmp0 tmp1" -fi - -diff tmp0 tmp2 -if [ $? -ne 0 ]; then - echo "1.3 different value after DirtyRead in tmp0 tmp2" -fi