(&mut self, peer: u64)
| 161 | } |
| 162 | |
| 163 | pub(super) fn send_append_entries(&mut self, peer: u64) { |
| 164 | let leader = match &self.leader_state { |
| 165 | Some(ls) => ls, |
| 166 | None => return, |
| 167 | }; |
| 168 | |
| 169 | let next_index = leader.next_index_for(peer); |
| 170 | let prev_log_index = next_index.saturating_sub(1); |
| 171 | |
| 172 | let prev_log_term = match self.log.term_at(prev_log_index) { |
| 173 | Some(term) => term, |
| 174 | None => { |
| 175 | debug!( |
| 176 | node = self.config.node_id, |
| 177 | group = self.config.group_id, |
| 178 | peer, |
| 179 | next_index, |
| 180 | snapshot_index = self.log.snapshot_index(), |
| 181 | "peer needs snapshot (log compacted)" |
| 182 | ); |
| 183 | self.ready.snapshots_needed.push(peer); |
| 184 | return; |
| 185 | } |
| 186 | }; |
| 187 | |
| 188 | let entries = if next_index <= self.log.last_index() { |
| 189 | match self.log.entries_range(next_index, self.log.last_index()) { |
| 190 | Ok(slice) => slice.to_vec(), |
| 191 | Err(RaftError::LogCompacted { .. }) => { |
| 192 | debug!( |
| 193 | node = self.config.node_id, |
| 194 | group = self.config.group_id, |
| 195 | peer, |
| 196 | next_index, |
| 197 | "peer needs snapshot (entries compacted)" |
| 198 | ); |
| 199 | self.ready.snapshots_needed.push(peer); |
| 200 | return; |
| 201 | } |
| 202 | Err(_) => vec![], |
| 203 | } |
| 204 | } else { |
| 205 | vec![] |
| 206 | }; |
| 207 | |
| 208 | self.ready.messages.push(( |
| 209 | peer, |
| 210 | AppendEntriesRequest { |
| 211 | term: self.hard_state.current_term, |
| 212 | leader_id: self.config.node_id, |
| 213 | prev_log_index, |
| 214 | prev_log_term, |
| 215 | entries, |
| 216 | leader_commit: self.volatile.commit_index, |
| 217 | group_id: self.config.group_id, |
| 218 | }, |
| 219 | )); |
| 220 | } |
no test coverage detected