Skip to content

Commit 97c3af6

Browse files
committed
WIP refactor: replace sharding with single connection set (6)
1 parent ac3d382 commit 97c3af6

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

benches/any/pool.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ use criterion::{criterion_group, criterion_main, Bencher, BenchmarkId, Criterion
33
use sqlx_core::any::AnyPoolOptions;
44
use std::fmt::{Display, Formatter};
55
use std::future::Future;
6-
use std::time::Instant;
6+
use std::thread;
7+
use std::time::{Duration, Instant};
78
use tracing::Instrument;
89

910
#[derive(Debug)]
@@ -131,7 +132,9 @@ fn bench_pool_with(b: &mut Bencher, input: &Input, database_url: &str) {
131132
}
132133
});
133134

134-
drop(pool.close());
135+
runtime.block_on(pool.close());
136+
// Give the server a second to clean up
137+
thread::sleep(Duration::from_millis(50));
135138
}
136139

137140
criterion_group!(benches, bench_pool,);

sqlx-core/src/pool/connection_set.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,13 @@ impl<C> ConnectionSet<C> {
238238
closing.push(async {
239239
let locked = slot.lock().await;
240240

241-
let DisconnectedSlot(mut guard) = match locked.try_connected() {
241+
let slot = match locked.try_connected() {
242242
Ok(connected) => close(connected).await,
243243
Err(disconnected) => disconnected,
244244
};
245245

246246
// The pool is shutting down; don't wake any tasks that might have been interested
247-
guard.drop_without_notify();
247+
slot.leak();
248248
});
249249
}
250250

@@ -461,8 +461,9 @@ impl<C> DisconnectedSlot<C> {
461461
ConnectedSlot(self.0)
462462
}
463463

464-
pub fn leak(self) {
464+
pub fn leak(mut self) {
465465
self.0.slot.leaked.store(true, Ordering::Release);
466+
self.0.drop_without_notify();
466467
}
467468
}
468469

sqlx-core/src/pool/inner.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ impl<DB: Database> PoolInner<DB> {
7979

8080
// Keep clearing the idle queue as connections are released until the count reaches zero.
8181
self.connections.drain(async |slot| {
82-
let (conn, slot) = ConnectedSlot::take(slot);
83-
84-
let _ = rt::timeout(GRACEFUL_CLOSE_TIMEOUT, conn.raw.close()).await;
85-
82+
let (_res, slot) = connection::close(slot).await;
8683
slot
8784
})
8885
}

0 commit comments

Comments
 (0)