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

Expose connection pool's get timeout via ConnectionOptionsBuilder #212

Merged
merged 1 commit into from
May 13, 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
5 changes: 4 additions & 1 deletion gremlin-client/src/aio/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use crate::GValue;
use crate::ToGValue;
use crate::{ConnectionOptions, GremlinError, GremlinResult};
use base64::encode;

Check warning on line 11 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 11 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 11 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 11 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 11 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 11 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode
use futures::future::{BoxFuture, FutureExt};
use mobc::{Connection, Pool};
use serde::Serialize;
Expand Down Expand Up @@ -56,7 +56,10 @@
let pool_size = opts.pool_size;
let manager = GremlinConnectionManager::new(opts.clone());

let pool = Pool::builder().max_open(pool_size as u64).build(manager);
let pool = Pool::builder()
.get_timeout(opts.pool_get_connection_timeout)
.max_open(pool_size as u64)
.build(manager);

Ok(GremlinClient {
pool,
Expand Down Expand Up @@ -176,7 +179,7 @@

args.insert(
String::from("sasl"),
GValue::String(encode(&format!("\0{}\0{}", c.username, c.password))),

Check warning on line 182 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 182 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 182 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 182 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 182 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 182 in gremlin-client/src/aio/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode
);

let args = self.options.serializer.write(&GValue::from(args))?;
Expand Down
8 changes: 6 additions & 2 deletions gremlin-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use crate::ToGValue;
use crate::{ConnectionOptions, GremlinError, GremlinResult};
use crate::{GResultSet, GValue};
use base64::encode;

Check warning on line 10 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 10 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 10 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 10 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 10 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 10 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode
use r2d2::Pool;
use serde::Serialize;
use std::collections::{HashMap, VecDeque};
Expand Down Expand Up @@ -54,10 +54,14 @@
let pool_size = opts.pool_size;
let manager = GremlinConnectionManager::new(opts.clone());

let pool = Pool::builder().max_size(pool_size).build(manager)?;
let mut pool_builder = Pool::builder().max_size(pool_size);

if let Some(get_connection_timeout) = opts.pool_get_connection_timeout {
pool_builder = pool_builder.connection_timeout(get_connection_timeout);
}

Ok(GremlinClient {
pool,
pool: pool_builder.build(manager)?,
session: None,
alias: None,
options: opts,
Expand Down Expand Up @@ -234,7 +238,7 @@

args.insert(
String::from("sasl"),
GValue::String(encode(&format!("\0{}\0{}", c.username, c.password))),

Check warning on line 241 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 241 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 241 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 241 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 241 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode

Check warning on line 241 in gremlin-client/src/client.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated function `base64::encode`: Use Engine::encode
);

let args = self.options.serializer.write(&GValue::from(args))?;
Expand Down
11 changes: 10 additions & 1 deletion gremlin-client/src/connection.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::net::TcpStream;
use std::{net::TcpStream, time::Duration};

use crate::{GraphSON, GremlinError, GremlinResult};
use native_tls::TlsConnector;
Expand Down Expand Up @@ -62,7 +62,7 @@

fn send(&mut self, payload: Vec<u8>) -> GremlinResult<()> {
self.0
.write_message(Message::Binary(payload))

Check warning on line 65 in gremlin-client/src/connection.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.5.7)

use of deprecated method `tungstenite::WebSocket::<Stream>::write_message`: Use `send`

Check warning on line 65 in gremlin-client/src/connection.rs

View workflow job for this annotation

GitHub Actions / build_and_test (ubuntu-latest, stable, 3.6.5)

use of deprecated method `tungstenite::WebSocket::<Stream>::write_message`: Use `send`

Check warning on line 65 in gremlin-client/src/connection.rs

View workflow job for this annotation

GitHub Actions / grcov (ubuntu-latest, nightly, 3.6.2)

use of deprecated method `tungstenite::WebSocket::<Stream>::write_message`: Use `send`
.map_err(GremlinError::from)
}

Expand Down Expand Up @@ -120,6 +120,13 @@
self
}

/// Both the sync and async pool providers use a default of 30 seconds,
/// Async pool interprets `None` as no timeout. Sync pool maps `None` to the default value
pub fn pool_connection_timeout(mut self, pool_connection_timeout: Option<Duration>) -> Self {
self.0.pool_get_connection_timeout = pool_connection_timeout;
self
}

pub fn build(self) -> ConnectionOptions {
self.0
}
Expand Down Expand Up @@ -163,6 +170,7 @@
pub(crate) host: String,
pub(crate) port: u16,
pub(crate) pool_size: u32,
pub(crate) pool_get_connection_timeout: Option<Duration>,
pub(crate) credentials: Option<Credentials>,
pub(crate) ssl: bool,
pub(crate) tls_options: Option<TlsOptions>,
Expand Down Expand Up @@ -245,6 +253,7 @@
host: String::from("localhost"),
port: 8182,
pool_size: 10,
pool_get_connection_timeout: Some(Duration::from_secs(30)),
credentials: None,
ssl: false,
tls_options: None,
Expand Down
Loading