@@ -222,6 +222,7 @@ void Peer::AppendEntriesRPC() {
222
222
uint64_t num_entries = 0 ;
223
223
uint64_t prev_log_term = 0 ;
224
224
uint64_t last_log_index = 0 ;
225
+ uint64_t current_term = 0 ;
225
226
CmdRequest req;
226
227
CmdRequest_AppendEntries* append_entries = req.mutable_append_entries ();
227
228
{
@@ -246,14 +247,17 @@ void Peer::AppendEntriesRPC() {
246
247
prev_log_term = entry.term ();
247
248
}
248
249
}
250
+ current_term = context_->current_term ;
249
251
250
252
req.set_type (Type::kAppendEntries );
251
253
append_entries->set_ip (options_.local_ip );
252
254
append_entries->set_port (options_.local_port );
253
- append_entries->set_term (context_-> current_term );
255
+ append_entries->set_term (current_term);
254
256
append_entries->set_prev_log_index (prev_log_index);
255
257
append_entries->set_prev_log_term (prev_log_term);
256
258
append_entries->set_leader_commit (context_->commit_index );
259
+ }
260
+
257
261
Entry *tmp_entry = new Entry ();
258
262
for (uint64_t index = next_index_; index <= last_log_index; index ++) {
259
263
if (raft_log_->GetEntry (index , tmp_entry) == 0 ) {
@@ -278,8 +282,7 @@ void Peer::AppendEntriesRPC() {
278
282
// if the AppendEntries don't contain any log item
279
283
if (num_entries == 0 ) {
280
284
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);
283
286
}
284
287
285
288
CmdResponse res;
0 commit comments