Simplify code and use match to harden logic (#33409)
addressed more feedback from Jon: Simplify code and use match to harden logic in connection cache
This commit is contained in:
parent
3608378097
commit
3fbfa0e0da
|
@ -196,8 +196,8 @@ where
|
|||
}
|
||||
|
||||
fn create_connection_internal(
|
||||
config: &Arc<C>,
|
||||
connection_manager: &Arc<M>,
|
||||
config: &C,
|
||||
connection_manager: &M,
|
||||
map: &mut std::sync::RwLockWriteGuard<'_, IndexMap<SocketAddr, P>>,
|
||||
addr: &SocketAddr,
|
||||
connection_pool_size: usize,
|
||||
|
@ -276,11 +276,13 @@ where
|
|||
} = match map.get(addr) {
|
||||
Some(pool) => {
|
||||
let pool_status = pool.check_pool_status(self.connection_pool_size);
|
||||
if matches!(pool_status, PoolStatus::Empty) {
|
||||
match pool_status {
|
||||
PoolStatus::Empty => {
|
||||
// create more connection and put it in the pool
|
||||
drop(map);
|
||||
self.create_connection(&mut lock_timing_ms, addr)
|
||||
} else {
|
||||
}
|
||||
PoolStatus::PartiallyFull | PoolStatus::Full => {
|
||||
let connection = pool.borrow_connection();
|
||||
if matches!(pool_status, PoolStatus::PartiallyFull) {
|
||||
debug!("Creating connection async for {addr}");
|
||||
|
@ -304,6 +306,7 @@ where
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
// Upgrade to write access by dropping read lock and acquire write lock
|
||||
drop(map);
|
||||
|
|
Loading…
Reference in New Issue