Compare commits

..

1 Commits

Author SHA1 Message Date
dependabot[bot]
26dd78d0aa chore(deps): bump itertools from 0.10.5 to 0.13.0
Bumps [itertools](https://github.com/rust-itertools/itertools) from 0.10.5 to 0.13.0.
- [Changelog](https://github.com/rust-itertools/itertools/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-itertools/itertools/compare/v0.10.5...v0.13.0)

---
updated-dependencies:
- dependency-name: itertools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-05-17 04:40:39 +00:00
11 changed files with 41 additions and 94 deletions

4
Cargo.lock generated
View File

@@ -760,9 +760,9 @@ dependencies = [
[[package]] [[package]]
name = "itertools" name = "itertools"
version = "0.10.5" version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
dependencies = [ dependencies = [
"either", "either",
] ]

View File

@@ -44,7 +44,7 @@ rustls = { version = "0.21", features = ["dangerous_configuration"] }
trust-dns-resolver = "0.22.0" trust-dns-resolver = "0.22.0"
tokio-test = "0.4.2" tokio-test = "0.4.2"
serde_json = "1" serde_json = "1"
itertools = "0.10" itertools = "0.13"
clap = { version = "4.3.1", features = ["derive", "env"] } clap = { version = "4.3.1", features = ["derive", "env"] }
tracing = "0.1.37" tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = [ tracing-subscriber = { version = "0.3.17", features = [

View File

@@ -1,4 +1,4 @@
FROM rust:1.79.0-slim-bookworm AS builder FROM rust:1-slim-bookworm AS builder
RUN apt-get update && \ RUN apt-get update && \
apt-get install -y build-essential apt-get install -y build-essential
@@ -19,4 +19,3 @@ COPY --from=builder /app/pgcat.toml /etc/pgcat/pgcat.toml
WORKDIR /etc/pgcat WORKDIR /etc/pgcat
ENV RUST_LOG=info ENV RUST_LOG=info
CMD ["pgcat"] CMD ["pgcat"]
STOPSIGNAL SIGINT

View File

@@ -11,7 +11,6 @@ RestartSec=1
Environment=RUST_LOG=info Environment=RUST_LOG=info
LimitNOFILE=65536 LimitNOFILE=65536
ExecStart=/usr/bin/pgcat /etc/pgcat.toml ExecStart=/usr/bin/pgcat /etc/pgcat.toml
ExecReload=/bin/kill -SIGHUP $MAINPID
[Install] [Install]
WantedBy=multi-user.target WantedBy=multi-user.target

View File

@@ -1204,12 +1204,9 @@ where
if !server.in_transaction() { if !server.in_transaction() {
// Report transaction executed statistics. // Report transaction executed statistics.
self.stats.transaction(); self.stats.transaction();
server.stats().transaction( server
Instant::now() .stats()
.duration_since(server.transaction_start().into()) .transaction(self.server_parameters.get_application_name());
.as_millis() as u64,
self.server_parameters.get_application_name(),
);
// Release server back to the pool if we are in transaction mode. // Release server back to the pool if we are in transaction mode.
// If we are in session mode, we keep the server until the client disconnects. // If we are in session mode, we keep the server until the client disconnects.
@@ -1463,12 +1460,9 @@ where
if !server.in_transaction() { if !server.in_transaction() {
self.stats.transaction(); self.stats.transaction();
server.stats().transaction( server
Instant::now() .stats()
.duration_since(server.transaction_start().into()) .transaction(self.server_parameters.get_application_name());
.as_millis() as u64,
self.server_parameters.get_application_name(),
);
// Release server back to the pool if we are in transaction mode. // Release server back to the pool if we are in transaction mode.
// If we are in session mode, we keep the server until the client disconnects. // If we are in session mode, we keep the server until the client disconnects.
@@ -1517,12 +1511,9 @@ where
if !server.in_transaction() { if !server.in_transaction() {
self.stats.transaction(); self.stats.transaction();
server.stats().transaction( server
Instant::now() .stats()
.duration_since(server.transaction_start().into()) .transaction(self.server_parameters.get_application_name());
.as_millis() as u64,
self.server_parameters.get_application_name(),
);
// Release server back to the pool if we are in transaction mode. // Release server back to the pool if we are in transaction mode.
// If we are in session mode, we keep the server until the client disconnects. // If we are in session mode, we keep the server until the client disconnects.

View File

@@ -38,12 +38,12 @@ pub enum Role {
Mirror, Mirror,
} }
impl std::fmt::Display for Role { impl ToString for Role {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn to_string(&self) -> String {
match self { match *self {
Role::Primary => write!(f, "primary"), Role::Primary => "primary".to_string(),
Role::Replica => write!(f, "replica"), Role::Replica => "replica".to_string(),
Role::Mirror => write!(f, "mirror"), Role::Mirror => "mirror".to_string(),
} }
} }
} }
@@ -476,11 +476,11 @@ pub enum PoolMode {
Session, Session,
} }
impl std::fmt::Display for PoolMode { impl ToString for PoolMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn to_string(&self) -> String {
match self { match *self {
PoolMode::Transaction => write!(f, "transaction"), PoolMode::Transaction => "transaction".to_string(),
PoolMode::Session => write!(f, "session"), PoolMode::Session => "session".to_string(),
} }
} }
} }
@@ -493,13 +493,12 @@ pub enum LoadBalancingMode {
#[serde(alias = "loc", alias = "LOC", alias = "least_outstanding_connections")] #[serde(alias = "loc", alias = "LOC", alias = "least_outstanding_connections")]
LeastOutstandingConnections, LeastOutstandingConnections,
} }
impl ToString for LoadBalancingMode {
impl std::fmt::Display for LoadBalancingMode { fn to_string(&self) -> String {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match *self {
match self { LoadBalancingMode::Random => "random".to_string(),
LoadBalancingMode::Random => write!(f, "random"),
LoadBalancingMode::LeastOutstandingConnections => { LoadBalancingMode::LeastOutstandingConnections => {
write!(f, "least_outstanding_connections") "least_outstanding_connections".to_string()
} }
} }
} }
@@ -1000,17 +999,15 @@ impl Config {
pub fn fill_up_auth_query_config(&mut self) { pub fn fill_up_auth_query_config(&mut self) {
for (_name, pool) in self.pools.iter_mut() { for (_name, pool) in self.pools.iter_mut() {
if pool.auth_query.is_none() { if pool.auth_query.is_none() {
pool.auth_query.clone_from(&self.general.auth_query); pool.auth_query = self.general.auth_query.clone();
} }
if pool.auth_query_user.is_none() { if pool.auth_query_user.is_none() {
pool.auth_query_user pool.auth_query_user = self.general.auth_query_user.clone();
.clone_from(&self.general.auth_query_user);
} }
if pool.auth_query_password.is_none() { if pool.auth_query_password.is_none() {
pool.auth_query_password pool.auth_query_password = self.general.auth_query_password.clone();
.clone_from(&self.general.auth_query_password);
} }
} }
} }
@@ -1158,7 +1155,7 @@ impl Config {
"Default max server lifetime: {}ms", "Default max server lifetime: {}ms",
self.general.server_lifetime self.general.server_lifetime
); );
info!("Server round robin: {}", self.general.server_round_robin); info!("Sever round robin: {}", self.general.server_round_robin);
match self.general.tls_certificate.clone() { match self.general.tls_certificate.clone() {
Some(tls_certificate) => { Some(tls_certificate) => {
info!("TLS certificate: {}", tls_certificate); info!("TLS certificate: {}", tls_certificate);

View File

@@ -733,10 +733,6 @@ pub fn configure_socket(stream: &TcpStream) {
} }
Err(err) => error!("Could not configure socket: {}", err), Err(err) => error!("Could not configure socket: {}", err),
} }
match sock_ref.set_nodelay(true) {
Ok(_) => (),
Err(err) => error!("Could not configure TCP_NODELAY for socket: {}", err),
}
} }
pub trait BytesMutReader { pub trait BytesMutReader {

View File

@@ -15,7 +15,6 @@ use std::sync::Arc;
use std::time::SystemTime; use std::time::SystemTime;
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, BufStream}; use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, BufStream};
use tokio::net::TcpStream; use tokio::net::TcpStream;
use tokio::time::Instant;
use tokio_rustls::rustls::{OwnedTrustAnchor, RootCertStore}; use tokio_rustls::rustls::{OwnedTrustAnchor, RootCertStore};
use tokio_rustls::{client::TlsStream, TlsConnector}; use tokio_rustls::{client::TlsStream, TlsConnector};
@@ -286,9 +285,6 @@ pub struct Server {
/// Is the server inside a transaction or idle. /// Is the server inside a transaction or idle.
in_transaction: bool, in_transaction: bool,
/// The time the most recent transaction started.
transaction_start: Instant,
/// Is there more data for the client to read. /// Is there more data for the client to read.
data_available: bool, data_available: bool,
@@ -808,7 +804,6 @@ impl Server {
process_id, process_id,
secret_key, secret_key,
in_transaction: false, in_transaction: false,
transaction_start: Instant::now(),
in_copy_mode: false, in_copy_mode: false,
data_available: false, data_available: false,
bad: false, bad: false,
@@ -941,7 +936,6 @@ impl Server {
// In transaction. // In transaction.
'T' => { 'T' => {
self.in_transaction = true; self.in_transaction = true;
self.transaction_start = Instant::now();
} }
// Idle, transaction over. // Idle, transaction over.
@@ -1226,12 +1220,6 @@ impl Server {
self.in_transaction self.in_transaction
} }
/// The start time of the most recent transaction.
/// Will be stale if not in a transaction.
pub fn transaction_start(&self) -> Instant {
self.transaction_start
}
/// Currently copying data from client to server or vice-versa. /// Currently copying data from client to server or vice-versa.
pub fn in_copy_mode(&self) -> bool { pub fn in_copy_mode(&self) -> bool {
self.in_copy_mode self.in_copy_mode

View File

@@ -14,11 +14,11 @@ pub enum ShardingFunction {
Sha1, Sha1,
} }
impl std::fmt::Display for ShardingFunction { impl ToString for ShardingFunction {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { fn to_string(&self) -> String {
match self { match *self {
ShardingFunction::PgBigintHash => write!(f, "pg_bigint_hash"), ShardingFunction::PgBigintHash => "pg_bigint_hash".to_string(),
ShardingFunction::Sha1 => write!(f, "sha1"), ShardingFunction::Sha1 => "sha1".to_string(),
} }
} }
} }

View File

@@ -187,12 +187,11 @@ impl ServerStats {
/// we report each individual queries outside a transaction as a transaction /// we report each individual queries outside a transaction as a transaction
/// We only count the initial BEGIN as a transaction, all queries within do not /// We only count the initial BEGIN as a transaction, all queries within do not
/// count as transactions /// count as transactions
pub fn transaction(&self, milliseconds: u64, application_name: &str) { pub fn transaction(&self, application_name: &str) {
self.set_application(application_name.to_string()); self.set_application(application_name.to_string());
self.transaction_count.fetch_add(1, Ordering::Relaxed); self.transaction_count.fetch_add(1, Ordering::Relaxed);
self.address.stats.xact_count_add(); self.address.stats.xact_count_add();
self.address.stats.xact_time_add(milliseconds);
} }
/// Report data sent to a server /// Report data sent to a server

View File

@@ -16,7 +16,7 @@ describe "Stats" do
it "updates *_query_time and *_wait_time" do it "updates *_query_time and *_wait_time" do
connections = Array.new(3) { PG::connect("#{pgcat_conn_str}?application_name=one_query") } connections = Array.new(3) { PG::connect("#{pgcat_conn_str}?application_name=one_query") }
connections.each do |c| connections.each do |c|
Thread.new { c.async_exec("BEGIN; SELECT pg_sleep(0.25); COMMIT;") } Thread.new { c.async_exec("SELECT pg_sleep(0.25)") }
end end
sleep(1) sleep(1)
connections.map(&:close) connections.map(&:close)
@@ -25,32 +25,10 @@ describe "Stats" do
sleep(15.5) sleep(15.5)
admin_conn = PG::connect(processes.pgcat.admin_connection_string) admin_conn = PG::connect(processes.pgcat.admin_connection_string)
results = admin_conn.async_exec("SHOW STATS")[0] results = admin_conn.async_exec("SHOW STATS")[0]
admin_conn.close
expect(results["total_query_time"].to_i).to be_within(200).of(750) expect(results["total_query_time"].to_i).to be_within(200).of(750)
expect(results["avg_query_time"].to_i).to be_within(50).of(250) expect(results["avg_query_time"].to_i).to be_within(50).of(250)
expect(results["total_xact_time"].to_i).to be_within(200).of(750)
expect(results["avg_xact_time"].to_i).to be_within(50).of(250)
expect(results["total_wait_time"].to_i).to_not eq(0)
expect(results["avg_wait_time"].to_i).to_not eq(0)
connections = Array.new(3) { PG::connect("#{pgcat_conn_str}?application_name=one_query") }
connections.each do |c|
Thread.new { c.async_exec("SELECT pg_sleep(0.25);") }
end
sleep(1)
connections.map(&:close)
results = admin_conn.async_exec("SHOW STATS")[0]
admin_conn.close
# This should increase with more queries
expect(results["total_query_time"].to_i).to be_within(400).of(1500)
expect(results["avg_query_time"].to_i).to be_within(50).of(250)
# This should not increase as we did not run any additional transactions
expect(results["total_xact_time"].to_i).to be_within(200).of(750)
expect(results["avg_xact_time"].to_i).to be_within(50).of(250)
expect(results["total_wait_time"].to_i).to_not eq(0) expect(results["total_wait_time"].to_i).to_not eq(0)
expect(results["avg_wait_time"].to_i).to_not eq(0) expect(results["avg_wait_time"].to_i).to_not eq(0)
end end