Skip to content

Commit 01a6979

Browse files
committedJan 8, 2018
Fix #29
1 parent 458f91d commit 01a6979

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed
 

‎floyd/src/floyd_peer_thread.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ void Peer::AppendEntriesRPC() {
222222
uint64_t num_entries = 0;
223223
uint64_t prev_log_term = 0;
224224
uint64_t last_log_index = 0;
225+
uint64_t current_term = 0;
225226
CmdRequest req;
226227
CmdRequest_AppendEntries* append_entries = req.mutable_append_entries();
227228
{
@@ -246,14 +247,17 @@ void Peer::AppendEntriesRPC() {
246247
prev_log_term = entry.term();
247248
}
248249
}
250+
current_term = context_->current_term;
249251

250252
req.set_type(Type::kAppendEntries);
251253
append_entries->set_ip(options_.local_ip);
252254
append_entries->set_port(options_.local_port);
253-
append_entries->set_term(context_->current_term);
255+
append_entries->set_term(current_term);
254256
append_entries->set_prev_log_index(prev_log_index);
255257
append_entries->set_prev_log_term(prev_log_term);
256258
append_entries->set_leader_commit(context_->commit_index);
259+
}
260+
257261
Entry *tmp_entry = new Entry();
258262
for (uint64_t index = next_index_; index <= last_log_index; index++) {
259263
if (raft_log_->GetEntry(index, tmp_entry) == 0) {
@@ -278,8 +282,7 @@ void Peer::AppendEntriesRPC() {
278282
// if the AppendEntries don't contain any log item
279283
if (num_entries == 0) {
280284
LOGV(INFO_LEVEL, info_log_, "Peer::AppendEntryRpc server %s:%d Send pingpong appendEntries message to %s at term %d",
281-
options_.local_ip.c_str(), options_.local_port, peer_addr_.c_str(), context_->current_term);
282-
}
285+
options_.local_ip.c_str(), options_.local_port, peer_addr_.c_str(), current_term);
283286
}
284287

285288
CmdResponse res;

0 commit comments

Comments
 (0)
Please sign in to comment.