Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade to latest deadpool #1631

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 15 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ diesel_logger = "0.1"
cadence = "1.3"
backtrace = "0.3"
chrono = "0.4"
deadpool = { version = "0.12", features = ["rt_tokio_1"] }
env_logger = "0.11"
futures = { version = "0.3", features = ["compat"] }
futures-util = { version = "0.3", features = [
Expand Down
2 changes: 1 addition & 1 deletion syncserver-db-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ edition.workspace = true

[dependencies]
backtrace.workspace = true
deadpool.workspace = true
futures.workspace = true
http.workspace = true
thiserror.workspace = true

diesel = { workspace = true, features = ["mysql", "r2d2"] }
deadpool = { git = "https://github.com/mozilla-services/deadpool", tag = "deadpool-v0.7.0" }
diesel_migrations = { workspace = true, features = ["mysql"] }
syncserver-common = { path = "../syncserver-common" }
4 changes: 2 additions & 2 deletions syncstorage-spanner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition.workspace = true
[dependencies]
backtrace.workspace = true
cadence.workspace = true
deadpool.workspace = true
env_logger.workspace = true
futures.workspace = true
http.workspace = true
Expand All @@ -16,7 +17,6 @@ thiserror.workspace = true

async-trait = "0.1.40"
google-cloud-rust-raw = { version = "0.16.1", features = ["spanner"] }
deadpool = { git = "https://github.com/mozilla-services/deadpool", tag = "deadpool-v0.7.0" }
form_urlencoded = "1.2"
# Some versions of OpenSSL 1.1.1 conflict with grpcio's built-in boringssl which can cause
# syncserver to either fail to either compile, or start. In those cases, try
Expand All @@ -34,7 +34,7 @@ syncstorage-settings = { path = "../syncstorage-settings" }
tokio = { workspace = true, features = [
"macros",
"sync",
] } # pinning to 0.2.4 due to high number of dependencies (actix, bb8, deadpool, etc.)
] }
url = "2.1"
uuid = { version = "1.6", features = ["serde", "v4"] }

Expand Down
15 changes: 10 additions & 5 deletions syncstorage-spanner/src/manager/deadpool.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{fmt, sync::Arc};

use async_trait::async_trait;
use deadpool::managed::{Manager, RecycleError, RecycleResult};
use grpcio::{EnvBuilder, Environment};
use syncserver_common::{BlockingThreadpool, Metrics};
Expand All @@ -11,7 +10,7 @@ use super::session::{
};
use crate::error::DbError;

pub(crate) type Conn = deadpool::managed::Object<SpannerSession, DbError>;
pub(crate) type Conn = deadpool::managed::Object<SpannerSessionManager>;

pub(crate) struct SpannerSessionManager {
settings: SpannerSessionSettings,
Expand Down Expand Up @@ -45,8 +44,10 @@ impl SpannerSessionManager {
}
}

#[async_trait]
impl Manager<SpannerSession, DbError> for SpannerSessionManager {
impl Manager for SpannerSessionManager {
type Type = SpannerSession;
type Error = DbError;

async fn create(&self) -> Result<SpannerSession, DbError> {
let session = create_spanner_session(
&self.settings,
Expand All @@ -58,7 +59,11 @@ impl Manager<SpannerSession, DbError> for SpannerSessionManager {
Ok(session)
}

async fn recycle(&self, conn: &mut SpannerSession) -> RecycleResult<DbError> {
async fn recycle(
&self,
conn: &mut SpannerSession,
_: &deadpool::managed::Metrics,
) -> RecycleResult<DbError> {
recycle_spanner_session(conn, &self.metrics)
.await
.map_err(RecycleError::Backend)
Expand Down
1 change: 0 additions & 1 deletion syncstorage-spanner/src/manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@ mod deadpool;
mod session;

pub(super) use self::deadpool::{Conn, SpannerSessionManager};
pub(super) use self::session::SpannerSession;
22 changes: 13 additions & 9 deletions syncstorage-spanner/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ use syncstorage_settings::{Quota, Settings};
use tokio::sync::RwLock;

pub(super) use super::manager::Conn;
use super::{
error::DbError,
manager::{SpannerSession, SpannerSessionManager},
models::SpannerDb,
DbResult,
};
use super::{error::DbError, manager::SpannerSessionManager, models::SpannerDb, DbResult};

#[derive(Clone)]
pub struct SpannerDbPool {
/// Pool of db connections
pool: deadpool::managed::Pool<SpannerSession, DbError>,
pool: deadpool::managed::Pool<SpannerSessionManager>,
/// In-memory cache of collection_ids and their names
coll_cache: Arc<CollectionCache>,

Expand Down Expand Up @@ -51,8 +46,16 @@ impl SpannerDbPool {
wait,
..Default::default()
};
let config = deadpool::managed::PoolConfig { max_size, timeouts };
let pool = deadpool::managed::Pool::from_config(manager, config);
let config = deadpool::managed::PoolConfig {
max_size,
timeouts,
..Default::default()
};
let pool = deadpool::managed::Pool::builder(manager)
.config(config)
.runtime(deadpool::Runtime::Tokio1)
.build()
.map_err(|e| DbError::internal(format!("Couldn't build Db Pool: {}", e)))?;

Ok(Self {
pool,
Expand All @@ -72,6 +75,7 @@ impl SpannerDbPool {
deadpool::managed::PoolError::Timeout(timeout_type) => {
DbError::internal(format!("deadpool Timeout: {:?}", timeout_type))
}
_ => DbError::internal(format!("deadpool PoolError: {}", e)),
})?;
Ok(SpannerDb::new(
conn,
Expand Down