Skip to content

Commit

Permalink
Merge branch 'master' into arangodb
Browse files Browse the repository at this point in the history
  • Loading branch information
bikeshedder authored Oct 30, 2021
2 parents d3ef3a5 + c14c7ad commit 6aaf171
Show file tree
Hide file tree
Showing 52 changed files with 1,135 additions and 462 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log

## v0.9.0 (unreleased)
## v0.9.1

* Deprecate `managed::sync` module in favor of `deadpool-sync` crate
* Extract `runtime` module as separate `deadpool-runtime` crate

## v0.9.0

* __Breaking:__ Replace `config` feature with `serde` (opted out by default)
* Fix `std::error::Error::source` implementations for library errors
Expand All @@ -13,6 +18,7 @@
* Update `tokio` dependency to version `1.5.0`
* Add `post_create`, `pre_recycle` and `post_recycle` hooks
* Add `Pool::resize` method
* Add `managed_reexports` macro

## v0.8.2

Expand Down
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deadpool"
version = "0.9.0-pre"
version = "0.9.1"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
Expand All @@ -18,8 +18,8 @@ rustdoc-args = ["--cfg", "docsrs"]
default = ["managed", "unmanaged"]
managed = ["async-trait"]
unmanaged = []
rt_tokio_1 = ["tokio/time", "tokio/rt"]
rt_async-std_1 = ["async-std"]
rt_tokio_1 = ["deadpool-runtime/tokio_1"]
rt_async-std_1 = ["deadpool-runtime/async-std_1"]

[dependencies]
num_cpus = "1.11.1"
Expand All @@ -28,7 +28,7 @@ async-trait = { version = "0.1.17", optional = true }
# `serde` feature
serde = { version = "1.0.103", features = ["derive"], optional = true }
# `rt_async-std_1` feature
async-std = { version = "1.0", features = ["unstable"], optional = true }
deadpool-runtime = { version = "0.1", path = "./runtime" }
# The dependency of tokio::sync is non-optional. Deadpool depends on
# `tokio::sync::Semaphore`. No other features of `tokio` are enabled or used
# unless the `rt_tokio_1` feature is enabled.
Expand All @@ -50,7 +50,10 @@ members = [
"diesel",
"lapin",
"postgres",
"r2d2",
"redis",
"runtime",
"sqlite",
"sync",
"examples/*"
]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ Backend | Crate | Latest Version |
[async-memcached](https://crates.io/crates/async-memcached) | [deadpool-memcached](https://crates.io/crates/deadpool-memcached) | [![Latest Version](https://img.shields.io/crates/v/deadpool-memcached.svg)](https://crates.io/crates/deadpool-memcached) |
[rusqlite](https://crates.io/crates/rusqlite) | [deadpool-sqlite](https://crates.io/crates/deadpool-sqlite) | [![Latest Version](https://img.shields.io/crates/v/deadpool-sqlite.svg)](https://crates.io/crates/deadpool-sqlite) |
[diesel](https://crates.io/crates/diesel) | [deadpool-diesel](https://crates.io/crates/deadpool-diesel) | [![Latest Version](https://img.shields.io/crates/v/deadpool-diesel.svg)](https://crates.io/crates/deadpool-diesel) |
[r2d2](https://crates.io/crates/r2d2) | [deadpool-r2d2](https://crates.io/crates/deadpool-r2d2) | [![Latest Version](https://img.shields.io/crates/v/deadpool-r2d2.svg)](https://crates.io/crates/deadpool-r2d2) |
[arangors](https://crates.io/crates/arangors) | [deadpool-arangodb](https://crates.io/crates/deadpool-arangodb) | [![Latest Version](https://img.shields.io/crates/v/deadpool-arangodb.svg)](https://crates.io/crates/deadpool-arangodb) |

### Reasons for yet another connection pool
Expand Down Expand Up @@ -132,18 +133,17 @@ things a little different and that is the main reason for it to exist:
The actual code is barely 100 lines of code and lives in the two functions
`Pool::get` and `Object::drop`.

### Differences to other connection pool implementations
- **Deadpool is extensible.** By using `post_create`, `pre_recycle` and
`post_recycle` hooks you can customize object creation and recycling
to fit your needs.

- [`r2d2`](https://crates.io/crates/r2d2) provides a lot more configuration
options but only provides a synchroneous interface.
- **Deadpool provides insights.** All objects track `Metrics` and the pool
provides a `status` method that can be used to find out details about
the inner workings.

- [`bb8`](https://crates.io/crates/bb8) provides an `async/.await` based
interface and provides the same configuration options as `r2d2`. It
depends on the tokio executor though and the code is more complex.
- **Deadpool is resizable.** You can grow and shrink the pool at runtime
without requiring an application restart.

- [`mobc`](https://crates.io/crates/mobc) provides an `async/.await` based
interface and provides a lot more configuration options. It requires an
executor though and the code is a lot more complex.

## Unmanaged pool

Expand Down
8 changes: 7 additions & 1 deletion diesel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Change Log

## v0.2.0 (unreleased)
## v0.3.0

* __Breaking:__ Replace `deadpool::managed::sync` by
`deadpool-sync::SyncWrapper` which fixes the return type
of the `interact` method.

## v0.2.0

* __Breaking:__ Replace `config` feature with `serde` (opted out by default)
* Fix `std::error::Error::source` implementations for library errors
Expand Down
5 changes: 3 additions & 2 deletions diesel/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deadpool-diesel"
version = "0.2.0-pre"
version = "0.3.0"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
Expand All @@ -24,7 +24,8 @@ rt_async-std_1 = ["deadpool/rt_async-std_1"]
serde = ["deadpool/serde"]

[dependencies]
deadpool = { path = "../", version = "0.9.0-pre", default-features = false, features = ["managed"] }
deadpool = { path = "../", version = "0.9.1", default-features = false, features = ["managed"] }
deadpool-sync = { path = "../sync", version = "0.1.0" }
diesel = { version = "1.4.7", default-features = false }

[dev-dependencies]
Expand Down
5 changes: 2 additions & 3 deletions diesel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ manager for [`diesel`](https://crates.io/crates/diesel) connections.
## Example

```rust
use deadpool_diesel::{Runtime, sqlite::{Manager, Pool}};
use deadpool_diesel::sqlite::{Runtime, Manager, Pool};
use diesel::{prelude::*, select, sql_types::Text};

#[tokio::main]
Expand All @@ -34,8 +34,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let result = conn.interact(|conn| {
let query = select("Hello world!".into_sql::<Text>());
query.get_result::<String>(conn)
.map_err(Into::into)
}).await.unwrap();
}).await??;
assert!(result == "Hello world!");
Ok(())
}
Expand Down
5 changes: 3 additions & 2 deletions diesel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ pub mod sqlite;

use deadpool::managed;

pub use deadpool::managed::sync::reexports::*;
pub use deadpool::managed::reexports::*;
pub use deadpool_sync::reexports::*;
// Normally backend implementations don't export the generic `Pool`
// type. `deadpool-diesel` is different in that regards as it is
// generic itself.
Expand All @@ -47,4 +48,4 @@ pub use self::{error::Error, manager::Manager};
pub type PoolError = managed::PoolError<Error>;

/// Connection which is returned by the [`Pool`].
pub type Connection<C> = managed::sync::SyncWrapper<C, Error>;
pub type Connection<C> = deadpool_sync::SyncWrapper<C>;
9 changes: 5 additions & 4 deletions diesel/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use std::{fmt, marker::PhantomData};

use deadpool::{
async_trait,
managed::{self, sync::SyncWrapper, RecycleError, RecycleResult},
managed::{self, RecycleError, RecycleResult},
Runtime,
};
use deadpool_sync::SyncWrapper;

use crate::{Connection, Error};

Expand Down Expand Up @@ -54,15 +55,15 @@ where
async fn create(&self) -> Result<Self::Type, Self::Error> {
let database_url = self.database_url.clone();
SyncWrapper::new(self.runtime, move || {
C::establish(&database_url).map_err(Error::Connection)
C::establish(&database_url).map_err(Into::into)
})
.await
}

async fn recycle(&self, obj: &mut Self::Type) -> RecycleResult<Self::Error> {
if obj.is_mutex_poisoned() {
return Err(RecycleError::Message(
"Mutex is poisoned. Connection is considered unusable.".into(),
return Err(RecycleError::StaticMessage(
"Mutex is poisoned. Connection is considered unusable.",
));
}
obj.interact(|conn| conn.execute("SELECT 1").map_err(Error::Ping))
Expand Down
17 changes: 11 additions & 6 deletions diesel/src/mysql.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
//! Type aliases for using `deadpool-diesel` with MySQL.
/// Connection which is returned by the MySQL [`Pool`].
pub type Connection = crate::Connection<diesel::MysqlConnection>;
/// Manager for MySQL connections
pub type Manager = crate::Manager<diesel::MysqlConnection>;

/// Manager which is used to create [`diesel::MysqlConnection`]s.
pub type Manager = crate::manager::Manager<diesel::MysqlConnection>;
deadpool::managed_reexports!(
"diesel",
Manager,
deadpool::managed::Object<Manager>,
diesel::ConnectionError,
std::convert::Infallible
);

/// Pool for using `deadpool-diesel` with MySQL.
pub type Pool = deadpool::managed::Pool<Manager>;
/// Type alias for [`Object`]
pub type Connection = Object;
17 changes: 11 additions & 6 deletions diesel/src/postgres.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
//! Type aliases for using `deadpool-diesel` with PostgreSQL.
/// Connection which is returned by the PostgreSQL [`Pool`].
pub type Connection = crate::Connection<diesel::PgConnection>;
/// Manager for PostgreSQL connections
pub type Manager = crate::Manager<diesel::PgConnection>;

/// Manager which is used to create [`diesel::PgConnection`]s.
pub type Manager = crate::manager::Manager<diesel::PgConnection>;
deadpool::managed_reexports!(
"diesel",
Manager,
deadpool::managed::Object<Manager>,
diesel::ConnectionError,
std::convert::Infallible
);

/// Pool for using `deadpool-diesel` with PostgreSQL.
pub type Pool = deadpool::managed::Pool<Manager>;
/// Type alias for [`Object`]
pub type Connection = Object;
19 changes: 13 additions & 6 deletions diesel/src/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
//! Type aliases for using `deadpool-diesel` with SQLite.
/// Connection which is returned by the SQLite [`Pool`].
pub type Connection = crate::Connection<diesel::SqliteConnection>;
/// Manager for SQLite connections
pub type Manager = crate::Manager<diesel::SqliteConnection>;

/// Manager which is used to create [`diesel::SqliteConnection`]s.
pub type Manager = crate::manager::Manager<diesel::SqliteConnection>;
pub use deadpool::managed::reexports::*;
pub use deadpool_sync::reexports::*;
deadpool::managed_reexports!(
"diesel",
Manager,
deadpool::managed::Object<Manager>,
diesel::ConnectionError,
std::convert::Infallible
);

/// Pool for using `deadpool-diesel` with SQLite.
pub type Pool = deadpool::managed::Pool<Manager>;
/// Type alias for [`Object`]
pub type Connection = Object;
26 changes: 11 additions & 15 deletions diesel/tests/basics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

use tokio::sync::mpsc;

use deadpool_diesel::{Manager, Pool, Runtime};
use deadpool_diesel::{
sqlite::{Manager, Pool, Runtime},
InteractError,
};

type SqliteManager = Manager<diesel::SqliteConnection>;
type SqlitePool = Pool<SqliteManager>;

fn create_pool(max_size: usize) -> SqlitePool {
let manager = SqliteManager::new(":memory:", Runtime::Tokio1);
let pool = SqlitePool::builder(manager)
.max_size(max_size)
.build()
.unwrap();
fn create_pool(max_size: usize) -> Pool {
let manager = Manager::new(":memory:", Runtime::Tokio1);
let pool = Pool::builder(manager).max_size(max_size).build().unwrap();
pool
}

Expand Down Expand Up @@ -53,14 +50,13 @@ async fn pooled_connection_impls_connection() {

let pool = create_pool(1);
let conn = pool.get().await.unwrap();
let result = conn
let result: Result<Result<String, diesel::result::Error>, InteractError> = conn
.interact(|conn| {
let query = select("foo".into_sql::<Text>());
query.get_result::<String>(conn).map_err(Into::into)
query.get_result::<String>(conn)
})
.await
.unwrap();
assert_eq!("foo", &result);
.await;
assert_eq!("foo", &result.unwrap().unwrap());
}

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion examples/redis-actix-web/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ publish = false
[dependencies]
actix-web = "4.0.0-beta.8"
deadpool-redis = { version = "0.10.0-pre", path = "../../redis" }
redis = { version = "0.19", features = ["tokio-comp"] }
redis = { version = "0.21", features = ["tokio-comp"] }
2 changes: 1 addition & 1 deletion lapin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

## v0.9.0 (unreleased)
## v0.9.0

* __Breaking:__ Replace `config` feature with `serde` (opted out by default)
* Remove unused `futures` and `log` dependencies
Expand Down
4 changes: 2 additions & 2 deletions lapin/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deadpool-lapin"
version = "0.9.0-pre"
version = "0.9.0"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
Expand All @@ -22,7 +22,7 @@ serde = ["deadpool/serde", "serde_1"]

[dependencies]
async-amqp = { version = "1.2", optional = true }
deadpool = { path = "../", version = "0.9.0-pre", default-features = false, features = ["managed"] }
deadpool = { path = "../", version = "0.9.0", default-features = false, features = ["managed"] }
lapin = { version = "1.0", default-features = false }
serde_1 = { package = "serde", version = "1.0.103", features = ["derive"], optional = true }
tokio-amqp = { version = "1.0", optional = true }
Expand Down
27 changes: 10 additions & 17 deletions lapin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,20 @@ mod config;
use deadpool::{async_trait, managed};
use lapin::{ConnectionProperties, Error};

pub use deadpool::managed::reexports::*;
pub use lapin;

pub use self::config::{Config, ConfigError};

/// Type alias for using [`deadpool::managed::Pool`] with [`lapin`].
pub type Pool = managed::Pool<Manager>;

/// Type alias for using [`deadpool::managed::PoolBuilder`] with [`lapin`].
pub type PoolBuilder = managed::PoolBuilder<Manager>;

/// Type alias for using [`deadpool::managed::BuildError`] with [`lapin`].
pub type BuildError = managed::BuildError<Error>;

/// Type alias for using [`deadpool::managed::CreatePoolError`] with [`lapin`].
pub type CreatePoolError = managed::CreatePoolError<ConfigError, Error>;

/// Type alias for using [`deadpool::managed::PoolError`] with [`lapin`].
pub type PoolError = managed::PoolError<Error>;

/// Type alias for using [`deadpool::managed::Object`] with [`lapin`].
pub use deadpool::managed::reexports::*;
deadpool::managed_reexports!(
"lapin",
Manager,
deadpool::managed::Object<Manager>,
Error,
ConfigError
);

/// Type alias for ['Object']
pub type Connection = managed::Object<Manager>;

type RecycleResult = managed::RecycleResult<Error>;
Expand Down
2 changes: 1 addition & 1 deletion postgres/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Change Log

## v0.10.0 (unreleased)
## v0.10.0

* __Breaking:__ Replace `config` feature with `serde` (opted out by default)
* Re-export `deadpool::managed::Timeouts`
Expand Down
4 changes: 2 additions & 2 deletions postgres/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "deadpool-postgres"
version = "0.10.0-pre"
version = "0.10.0"
edition = "2018"
resolver = "2"
authors = ["Michael P. Jung <[email protected]>"]
Expand All @@ -20,7 +20,7 @@ rt_async-std_1 = ["deadpool/rt_async-std_1"]
serde = ["deadpool/serde", "serde_1"]

[dependencies]
deadpool = { path = "../", version = "0.9.0-pre", default-features = false, features = ["managed"] }
deadpool = { path = "../", version = "0.9.0", default-features = false, features = ["managed"] }
log = "0.4"
serde_1 = { package = "serde", version = "1.0", features = ["derive"], optional = true }
tokio = { version = "1", features = ["rt"] }
Expand Down
Loading

0 comments on commit 6aaf171

Please sign in to comment.