Skip to content
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
4 changes: 4 additions & 0 deletions integration/go/go_pgx/sharded_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"testing"
"time"

"github.com/jackc/pgx/v5"
"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -263,6 +264,9 @@ func TestShardedTwoPcAutoOnError(t *testing.T) {
assertShowField(t, "SHOW STATS", "total_xact_2pc_count", 0, "pgdog_2pc", "pgdog_sharded", 0, "primary")
assertShowField(t, "SHOW STATS", "total_xact_2pc_count", 0, "pgdog_2pc", "pgdog_sharded", 1, "primary")

// Give the pool an extra second to warm up.
time.Sleep(1 * time.Second)

// Attempt explicit transaction with non-existent table that would require 2PC
for i := range 25 {
tx, err := conn.BeginTx(context.Background(), pgx.TxOptions{})
Expand Down
14 changes: 14 additions & 0 deletions integration/load_balancer/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ export PGPASSWORD=postgres
echo "[load_balancer] Using PGDOG_BIN=${PGDOG_BIN}"
echo "[load_balancer] LLVM_PROFILE_FILE=${LLVM_PROFILE_FILE}"

docker-compose down 2>/dev/null || true

for p in 45000 45001 45002; do
container=$(docker ps -q --filter "publish=${p}")
if [ -n "${container}" ]; then
echo "Stopping docker container on port ${p}: ${container}"
docker kill ${container} 2>/dev/null || true
fi
if pid=$(lsof -t -i:${p} 2>/dev/null); then
echo "Killing process(es) on port ${p}: ${pid}"
kill -9 ${pid} 2>/dev/null || true
fi
done

docker-compose up -d

echo "Waiting for Postgres to be ready"
Expand Down
2 changes: 1 addition & 1 deletion integration/toxi/toxi_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def health(role, field = 'healthy')
rescue PG::Error
errors += 1
end
expect(errors).to be >= 1
expect(errors).to be_between(0, 1).inclusive
expect(health('replica')).to include('f')
sleep(0.4) # ban maintenance runs every 333ms
expect(health('replica', 'banned')).to include('t')
Expand Down
10 changes: 2 additions & 8 deletions pgdog-stats/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,8 @@ impl Stats {
.clamp(1, u32::MAX as usize);
self.averages.idle_xact_time =
diff.idle_xact_time / queries_in_xact.try_into().unwrap_or(u32::MAX);
self.averages
.reads
.checked_div(diff.xact_count)
.unwrap_or_default();
self.averages
.writes
.checked_div(diff.xact_count)
.unwrap_or_default();
self.averages.reads = diff.reads.checked_div(diff.xact_count).unwrap_or_default();
self.averages.writes = diff.writes.checked_div(diff.xact_count).unwrap_or_default();

self.last_counts = self.counts;
}
Expand Down
6 changes: 6 additions & 0 deletions pgdog/src/backend/pool/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,9 @@ mod tests {

stats.counts.idle_xact_time = Duration::from_millis(250);

stats.counts.reads = 30;
stats.counts.writes = 20;

stats.calc_averages(Duration::from_secs(1));

assert_eq!(stats.averages.query_time, Duration::from_millis(50));
Expand All @@ -502,6 +505,9 @@ mod tests {
assert_eq!(stats.averages.connect_time, Duration::from_millis(50));
// idle_xact_time is divided by (query_count - xact_count) = 10 - 5 = 5
assert_eq!(stats.averages.idle_xact_time, Duration::from_millis(50));
// reads/writes: first divided by secs (30/1=30, 20/1=20), then by xact_count (30/5=6, 20/5=4)
assert_eq!(stats.averages.reads, 6);
assert_eq!(stats.averages.writes, 4);
}

#[test]
Expand Down
Loading