Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
Signed-off-by: glorv <[email protected]>
  • Loading branch information
glorv committed Feb 21, 2025
1 parent 09742ec commit d5a0e2c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion examples/five_mem_node/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ fn on_ready(
}
}

let reg = Regex::new("put ([0-9]+) (.+)").unwrap();
let mut handle_committed_entries =
|rn: &mut RawNode<MemStorage>, committed_entries: Vec<Entry>| {
for entry in committed_entries {
Expand All @@ -295,7 +296,6 @@ fn on_ready(
// For normal proposals, extract the key-value pair and then
// insert them into the kv engine.
let data = str::from_utf8(&entry.data).unwrap();
let reg = Regex::new("put ([0-9]+) (.+)").unwrap();
if let Some(caps) = reg.captures(data) {
kv_pairs.insert(caps[1].parse().unwrap(), caps[2].to_string());
}
Expand Down
16 changes: 8 additions & 8 deletions harness/tests/integration_cases/test_raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ fn test_raw_node_propose_and_conf_change() {
}
};
handle_committed_entries(&mut raw_node, rd.take_committed_entries());
let is_leader = rd.ss().map_or(false, |ss| ss.leader_id == raw_node.raft.id);
let is_leader = rd.ss().is_some_and(|ss| ss.leader_id == raw_node.raft.id);

let mut light_rd = raw_node.advance(rd);
handle_committed_entries(&mut raw_node, light_rd.take_committed_entries());
Expand Down Expand Up @@ -408,7 +408,7 @@ fn test_raw_node_joint_auto_leave() {
}
};
handle_committed_entries(&mut raw_node, rd.take_committed_entries());
let is_leader = rd.ss().map_or(false, |ss| ss.leader_id == raw_node.raft.id);
let is_leader = rd.ss().is_some_and(|ss| ss.leader_id == raw_node.raft.id);

let mut light_rd = raw_node.advance(rd);
handle_committed_entries(&mut raw_node, light_rd.take_committed_entries());
Expand Down Expand Up @@ -486,7 +486,7 @@ fn test_raw_node_propose_add_duplicate_node() {
loop {
let rd = raw_node.ready();
s.wl().append(rd.entries()).unwrap();
if rd.ss().map_or(false, |ss| ss.leader_id == raw_node.raft.id) {
if rd.ss().is_some_and(|ss| ss.leader_id == raw_node.raft.id) {
let _ = raw_node.advance(rd);
break;
}
Expand Down Expand Up @@ -555,7 +555,7 @@ fn test_raw_node_propose_add_learner_node() -> Result<()> {
loop {
let rd = raw_node.ready();
s.wl().append(rd.entries()).unwrap();
if rd.ss().map_or(false, |ss| ss.leader_id == raw_node.raft.id) {
if rd.ss().is_some_and(|ss| ss.leader_id == raw_node.raft.id) {
let _ = raw_node.advance(rd);
break;
}
Expand Down Expand Up @@ -605,7 +605,7 @@ fn test_raw_node_read_index() {
loop {
let rd = raw_node.ready();
s.wl().append(rd.entries()).unwrap();
if rd.ss().map_or(false, |ss| ss.leader_id == raw_node.raft.id) {
if rd.ss().is_some_and(|ss| ss.leader_id == raw_node.raft.id) {
let _ = raw_node.advance(rd);

// Once we are the leader, issue a read index request
Expand Down Expand Up @@ -839,7 +839,7 @@ fn test_bounded_uncommitted_entries_growth_with_partition() {
s.wl().append(rd.entries()).unwrap();
if rd
.ss()
.map_or(false, |ss| ss.leader_id == raw_node.raft.leader_id)
.is_some_and(|ss| ss.leader_id == raw_node.raft.leader_id)
{
let _ = raw_node.advance(rd);
break;
Expand Down Expand Up @@ -1052,7 +1052,7 @@ fn test_raw_node_with_async_apply() {
// Single node should become leader.
assert!(rd
.ss()
.map_or(false, |ss| ss.leader_id == raw_node.raft.leader_id));
.is_some_and(|ss| ss.leader_id == raw_node.raft.leader_id));
s.wl().append(rd.entries()).unwrap();
let _ = raw_node.advance(rd);

Expand Down Expand Up @@ -1277,7 +1277,7 @@ fn test_async_ready_leader() {
let rd = raw_node.ready();
assert!(rd
.ss()
.map_or(false, |ss| ss.leader_id == raw_node.raft.leader_id));
.is_some_and(|ss| ss.leader_id == raw_node.raft.leader_id));
s.wl().append(rd.entries()).unwrap();
let _ = raw_node.advance(rd);

Expand Down
8 changes: 4 additions & 4 deletions src/raft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,14 +583,14 @@ impl<T: Storage> Raft<T> {
pub fn commit_to_current_term(&self) -> bool {
self.raft_log
.term(self.raft_log.committed)
.map_or(false, |t| t == self.term)
.is_ok_and(|t| t == self.term)
}

/// Checks if logs are applied to current term.
pub fn apply_to_current_term(&self) -> bool {
self.raft_log
.term(self.raft_log.applied)
.map_or(false, |t| t == self.term)
.is_ok_and(|t| t == self.term)
}

/// Set `max_committed_size_per_ready` to `size`.
Expand Down Expand Up @@ -2753,7 +2753,7 @@ impl<T: Storage> Raft<T> {
.r
.read_only
.recv_ack(self.id, &ctx)
.map_or(false, |acks| prs.has_quorum(acks))
.is_some_and(|acks| prs.has_quorum(acks))
{
for rs in self.r.read_only.advance(&ctx, &self.r.logger) {
if let Some(m) = self.handle_ready_read_index(rs.req, rs.index) {
Expand All @@ -2765,7 +2765,7 @@ impl<T: Storage> Raft<T> {

if self
.lead_transferee
.map_or(false, |e| !self.prs.conf().voters.contains(e))
.is_some_and(|e| !self.prs.conf().voters.contains(e))
{
self.abort_leader_transfer();
}
Expand Down
4 changes: 2 additions & 2 deletions src/raft_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<T: Storage> RaftLog<T> {

/// Attempts to commit the index and term and returns whether it did.
pub fn maybe_commit(&mut self, max_index: u64, term: u64) -> bool {
if max_index > self.committed && self.term(max_index).map_or(false, |t| t == term) {
if max_index > self.committed && self.term(max_index).is_ok_and(|t| t == term) {
debug!(
self.unstable.logger,
"committing index {index}",
Expand Down Expand Up @@ -554,7 +554,7 @@ impl<T: Storage> RaftLog<T> {
};
if index > self.persisted
&& index < first_update_index
&& self.store.term(index).map_or(false, |t| t == term)
&& self.store.term(index).is_ok_and(|t| t == term)
{
debug!(self.unstable.logger, "persisted index {}", index);
self.persisted = index;
Expand Down
2 changes: 1 addition & 1 deletion src/raw_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ impl<T: Storage> RawNode<T> {
return true;
}

if self.snap().map_or(false, |s| !s.is_empty()) {
if self.snap().is_some_and(|s| !s.is_empty()) {
return true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/tracker/inflights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ impl Inflights {
/// Returns true if the inflights is full.
#[inline]
pub fn full(&self) -> bool {
self.count == self.cap || self.incoming_cap.map_or(false, |cap| self.count >= cap)
self.count == self.cap || self.incoming_cap.is_some_and(|cap| self.count >= cap)
}

/// Adds an inflight into inflights
Expand Down

0 comments on commit d5a0e2c

Please sign in to comment.