print session duration; connect to all servers when validating (#11)

This commit is contained in:
Lev Kokotov
2022-02-12 09:24:24 -08:00
committed by GitHub
parent eb45d65110
commit 20ceb729a0
2 changed files with 67 additions and 17 deletions

View File

@@ -109,24 +109,27 @@ impl ConnectionPool {
/// Connect to all shards and grab server information.
/// Return server information we will pass to the clients
/// when they connect.
/// This also warms up the pool for clients that connect when
/// the pooler starts up.
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);
}
};
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);
}
};
let mut proxy = connection.0;
let _address = connection.1;
let server = &mut *proxy;
let mut proxy = connection.0;
let _address = connection.1;
let server = &mut *proxy;
server_infos.push(server.server_info());
server_infos.push(server.server_info());
}
}
// TODO: compare server information to make sure
@@ -326,6 +329,10 @@ impl ConnectionPool {
pub fn shards(&self) -> usize {
self.databases.len()
}
pub fn replicas(&self, shard: usize) -> usize {
self.addresses[shard].len()
}
}
pub struct ServerPool {