From 39f00fa19064e2ab85c514f74f61c55287484c44 Mon Sep 17 00:00:00 2001 From: Austin Bonander Date: Fri, 8 Nov 2024 15:56:53 -0800 Subject: [PATCH] fix: compilation error, warnings --- sqlx-core/src/error.rs | 6 +++--- sqlx-core/src/pool/connect.rs | 23 ++++++++++------------- sqlx-core/src/pool/connection.rs | 2 -- sqlx-core/src/pool/inner.rs | 2 +- sqlx-core/src/pool/mod.rs | 10 ---------- sqlx-core/src/rt/mod.rs | 2 +- 6 files changed, 15 insertions(+), 30 deletions(-) diff --git a/sqlx-core/src/error.rs b/sqlx-core/src/error.rs index a3bbb45dbc..625de3958c 100644 --- a/sqlx-core/src/error.rs +++ b/sqlx-core/src/error.rs @@ -263,13 +263,13 @@ pub trait DatabaseError: 'static + Send + Sync + StdError { /// For example, the Postgres driver overrides this to return `true` for the following error codes: /// /// * `53300 too_many_connections`: returned when the maximum connections are exceeded - /// on the server. Assumed to be the result of a temporary overcommit - /// (e.g. an extra application replica being spun up to replace one that is going down). + /// on the server. Assumed to be the result of a temporary overcommit + /// (e.g. an extra application replica being spun up to replace one that is going down). /// * This error being consistently logged or returned is a likely indicator of a misconfiguration; /// the sum of [`PoolOptions::max_connections`] for all replicas should not exceed /// the maximum connections allowed by the server. /// * `57P03 cannot_connect_now`: returned when the database server is still starting up - /// and the tcop component is not ready to accept connections yet. + /// and the tcop component is not ready to accept connections yet. fn is_retryable_connect_error(&self) -> bool { false } diff --git a/sqlx-core/src/pool/connect.rs b/sqlx-core/src/pool/connect.rs index 187dab9293..f1f7ce7d4b 100644 --- a/sqlx-core/src/pool/connect.rs +++ b/sqlx-core/src/pool/connect.rs @@ -1,21 +1,18 @@ use crate::connection::{ConnectOptions, Connection}; use crate::database::Database; -use crate::pool::connection::{Floating, Live}; +use crate::pool::connection::Floating; use crate::pool::inner::PoolInner; use crate::pool::PoolConnection; use crate::rt::JoinHandle; use crate::Error; use ease_off::EaseOff; -use event_listener::{Event, EventListener}; +use event_listener::Event; use std::fmt::{Display, Formatter}; use std::future::Future; -use std::pin::Pin; use std::ptr; use std::sync::atomic::{AtomicUsize, Ordering}; -use std::sync::{Arc, RwLock}; -use std::task::{Context, Poll}; -use std::time::{Duration, Instant}; -use tracing::Instrument; +use std::sync::Arc; +use std::time::Instant; use std::io; @@ -74,7 +71,7 @@ use std::io; /// `set_connect_options` and `get_connect_options` were removed in 0.9.0 because they complicated /// the pool internals. They can be reimplemented by capturing a mutex, or similar, in the callback. /// -/// This example uses Postgres and [`tokio::sync::Mutex`] but may be adapted to any driver +/// This example uses Postgres and [`tokio::sync::RwLock`] but may be adapted to any driver /// or `async-std`, respectively. /// /// ```rust,no_run @@ -197,11 +194,11 @@ pub trait PoolConnector: Send + Sync + 'static { /// /// * [`io::ErrorKind::ConnectionRefused`] /// * Database errors for which - /// [`is_retryable_connect_error`][crate::error::DatabaseError::is_retryable_connect_error] - /// returns `true`. + /// [`is_retryable_connect_error`][crate::error::DatabaseError::is_retryable_connect_error] + /// returns `true`. /// * [`Error::PoolConnector`] with `retryable: true`. - /// This error kind is not returned internally and is designed to allow this method to return - /// arbitrary error types not otherwise supported. + /// This error kind is not returned internally and is designed to allow this method to return + /// arbitrary error types not otherwise supported. /// /// Manual implementations of this method may also use the signature: /// ```rust,ignore @@ -363,7 +360,7 @@ impl ConnectionCounter { // Check that `self` can increase size first before we check the parent. let acquired = self.acquire_permit_self(pool).await; - if let Some(parent) = &pool.options.parent_pool { + if let Some(parent) = pool.parent() { let (_, permit) = parent.0.counter.acquire_permit_self(&parent.0).await; // consume the parent permit diff --git a/sqlx-core/src/pool/connection.rs b/sqlx-core/src/pool/connection.rs index ac26437b4c..b3044de14d 100644 --- a/sqlx-core/src/pool/connection.rs +++ b/sqlx-core/src/pool/connection.rs @@ -3,8 +3,6 @@ use std::ops::{Deref, DerefMut}; use std::sync::Arc; use std::time::{Duration, Instant}; -use crate::sync::AsyncSemaphoreReleaser; - use crate::connection::Connection; use crate::database::Database; use crate::error::Error; diff --git a/sqlx-core/src/pool/inner.rs b/sqlx-core/src/pool/inner.rs index f78f86c622..bae686b7f9 100644 --- a/sqlx-core/src/pool/inner.rs +++ b/sqlx-core/src/pool/inner.rs @@ -90,7 +90,7 @@ impl PoolInner { } } - fn parent(&self) -> Option<&Pool> { + pub(super) fn parent(&self) -> Option<&Pool> { self.options.parent_pool.as_ref() } diff --git a/sqlx-core/src/pool/mod.rs b/sqlx-core/src/pool/mod.rs index 9d4b170316..1119e1a0d3 100644 --- a/sqlx-core/src/pool/mod.rs +++ b/sqlx-core/src/pool/mod.rs @@ -59,7 +59,6 @@ use std::future::Future; use std::pin::Pin; use std::sync::Arc; use std::task::{Context, Poll}; -use std::time::{Duration, Instant}; use event_listener::EventListener; use futures_core::FusedFuture; @@ -592,15 +591,6 @@ impl FusedFuture for CloseEvent { } } -/// get the time between the deadline and now and use that as our timeout -/// -/// returns `Error::PoolTimedOut` if the deadline is in the past -fn deadline_as_timeout(deadline: Instant) -> Result { - deadline - .checked_duration_since(Instant::now()) - .ok_or(Error::PoolTimedOut) -} - #[test] #[allow(dead_code)] fn assert_pool_traits() { diff --git a/sqlx-core/src/rt/mod.rs b/sqlx-core/src/rt/mod.rs index ce42dcade4..bef5e97158 100644 --- a/sqlx-core/src/rt/mod.rs +++ b/sqlx-core/src/rt/mod.rs @@ -62,7 +62,7 @@ pub async fn timeout_at(deadline: Instant, f: F) -> Result