Skip to content

Fix connection stats handling and add RESET STATS command - #1380

Open
rodneyosodo wants to merge 4 commits into
pgdogdev:mainfrom
rodneyosodo:fix/1281
Open

Fix connection stats handling and add RESET STATS command#1380
rodneyosodo wants to merge 4 commits into
pgdogdev:mainfrom
rodneyosodo:fix/1281

Conversation

@rodneyosodo

Copy link
Copy Markdown

Problem

Every RELOAD (SIGHUP or admin command) zeroed all pool and cluster statistics. Operators currently misuse RELOAD to reset counters, @ykonrad asked for a proper RESET STATS command.

What's changed

  • Pool stats survive reload: Pool::move_conns_to now copies the source pool's stats into the destination pool (the one-line fix at the spot @levkk pointed to).
  • Cluster metrics survive reload: Cluster::move_conns_to carries mirror counts and accumulates lookup-stats into the new cluster's Arc.
  • RESET STATS admin command: zeros pool stats, cluster mirror counts, and lookup stats across all databases/mirrors. Symmetric with what reload preserves.
  • Supporting helpers: LookupStats::reset/accumulate, ClusterMetrics::reset, Shard/Databases::reset_stats.

Verification

Manual run through pgdog confirms: queries counted → RELOAD preserved → RESET zeroed → counting resumes.

@CLAassistant

CLAassistant commented Aug 18, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@sgrif

sgrif commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Would you change anything marked as pub to either pub(crate) or pub(super) depending on where it's used, please?

let from = self.stats.lock();
let mut to = other.stats.lock();
to.mirror = from.mirror;
if !Arc::ptr_eq(&to.lookup, &from.lookup) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put this assertion higher, before we take the lock, to avoid deadlocks. Basically, we want to make sure that self and other are never the same cluster object.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.59155% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pgdog/src/backend/databases.rs 75.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
Signed-off-by: Rodney Osodo <socials@rodneyosodo.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants