mirror of
https://github.com/postgresml/pgcat.git
synced 2026-03-25 18:06:29 +00:00
Pass real server info to the client (#10)
This commit is contained in:
33
src/pool.rs
33
src/pool.rs
@@ -1,6 +1,7 @@
|
||||
/// Pooling and failover and banlist.
|
||||
use async_trait::async_trait;
|
||||
use bb8::{ManageConnection, Pool, PooledConnection};
|
||||
use bytes::BytesMut;
|
||||
use chrono::naive::NaiveDateTime;
|
||||
|
||||
use crate::config::{Address, Config, Role, User};
|
||||
@@ -105,6 +106,38 @@ impl ConnectionPool {
|
||||
}
|
||||
}
|
||||
|
||||
/// Connect to all shards and grab server information.
|
||||
/// Return server information we will pass to the clients
|
||||
/// when they connect.
|
||||
pub async fn validate(&mut self) -> Result<BytesMut, Error> {
|
||||
let mut server_infos = Vec::new();
|
||||
|
||||
for shard in 0..self.shards() {
|
||||
// TODO: query all primary and replicas in the shard configuration.
|
||||
let connection = match self.get(Some(shard), None).await {
|
||||
Ok(conn) => conn,
|
||||
Err(err) => {
|
||||
println!("> Shard {} down or misconfigured.", shard);
|
||||
return Err(err);
|
||||
}
|
||||
};
|
||||
|
||||
let mut proxy = connection.0;
|
||||
let _address = connection.1;
|
||||
let server = &mut *proxy;
|
||||
|
||||
server_infos.push(server.server_info());
|
||||
}
|
||||
|
||||
// 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())
|
||||
}
|
||||
|
||||
/// Get a connection from the pool.
|
||||
pub async fn get(
|
||||
&mut self,
|
||||
|
||||
Reference in New Issue
Block a user