2022-02-05 13:25:03 -08:00
|
|
|
/// Pooling and failover and banlist.
|
2022-02-03 16:25:05 -08:00
|
|
|
use async_trait::async_trait;
|
2022-02-05 18:20:53 -08:00
|
|
|
use bb8::{ManageConnection, Pool, PooledConnection};
|
2022-02-11 22:19:49 -08:00
|
|
|
use bytes::BytesMut;
|
2022-02-05 10:02:13 -08:00
|
|
|
use chrono::naive::NaiveDateTime;
|
2022-02-03 16:25:05 -08:00
|
|
|
|
2022-02-09 20:02:20 -08:00
|
|
|
use crate::config::{Address, Config, Role, User};
|
2022-02-03 16:25:05 -08:00
|
|
|
use crate::errors::Error;
|
2022-02-03 17:06:19 -08:00
|
|
|
use crate::server::Server;
|
2022-02-14 10:00:55 -08:00
|
|
|
use crate::stats::Reporter;
|
2022-02-05 10:02:13 -08:00
|
|
|
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
use std::sync::{
|
2022-02-10 10:37:49 -08:00
|
|
|
// atomic::{AtomicUsize, Ordering},
|
2022-02-10 10:38:06 -08:00
|
|
|
Arc,
|
|
|
|
|
Mutex,
|
2022-02-05 10:02:13 -08:00
|
|
|
};
|
2022-02-14 10:00:55 -08:00
|
|
|
use std::time::Instant;
|
2022-02-05 10:02:13 -08:00
|
|
|
|
|
|
|
|
// Banlist: bad servers go in here.
|
2022-02-06 11:13:12 -08:00
|
|
|
pub type BanList = Arc<Mutex<Vec<HashMap<Address, NaiveDateTime>>>>;
|
2022-02-10 10:37:49 -08:00
|
|
|
// pub type Counter = Arc<AtomicUsize>;
|
2022-02-05 10:02:13 -08:00
|
|
|
pub type ClientServerMap = Arc<Mutex<HashMap<(i32, i32), (i32, i32, String, String)>>>;
|
2022-02-03 16:25:05 -08:00
|
|
|
|
2022-02-08 09:25:59 -08:00
|
|
|
#[derive(Clone, Debug)]
|
2022-02-05 18:20:53 -08:00
|
|
|
pub struct ConnectionPool {
|
2022-02-05 19:43:48 -08:00
|
|
|
databases: Vec<Vec<Pool<ServerPool>>>,
|
|
|
|
|
addresses: Vec<Vec<Address>>,
|
2022-02-10 10:37:49 -08:00
|
|
|
round_robin: usize,
|
2022-02-05 18:20:53 -08:00
|
|
|
banlist: BanList,
|
2022-02-08 09:25:59 -08:00
|
|
|
healthcheck_timeout: u64,
|
2022-02-08 09:28:53 -08:00
|
|
|
ban_time: i64,
|
2022-02-10 08:54:06 -08:00
|
|
|
pool_size: u32,
|
2022-02-14 10:00:55 -08:00
|
|
|
stats: Reporter,
|
2022-02-03 16:25:05 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 18:20:53 -08:00
|
|
|
impl ConnectionPool {
|
2022-02-08 09:25:59 -08:00
|
|
|
/// Construct the connection pool from a config file.
|
2022-02-14 10:00:55 -08:00
|
|
|
pub async fn from_config(
|
|
|
|
|
config: Config,
|
|
|
|
|
client_server_map: ClientServerMap,
|
|
|
|
|
stats: Reporter,
|
|
|
|
|
) -> ConnectionPool {
|
2022-02-08 09:25:59 -08:00
|
|
|
let mut shards = Vec::new();
|
|
|
|
|
let mut addresses = Vec::new();
|
|
|
|
|
let mut banlist = Vec::new();
|
|
|
|
|
let mut shard_ids = config
|
|
|
|
|
.shards
|
|
|
|
|
.clone()
|
|
|
|
|
.into_keys()
|
|
|
|
|
.map(|x| x.to_string())
|
|
|
|
|
.collect::<Vec<String>>();
|
|
|
|
|
shard_ids.sort_by_key(|k| k.parse::<i64>().unwrap());
|
|
|
|
|
|
|
|
|
|
for shard in shard_ids {
|
|
|
|
|
let shard = &config.shards[&shard];
|
|
|
|
|
let mut pools = Vec::new();
|
|
|
|
|
let mut replica_addresses = Vec::new();
|
|
|
|
|
|
2022-02-15 08:18:01 -08:00
|
|
|
for (idx, server) in shard.servers.iter().enumerate() {
|
2022-02-09 20:02:20 -08:00
|
|
|
let role = match server.2.as_ref() {
|
|
|
|
|
"primary" => Role::Primary,
|
|
|
|
|
"replica" => Role::Replica,
|
|
|
|
|
_ => {
|
|
|
|
|
println!("> Config error: server role can be 'primary' or 'replica', have: '{}'. Defaulting to 'replica'.", server.2);
|
|
|
|
|
Role::Replica
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-08 09:25:59 -08:00
|
|
|
let address = Address {
|
|
|
|
|
host: server.0.clone(),
|
|
|
|
|
port: server.1.to_string(),
|
2022-02-09 20:02:20 -08:00
|
|
|
role: role,
|
2022-02-15 08:18:01 -08:00
|
|
|
shard: idx,
|
2022-02-08 09:25:59 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let manager = ServerPool::new(
|
|
|
|
|
address.clone(),
|
|
|
|
|
config.user.clone(),
|
|
|
|
|
&shard.database,
|
|
|
|
|
client_server_map.clone(),
|
2022-02-14 10:00:55 -08:00
|
|
|
stats.clone(),
|
2022-02-08 09:25:59 -08:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
let pool = Pool::builder()
|
|
|
|
|
.max_size(config.general.pool_size)
|
|
|
|
|
.connection_timeout(std::time::Duration::from_millis(
|
|
|
|
|
config.general.connect_timeout,
|
|
|
|
|
))
|
|
|
|
|
.test_on_check_out(false)
|
|
|
|
|
.build(manager)
|
|
|
|
|
.await
|
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
|
|
pools.push(pool);
|
|
|
|
|
replica_addresses.push(address);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
shards.push(pools);
|
|
|
|
|
addresses.push(replica_addresses);
|
|
|
|
|
banlist.push(HashMap::new());
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
assert_eq!(shards.len(), addresses.len());
|
|
|
|
|
let address_len = addresses.len();
|
|
|
|
|
|
2022-02-08 09:25:59 -08:00
|
|
|
ConnectionPool {
|
|
|
|
|
databases: shards,
|
|
|
|
|
addresses: addresses,
|
2022-02-10 10:37:49 -08:00
|
|
|
round_robin: rand::random::<usize>() % address_len, // Start at a random replica
|
2022-02-08 09:25:59 -08:00
|
|
|
banlist: Arc::new(Mutex::new(banlist)),
|
|
|
|
|
healthcheck_timeout: config.general.healthcheck_timeout,
|
2022-02-08 09:28:53 -08:00
|
|
|
ban_time: config.general.ban_time,
|
2022-02-10 08:54:06 -08:00
|
|
|
pool_size: config.general.pool_size,
|
2022-02-14 10:00:55 -08:00
|
|
|
stats: stats,
|
2022-02-08 09:25:59 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-11 22:19:49 -08:00
|
|
|
/// Connect to all shards and grab server information.
|
|
|
|
|
/// Return server information we will pass to the clients
|
|
|
|
|
/// when they connect.
|
2022-02-12 09:24:24 -08:00
|
|
|
/// This also warms up the pool for clients that connect when
|
|
|
|
|
/// the pooler starts up.
|
2022-02-11 22:19:49 -08:00
|
|
|
pub async fn validate(&mut self) -> Result<BytesMut, Error> {
|
|
|
|
|
let mut server_infos = Vec::new();
|
|
|
|
|
|
|
|
|
|
for shard in 0..self.shards() {
|
2022-02-12 09:24:24 -08:00
|
|
|
for _ in 0..self.replicas(shard) {
|
|
|
|
|
let connection = match self.get(Some(shard), None).await {
|
|
|
|
|
Ok(conn) => conn,
|
|
|
|
|
Err(err) => {
|
|
|
|
|
println!("> Shard {} down or misconfigured.", shard);
|
|
|
|
|
return Err(err);
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-02-11 22:19:49 -08:00
|
|
|
|
2022-02-12 09:24:24 -08:00
|
|
|
let mut proxy = connection.0;
|
|
|
|
|
let _address = connection.1;
|
|
|
|
|
let server = &mut *proxy;
|
2022-02-11 22:19:49 -08:00
|
|
|
|
2022-02-12 09:24:24 -08:00
|
|
|
server_infos.push(server.server_info());
|
|
|
|
|
}
|
2022-02-11 22:19:49 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: compare server information to make sure
|
|
|
|
|
// all shards are running identical configurations.
|
|
|
|
|
if server_infos.len() == 0 {
|
|
|
|
|
return Err(Error::AllServersDown);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(server_infos[0].clone())
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-08 09:25:59 -08:00
|
|
|
/// Get a connection from the pool.
|
2022-02-05 18:20:53 -08:00
|
|
|
pub async fn get(
|
2022-02-10 10:37:49 -08:00
|
|
|
&mut self,
|
2022-02-05 19:43:48 -08:00
|
|
|
shard: Option<usize>,
|
2022-02-09 20:02:20 -08:00
|
|
|
role: Option<Role>,
|
2022-02-05 18:20:53 -08:00
|
|
|
) -> Result<(PooledConnection<'_, ServerPool>, Address), Error> {
|
2022-02-05 19:43:48 -08:00
|
|
|
// Set this to false to gain ~3-4% speed.
|
|
|
|
|
let with_health_check = true;
|
2022-02-14 10:00:55 -08:00
|
|
|
let now = Instant::now();
|
2022-02-05 19:43:48 -08:00
|
|
|
|
|
|
|
|
let shard = match shard {
|
|
|
|
|
Some(shard) => shard,
|
|
|
|
|
None => 0, // TODO: pick a shard at random
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-15 08:18:01 -08:00
|
|
|
// We are waiting for a server now.
|
|
|
|
|
self.stats.client_waiting();
|
|
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
let addresses = &self.addresses[shard];
|
|
|
|
|
|
|
|
|
|
// Make sure if a specific role is requested, it's available in the pool.
|
|
|
|
|
match role {
|
|
|
|
|
Some(role) => {
|
2022-02-11 11:19:40 -08:00
|
|
|
let role_count = addresses.iter().filter(|&db| db.role == role).count();
|
2022-02-10 08:54:06 -08:00
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
if role_count == 0 {
|
|
|
|
|
println!(
|
|
|
|
|
">> Error: Role '{:?}' requested, but none are configured.",
|
|
|
|
|
role
|
|
|
|
|
);
|
|
|
|
|
|
2022-02-10 08:54:06 -08:00
|
|
|
return Err(Error::AllServersDown);
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-09 21:19:14 -08:00
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
// Any role should be present.
|
|
|
|
|
_ => (),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let mut allowed_attempts = match role {
|
|
|
|
|
// Primary-specific queries get one attempt, if the primary is down,
|
|
|
|
|
// nothing we should do about it I think. It's dangerous to retry
|
|
|
|
|
// write queries.
|
|
|
|
|
Some(Role::Primary) => 1,
|
|
|
|
|
|
2022-02-10 08:54:06 -08:00
|
|
|
// Replicas get to try as many times as there are replicas
|
|
|
|
|
// and connections in the pool.
|
|
|
|
|
_ => self.databases[shard].len() * self.pool_size as usize,
|
2022-02-09 21:19:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
while allowed_attempts > 0 {
|
2022-02-10 10:37:49 -08:00
|
|
|
// Round-robin each client's queries.
|
|
|
|
|
// If a client only sends one query and then disconnects, it doesn't matter
|
|
|
|
|
// which replica it'll go to.
|
|
|
|
|
self.round_robin += 1;
|
|
|
|
|
let index = self.round_robin % addresses.len();
|
|
|
|
|
let address = &addresses[index];
|
2022-02-05 19:43:48 -08:00
|
|
|
|
2022-02-09 20:02:20 -08:00
|
|
|
// Make sure you're getting a primary or a replica
|
|
|
|
|
// as per request.
|
|
|
|
|
match role {
|
|
|
|
|
Some(role) => {
|
2022-02-09 21:19:14 -08:00
|
|
|
// If the client wants a specific role,
|
|
|
|
|
// we'll do our best to pick it, but if we only
|
|
|
|
|
// have one server in the cluster, it's probably only a primary
|
|
|
|
|
// (or only a replica), so the client will just get what we have.
|
2022-02-10 10:37:49 -08:00
|
|
|
if address.role != role && addresses.len() > 1 {
|
2022-02-09 20:02:20 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
None => (),
|
|
|
|
|
};
|
|
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
if self.is_banned(address, shard, role) {
|
2022-02-09 21:19:14 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
allowed_attempts -= 1;
|
|
|
|
|
|
2022-02-05 19:43:48 -08:00
|
|
|
// Check if we can connect
|
|
|
|
|
let mut conn = match self.databases[shard][index].get().await {
|
|
|
|
|
Ok(conn) => conn,
|
|
|
|
|
Err(err) => {
|
|
|
|
|
println!(">> Banning replica {}, error: {:?}", index, err);
|
2022-02-10 10:37:49 -08:00
|
|
|
self.ban(address, shard);
|
2022-02-05 19:43:48 -08:00
|
|
|
continue;
|
2022-02-05 18:20:53 -08:00
|
|
|
}
|
2022-02-05 19:43:48 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if !with_health_check {
|
2022-02-15 08:18:01 -08:00
|
|
|
self.stats.checkout_time(now.elapsed().as_micros());
|
|
|
|
|
self.stats.client_active();
|
2022-02-10 10:37:49 -08:00
|
|
|
return Ok((conn, address.clone()));
|
2022-02-05 13:15:53 -08:00
|
|
|
}
|
2022-02-03 16:25:05 -08:00
|
|
|
|
2022-02-05 19:43:48 -08:00
|
|
|
// // Check if this server is alive with a health check
|
|
|
|
|
let server = &mut *conn;
|
|
|
|
|
|
|
|
|
|
match tokio::time::timeout(
|
2022-02-08 16:56:29 -08:00
|
|
|
tokio::time::Duration::from_millis(self.healthcheck_timeout),
|
2022-02-05 19:43:48 -08:00
|
|
|
server.query("SELECT 1"),
|
|
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
{
|
2022-02-08 15:48:28 -08:00
|
|
|
// Check if health check succeeded
|
|
|
|
|
Ok(res) => match res {
|
2022-02-14 10:00:55 -08:00
|
|
|
Ok(_) => {
|
2022-02-15 08:18:01 -08:00
|
|
|
self.stats.checkout_time(now.elapsed().as_micros());
|
|
|
|
|
self.stats.client_active();
|
2022-02-14 10:00:55 -08:00
|
|
|
return Ok((conn, address.clone()));
|
|
|
|
|
}
|
2022-02-08 15:48:28 -08:00
|
|
|
Err(_) => {
|
|
|
|
|
println!(
|
|
|
|
|
">> Banning replica {} because of failed health check",
|
|
|
|
|
index
|
|
|
|
|
);
|
2022-02-10 08:54:06 -08:00
|
|
|
// Don't leave a bad connection in the pool.
|
|
|
|
|
server.mark_bad();
|
|
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
self.ban(address, shard);
|
2022-02-08 15:48:28 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
// Health check never came back, database is really really down
|
2022-02-05 19:43:48 -08:00
|
|
|
Err(_) => {
|
|
|
|
|
println!(
|
2022-02-08 15:48:28 -08:00
|
|
|
">> Banning replica {} because of health check timeout",
|
2022-02-05 19:43:48 -08:00
|
|
|
index
|
|
|
|
|
);
|
2022-02-10 08:54:06 -08:00
|
|
|
// Don't leave a bad connection in the pool.
|
|
|
|
|
server.mark_bad();
|
|
|
|
|
|
2022-02-10 10:37:49 -08:00
|
|
|
self.ban(address, shard);
|
2022-02-05 19:43:48 -08:00
|
|
|
continue;
|
2022-02-05 18:20:53 -08:00
|
|
|
}
|
|
|
|
|
}
|
2022-02-05 10:02:13 -08:00
|
|
|
}
|
2022-02-09 21:19:14 -08:00
|
|
|
|
|
|
|
|
return Err(Error::AllServersDown);
|
2022-02-05 10:02:13 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 13:25:03 -08:00
|
|
|
/// Ban an address (i.e. replica). It no longer will serve
|
|
|
|
|
/// traffic for any new transactions. Existing transactions on that replica
|
|
|
|
|
/// will finish successfully or error out to the clients.
|
2022-02-06 11:13:12 -08:00
|
|
|
pub fn ban(&self, address: &Address, shard: usize) {
|
2022-02-05 13:15:53 -08:00
|
|
|
println!(">> Banning {:?}", address);
|
2022-02-05 10:02:13 -08:00
|
|
|
let now = chrono::offset::Utc::now().naive_utc();
|
|
|
|
|
let mut guard = self.banlist.lock().unwrap();
|
2022-02-06 11:13:12 -08:00
|
|
|
guard[shard].insert(address.clone(), now);
|
2022-02-05 10:02:13 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 13:25:03 -08:00
|
|
|
/// Clear the replica to receive traffic again. Takes effect immediately
|
|
|
|
|
/// for all new transactions.
|
2022-02-08 17:08:17 -08:00
|
|
|
pub fn _unban(&self, address: &Address, shard: usize) {
|
2022-02-05 10:02:13 -08:00
|
|
|
let mut guard = self.banlist.lock().unwrap();
|
2022-02-06 11:13:12 -08:00
|
|
|
guard[shard].remove(address);
|
2022-02-05 10:02:13 -08:00
|
|
|
}
|
|
|
|
|
|
2022-02-05 13:25:03 -08:00
|
|
|
/// Check if a replica can serve traffic. If all replicas are banned,
|
|
|
|
|
/// we unban all of them. Better to try then not to.
|
2022-02-09 21:19:14 -08:00
|
|
|
pub fn is_banned(&self, address: &Address, shard: usize, role: Option<Role>) -> bool {
|
|
|
|
|
// If primary is requested explicitely, it can never be banned.
|
|
|
|
|
if Some(Role::Primary) == role {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If you're not asking for the primary,
|
|
|
|
|
// all databases are treated as replicas.
|
2022-02-05 10:02:13 -08:00
|
|
|
let mut guard = self.banlist.lock().unwrap();
|
|
|
|
|
|
2022-02-09 06:51:31 -08:00
|
|
|
// Everything is banned = nothing is banned.
|
2022-02-06 11:13:12 -08:00
|
|
|
if guard[shard].len() == self.databases[shard].len() {
|
2022-02-06 12:52:59 -08:00
|
|
|
guard[shard].clear();
|
2022-02-05 13:15:53 -08:00
|
|
|
drop(guard);
|
2022-02-05 13:25:03 -08:00
|
|
|
println!(">> Unbanning all replicas.");
|
2022-02-05 10:02:13 -08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// I expect this to miss 99.9999% of the time.
|
2022-02-06 11:13:12 -08:00
|
|
|
match guard[shard].get(address) {
|
2022-02-05 10:02:13 -08:00
|
|
|
Some(timestamp) => {
|
|
|
|
|
let now = chrono::offset::Utc::now().naive_utc();
|
2022-02-09 06:51:31 -08:00
|
|
|
// Ban expired.
|
2022-02-08 09:28:53 -08:00
|
|
|
if now.timestamp() - timestamp.timestamp() > self.ban_time {
|
2022-02-06 11:13:12 -08:00
|
|
|
guard[shard].remove(address);
|
2022-02-05 10:02:13 -08:00
|
|
|
false
|
|
|
|
|
} else {
|
|
|
|
|
true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
None => false,
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-05 19:43:48 -08:00
|
|
|
|
|
|
|
|
pub fn shards(&self) -> usize {
|
|
|
|
|
self.databases.len()
|
|
|
|
|
}
|
2022-02-12 09:24:24 -08:00
|
|
|
|
|
|
|
|
pub fn replicas(&self, shard: usize) -> usize {
|
|
|
|
|
self.addresses[shard].len()
|
|
|
|
|
}
|
2022-02-05 18:20:53 -08:00
|
|
|
}
|
2022-02-05 10:02:13 -08:00
|
|
|
|
2022-02-05 18:20:53 -08:00
|
|
|
pub struct ServerPool {
|
|
|
|
|
address: Address,
|
|
|
|
|
user: User,
|
|
|
|
|
database: String,
|
|
|
|
|
client_server_map: ClientServerMap,
|
2022-02-14 10:00:55 -08:00
|
|
|
stats: Reporter,
|
2022-02-05 18:20:53 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl ServerPool {
|
|
|
|
|
pub fn new(
|
|
|
|
|
address: Address,
|
|
|
|
|
user: User,
|
|
|
|
|
database: &str,
|
|
|
|
|
client_server_map: ClientServerMap,
|
2022-02-14 10:00:55 -08:00
|
|
|
stats: Reporter,
|
2022-02-05 18:20:53 -08:00
|
|
|
) -> ServerPool {
|
|
|
|
|
ServerPool {
|
|
|
|
|
address: address,
|
|
|
|
|
user: user,
|
|
|
|
|
database: database.to_string(),
|
|
|
|
|
client_server_map: client_server_map,
|
2022-02-14 10:00:55 -08:00
|
|
|
stats: stats,
|
2022-02-05 10:02:13 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-05 18:20:53 -08:00
|
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
|
impl ManageConnection for ServerPool {
|
|
|
|
|
type Connection = Server;
|
|
|
|
|
type Error = Error;
|
|
|
|
|
|
|
|
|
|
/// Attempts to create a new connection.
|
|
|
|
|
async fn connect(&self) -> Result<Self::Connection, Self::Error> {
|
2022-02-08 15:48:28 -08:00
|
|
|
println!(">> Creating a new connection for the pool");
|
2022-02-05 18:20:53 -08:00
|
|
|
|
|
|
|
|
Server::startup(
|
2022-02-15 08:18:01 -08:00
|
|
|
&self.address,
|
|
|
|
|
&self.user,
|
2022-02-05 18:20:53 -08:00
|
|
|
&self.database,
|
|
|
|
|
self.client_server_map.clone(),
|
2022-02-14 10:00:55 -08:00
|
|
|
self.stats.clone(),
|
2022-02-05 18:20:53 -08:00
|
|
|
)
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Determines if the connection is still connected to the database.
|
|
|
|
|
async fn is_valid(&self, _conn: &mut PooledConnection<'_, Self>) -> Result<(), Self::Error> {
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Synchronously determine if the connection is no longer usable, if possible.
|
|
|
|
|
fn has_broken(&self, conn: &mut Self::Connection) -> bool {
|
|
|
|
|
conn.is_bad()
|
|
|
|
|
}
|
|
|
|
|
}
|