Skip to content

Commit

Permalink
cargo clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
mmastrac committed Jul 4, 2024
1 parent f1039af commit a4113fe
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 53 deletions.
18 changes: 8 additions & 10 deletions edb/server/conn_pool/src/algo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,14 @@ pub trait PoolAlgorithmDataBlock: PoolAlgorithmDataMetrics {
// may still be hungry if current == target.
if current > target {
None
} else if target > current {
let diff = target - current;
let score = diff * HUNGER_DIFF_WEIGHT + waiters * HUNGER_WAITER_WEIGHT;
score.try_into().ok()
} else if waiters > 0 {
(waiters * HUNGER_WAITER_WEIGHT).try_into().ok()
} else {
if target > current {
let diff = target - current;
let score = diff * HUNGER_DIFF_WEIGHT + waiters * HUNGER_WAITER_WEIGHT;
score.try_into().ok()
} else if waiters > 0 {
(waiters * HUNGER_WAITER_WEIGHT).try_into().ok()
} else {
None
}
None
}
}

Expand Down Expand Up @@ -363,7 +361,7 @@ impl PoolConstraints {
let overfullness: usize = overfullness.into();
if overfullness > max {
which = Some(name.clone());
max = overfullness.into();
max = overfullness;
}
}
});
Expand Down
10 changes: 3 additions & 7 deletions edb/server/conn_pool/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -449,17 +449,13 @@ impl<C: Connector> VisitPoolAlgoData<Block<C, PoolAlgoTargetData>>
}

fn with<T>(&self, db: &str, f: impl Fn(&Block<C, PoolAlgoTargetData>) -> T) -> Option<T> {
if let Some(block) = self.map.borrow().get(db) {
Some(f(&block))
} else {
None
}
self.map.borrow().get(db).map(|block| f(block))
}

fn with_all(&self, mut f: impl FnMut(&Name, &Block<C, PoolAlgoTargetData>)) {
for it in self.map.borrow().values() {
// // trace!("{}: {:?}", it.db_name, it.metrics().summary());
f(&it.db_name, &it);
f(&it.db_name, it);
}
}
}
Expand Down Expand Up @@ -627,7 +623,7 @@ impl<C: Connector, D: Default> Blocks<C, D> {
#[cfg(test)]
mod tests {
use super::*;
use crate::metrics::{ConnMetrics, MetricVariant, VariantArray};
use crate::metrics::{MetricVariant, VariantArray};
use crate::test::*;
use anyhow::{Ok, Result};
use pretty_assertions::assert_eq;
Expand Down
2 changes: 1 addition & 1 deletion edb/server/conn_pool/src/conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ impl<C: Connector> ConnHandle<C> {
std::mem::replace(
&mut self.conn,
Conn {
inner: Rc::new(RefCell::new(ConnInner::Closed.into())),
inner: Rc::new(RefCell::new(ConnInner::Closed)),
},
)
}
Expand Down
14 changes: 6 additions & 8 deletions edb/server/conn_pool/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,12 @@ impl<const SIZE: usize> RollingAverageU32<SIZE> {
pub fn avg(&self) -> u32 {
if SIZE == 1 {
self.values[0]
} else if self.rollover {
(self.cumulative / SIZE as u64) as u32
} else if self.ptr == 0 {
0
} else {
if self.rollover {
(self.cumulative / SIZE as u64) as u32
} else if self.ptr == 0 {
0
} else {
(self.cumulative / self.ptr as u64) as u32
}
(self.cumulative / self.ptr as u64) as u32
}
}
}
Expand Down Expand Up @@ -106,7 +104,7 @@ impl<T> std::ops::IndexMut<MetricVariant> for VariantArray<T> {
impl<T: Copy + std::ops::AddAssign> std::ops::Add for VariantArray<T> {
type Output = VariantArray<T>;
fn add(self, rhs: Self) -> Self::Output {
let mut out = *&self;
let mut out = self;
for i in MetricVariant::iter() {
out[i] += rhs[i];
}
Expand Down
19 changes: 9 additions & 10 deletions edb/server/conn_pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,14 +252,14 @@ impl<C: Connector> Pool<C> {
#[cfg(test)]
mod tests {
use super::*;
use crate::{pool, test::*};
use crate::test::*;
use anyhow::{Ok, Result};
use rand::random;

use rstest::rstest;
use scopeguard::defer;
use std::{cell::RefCell, collections::HashMap, default, rc::Rc};

use std::rc::Rc;
use test_log::test;
use tokio::task::{JoinHandle, LocalSet};
use tokio::task::LocalSet;
use tracing::{info, trace};

#[test(tokio::test)]
Expand Down Expand Up @@ -356,8 +356,8 @@ mod tests {
let local = LocalSet::new();
local
.run_until(async {
let disconnect_cost = spec.disconn_cost.clone();
let connect_cost = spec.disconn_cost.clone();
let disconnect_cost = spec.disconn_cost;
let connect_cost = spec.disconn_cost;
let pool = Pool::new(
config,
BasicConnector::delay(move |disconnect| {
Expand Down Expand Up @@ -417,7 +417,7 @@ mod tests {
}
let monitor = {
let pool = pool.clone();
let monitor = tokio::task::spawn_local(async move {
tokio::task::spawn_local(async move {
let mut orig = "".to_owned();
loop {
pool.run_once();
Expand All @@ -431,8 +431,7 @@ mod tests {
}
virtual_sleep(Duration::from_millis(10)).await;
}
});
monitor
})
};

info!("Starting...");
Expand Down
27 changes: 10 additions & 17 deletions edb/server/conn_pool/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
//! Test utilities.
use std::{
cell::RefCell,
collections::HashMap,
future::Future,
ops::{Range, RangeBounds},
rc::Rc,
time::Duration,
cell::RefCell, collections::HashMap, future::Future, ops::Range, rc::Rc, time::Duration,
};

use itertools::Itertools;
use rand::random;
use statrs::statistics::{Data, Distribution, OrderStatistics, Statistics};
use tracing::{info, warn};
use tracing::info;

use crate::{
conn::{ConnResult, Connector},
metrics::{self, MetricVariant, PoolMetrics},
metrics::{MetricVariant, PoolMetrics},
};

#[derive(derive_more::Debug)]
Expand Down Expand Up @@ -118,7 +113,7 @@ impl std::fmt::Debug for Latencies {
let mut s = f.debug_struct("Latencies");
let data = self.data.borrow();
let mut all = vec![];
for key in data.keys().into_iter().sorted() {
for key in data.keys().sorted() {
let data = &data.get(key).unwrap();
all.extend_from_slice(data);
let stats = stats(data);
Expand All @@ -135,16 +130,16 @@ fn stats(data: &[f64]) -> Stats {
all.sort_by(|a, b| a.partial_cmp(b).unwrap());
let sum: f64 = all.iter().map(|v| v.ln()).sum();
let mean: f64 = (sum / (all.len() as f64)).exp();
let stats = Stats {

Stats {
p01: all[all.len() / 99],
p25: all[all.len() / 4],
p50: all[all.len() / 2],
p75: all[all.len() * 3 / 4],
p99: all[all.len() * 99 / 100],
mean,
count: all.len(),
};
stats
}
}

#[derive(smart_default::SmartDefault)]
Expand Down Expand Up @@ -196,12 +191,10 @@ impl Score {
} else {
0.0
}
} else if value < self.v0 {
0.0
} else {
if value < self.v0 {
0.0
} else {
100.0
}
100.0
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions edb/server/conn_pool/src/waitqueue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ pub struct WaitQueue {
pub(crate) lock: Cell<usize>,
}

impl Default for WaitQueue {
fn default() -> Self {
Self::new()
}
}

impl WaitQueue {
pub fn new() -> Self {
Self {
Expand Down

0 comments on commit a4113fe

Please sign in to comment.