diff --git a/.gitignore b/.gitignore index 55061108..adb087dd 100644 --- a/.gitignore +++ b/.gitignore @@ -10,4 +10,6 @@ rocksdb/ rocksdb protobuf/ spdlog/ -spdlog \ No newline at end of file +spdlog +logs +logs/ \ No newline at end of file diff --git a/Makefile b/Makefile index 01041067..0fcb8ae3 100644 --- a/Makefile +++ b/Makefile @@ -51,17 +51,17 @@ rm-net: docker network rm mytestnetwork run-demo: - docker run --name kvserver-node1 --network mytestnetwork --ip 172.18.0.10 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 0 /tmp/kv_db0 /tmp/log_db0 /tmp/snap_db0 172.18.0.10:8088,172.18.0.11:8089,172.18.0.12:8090 /tmp/log1.log + docker run --name kvserver-node1 --network mytestnetwork --ip 172.18.0.10 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 0 /tmp/kv_db0 /tmp/log_db0 /tmp/snap_db0 172.18.0.10:8088,172.18.0.11:8089,172.18.0.12:8090 /eraft/logs/eraftkv-1.log sleep 2 - docker run --name kvserver-node2 --network mytestnetwork --ip 172.18.0.11 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 1 /tmp/kv_db1 /tmp/log_db1 /tmp/snap_db1 172.18.0.10:8088,172.18.0.11:8089,172.18.0.12:8090 /tmp/log2.log - docker run --name kvserver-node3 --network mytestnetwork --ip 172.18.0.12 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 2 /tmp/kv_db2 /tmp/log_db2 /tmp/snap_db2 172.18.0.10:8088,172.18.0.11:8089,172.18.0.12:8090 /tmp/log3.log + docker run --name kvserver-node2 --network mytestnetwork --ip 172.18.0.11 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 1 /tmp/kv_db1 /tmp/log_db1 /tmp/snap_db1 172.18.0.10:8088,172.18.0.11:8089,172.18.0.12:8090 /eraft/logs/eraftkv-2.log + docker run --name kvserver-node3 --network mytestnetwork --ip 172.18.0.12 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftkv 2 /tmp/kv_db2 /tmp/log_db2 /tmp/snap_db2 172.18.0.10:8088,172.18.0.11:8089,172.18.0.12:8090 /eraft/logs/eraftkv-3.log sleep 1 docker run --name metaserver-node1 --network mytestnetwork --ip 172.18.0.2 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftmeta 0 /tmp/meta_db0 /tmp/log_db0 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090 sleep 3 docker run --name metaserver-node2 --network mytestnetwork --ip 172.18.0.3 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftmeta 1 /tmp/meta_db1 /tmp/log_db1 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090 docker run --name metaserver-node3 --network mytestnetwork --ip 172.18.0.4 -d --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraftmeta 2 /tmp/meta_db2 /tmp/log_db2 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090 sleep 16 - docker run --name vdbserver-node --network mytestnetwork --ip 172.18.0.6 -it --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraft-kdb 172.18.0.6:12306 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090 /tmp/eraft-kdb.log + docker run --name vdbserver-node --network mytestnetwork --ip 172.18.0.6 -it --rm -v $(realpath .):/eraft eraft/eraftkv:v0.0.6 /eraft/build/eraft-kdb 172.18.0.6:12306 172.18.0.2:8088,172.18.0.3:8089,172.18.0.4:8090 /eraft/logs/eraftkdb.log stop-demo: docker stop kvserver-node1 kvserver-node2 kvserver-node3 vdbserver-node metaserver-node1 metaserver-node2 metaserver-node3 diff --git a/src/raft_server.cc b/src/raft_server.cc index b2102f88..675be00f 100644 --- a/src/raft_server.cc +++ b/src/raft_server.cc @@ -796,6 +796,10 @@ EStatus RaftServer::BecomeLeader() { this->role_ = NodeRaftRoleEnum::Leader; heartbeat_tick_count_ = 0; this->leader_id_ = this->id_; + for (auto node : this->nodes_) { + node->next_log_index = this->log_store_->LastIndex() + 1; + node->match_log_index = 0; + } election_running_ = false; return EStatus::kOk; } @@ -860,7 +864,6 @@ EStatus RaftServer::ElectionStart(bool is_prevote) { this->current_term_ += 1; vote_req->set_term(this->current_term_); } - // vote_req->set_term(this->current_term_); vote_req->set_candidtate_id(this->id_); vote_req->set_last_log_idx(this->log_store_->LastIndex()); vote_req->set_last_log_term(this->log_store_->GetLastEty()->term());