Skip to content

Commit 6b5089f

Browse files
RUST-1454 Add a PooledConnection type (#1241)
1 parent 80bab06 commit 6b5089f

File tree

11 files changed

+476
-363
lines changed

11 files changed

+476
-363
lines changed

src/client/executor.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ use crate::{
2525
},
2626
cmap::{
2727
conn::{
28+
pooled::PooledConnection,
2829
wire::{next_request_id, Message},
2930
PinnedConnectionHandle,
3031
},
31-
Connection,
3232
ConnectionPool,
3333
RawCommandResponse,
3434
},
@@ -193,7 +193,7 @@ impl Client {
193193
pub(crate) fn pin_connection_for_cursor(
194194
&self,
195195
spec: &CursorSpecification,
196-
conn: &mut Connection,
196+
conn: &mut PooledConnection,
197197
) -> Result<Option<PinnedConnectionHandle>> {
198198
if self.is_load_balanced() && spec.info.id != 0 {
199199
Ok(Some(conn.pin()?))
@@ -205,7 +205,7 @@ impl Client {
205205
fn pin_connection_for_session(
206206
&self,
207207
spec: &CursorSpecification,
208-
conn: &mut Connection,
208+
conn: &mut PooledConnection,
209209
session: &mut ClientSession,
210210
) -> Result<Option<PinnedConnectionHandle>> {
211211
if let Some(handle) = session.transaction.pinned_connection() {
@@ -489,7 +489,7 @@ impl Client {
489489
async fn execute_operation_on_connection<T: Operation>(
490490
&self,
491491
op: &mut T,
492-
connection: &mut Connection,
492+
connection: &mut PooledConnection,
493493
session: &mut Option<&mut ClientSession>,
494494
txn_number: Option<i64>,
495495
retryability: Retryability,
@@ -904,7 +904,7 @@ impl Client {
904904
/// Returns the retryability level for the execution of this operation on this connection.
905905
fn get_retryability<T: Operation>(
906906
&self,
907-
conn: &Connection,
907+
conn: &PooledConnection,
908908
op: &T,
909909
session: &Option<&mut ClientSession>,
910910
) -> Result<Retryability> {
@@ -945,7 +945,7 @@ async fn get_connection<T: Operation>(
945945
session: &Option<&mut ClientSession>,
946946
op: &T,
947947
pool: &ConnectionPool,
948-
) -> Result<Connection> {
948+
) -> Result<PooledConnection> {
949949
let session_pinned = session
950950
.as_ref()
951951
.and_then(|s| s.transaction.pinned_connection());
@@ -995,7 +995,7 @@ impl Error {
995995
/// ClientSession should be unpinned.
996996
fn add_labels_and_update_pin(
997997
&mut self,
998-
conn: Option<&Connection>,
998+
conn: Option<&PooledConnection>,
999999
session: &mut Option<&mut ClientSession>,
10001000
retryability: Option<Retryability>,
10011001
) -> Result<()> {
@@ -1060,7 +1060,7 @@ impl Error {
10601060

10611061
struct ExecutionDetails<T: Operation> {
10621062
output: T::O,
1063-
connection: Connection,
1063+
connection: PooledConnection,
10641064
implicit_session: Option<ClientSession>,
10651065
}
10661066

src/cmap.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@ use std::time::Instant;
1414
use derive_where::derive_where;
1515

1616
pub use self::conn::ConnectionInfo;
17-
pub(crate) use self::{
18-
conn::{Command, Connection, RawCommandResponse, StreamDescription},
19-
status::PoolGenerationSubscriber,
20-
worker::PoolGeneration,
21-
};
2217
use self::{
18+
conn::pooled::PooledConnection,
2319
connection_requester::ConnectionRequestResult,
2420
establish::ConnectionEstablisher,
2521
options::ConnectionPoolOptions,
2622
};
23+
pub(crate) use self::{
24+
conn::{Command, Connection, RawCommandResponse, StreamDescription},
25+
status::PoolGenerationSubscriber,
26+
worker::PoolGeneration,
27+
};
2728
use crate::{
2829
bson::oid::ObjectId,
2930
error::{Error, Result},
@@ -120,7 +121,7 @@ impl ConnectionPool {
120121
/// Checks out a connection from the pool. This method will yield until this thread is at the
121122
/// front of the wait queue, and then will block again if no available connections are in the
122123
/// pool and the total number of connections is not less than the max pool size.
123-
pub(crate) async fn check_out(&self) -> Result<Connection> {
124+
pub(crate) async fn check_out(&self) -> Result<PooledConnection> {
124125
let time_started = Instant::now();
125126
self.event_emitter.emit_event(|| {
126127
ConnectionCheckoutStartedEvent {

0 commit comments

Comments
 (0)