Skip to content

Commit

Permalink
change mem cmp to take
Browse files Browse the repository at this point in the history
Signed-off-by: gengliqi <[email protected]>
  • Loading branch information
gengliqi committed Oct 21, 2020
1 parent d58b237 commit 87a03d0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,17 +456,15 @@ impl<T: Storage> RawNode<T> {
}

if !self.messages.is_empty() {
mem::swap(&mut self.messages, &mut rd.messages);
rd.messages = mem::take(&mut self.messages);
}
if !raft.msgs.is_empty() {
if raft.state == StateRole::Leader {
// Leader can send messages immediately to make replication concurrently
// For more details, check raft thesis 10.2.1.
let mut msgs = Vec::new();
mem::swap(&mut raft.msgs, &mut msgs);
rd.messages.push(msgs);
rd.messages.push(mem::take(&mut raft.msgs));
} else {
mem::swap(&mut raft.msgs, &mut rd_record.messages);
rd_record.messages = mem::take(&mut raft.msgs);
}
}
self.records.push_back(rd_record);
Expand Down Expand Up @@ -545,7 +543,8 @@ impl<T: Storage> RawNode<T> {
if record.number > number {
break;
}
let record = self.records.pop_front().unwrap();
let mut record = self.records.pop_front().unwrap();
println!("record {:?}", record);
if let Some(last_log) = record.last_entry {
self.raft.on_persist_entries(last_log.0, last_log.1);
self.last_persisted_index = last_log.0;
Expand All @@ -557,7 +556,7 @@ impl<T: Storage> RawNode<T> {
self.pending_snapshot = false;
}
if !record.messages.is_empty() {
self.messages.push(record.messages);
self.messages.push(mem::take(&mut record.messages));
}
}
}
Expand All @@ -583,11 +582,11 @@ impl<T: Storage> RawNode<T> {
self.commit_since_index = e.get_index();
}

mem::swap(&mut res.messages, &mut self.messages);
if !self.messages.is_empty() {
res.messages = mem::take(&mut self.messages);
}
if !raft.msgs.is_empty() && raft.state == StateRole::Leader {
let mut msgs = Vec::new();
mem::swap(&mut raft.msgs, &mut msgs);
res.messages.push(msgs);
res.messages.push(mem::take(&mut raft.msgs));
}
res
}
Expand Down

0 comments on commit 87a03d0

Please sign in to comment.