Skip to content

fix: calculate rollback ratio independently of cache hits - #474

Merged
blogh merged 2 commits into
dalibo:masterfrom
pcbeingused33:fix/c3769-rollback-ratio
Nov 20, 2026
Merged

blogh merged 2 commits into
dalibo:masterfrom
pcbeingused33:fix/c3769-rollback-ratio

Conversation

@pcbeingused33

Copy link
Copy Markdown
Contributor

The rollback percentage displays N/A when a sampling interval contains only rolled-back transactions and no cache hits. The guard for the calculation incorrectly adds committed transactions to cache hits, so a valid nonzero transaction count can be ignored.

Use the sum of committed and rolled-back transactions to guard the rollback ratio calculation. Cache activity then has no effect on whether the ratio is available, and intervals without transactions continue to report N/A.

Testing and validation

A parametrized regression test supplies two server-statistics snapshots to the real sampling method, mocking database reads. It covers rollback-only intervals with and without cache hits, mixed transactions, commit-only intervals, and intervals without transactions. The rollback-only interval without cache hits fails on master (None instead of 100) and passes with this change.

python -m pytest tests/test_data.py -k test_rollback_ratio -q: 1 failed and 5 passed on master; 6 passed with the fix. Additional data doctests and type tests: 3 passed. Black, isort and diff whitespace checks pass. No live PostgreSQL server was used.

This change and its tests were generated with assistance from OpenAI Codex.

@blogh

blogh commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Hi, thank you fo rthe contribution, good catch!

@blogh

blogh commented Nov 19, 2026

Copy link
Copy Markdown
Collaborator

If we are going to add a test, I'd rather have it test all the values that are computed
in this try / except bloc instead of just this case. That way we have test on all the
value based on the previous snapshot instead only the commit ratio.

What do you think? Would that be ok for you to add this?

@pcbeingused33

Copy link
Copy Markdown
Contributor Author

Sure, makes sense. I extended the tests to cover everything computed in that try block from the previous snapshot: tps, size_evolution, inserts/updates/deletes per second, cache hit ratio and rollback ratio, plus a case with no activity between the two snapshots (no ratio computed). The server snapshots are faked by patching pg.fetchone, so no PostgreSQL instance is needed. Pushed as a new commit on top.

This reply was drafted with the help of an AI assistant (Claude); the change and tests were reviewed before posting.

@blogh
blogh merged commit 385f669 into dalibo:master Nov 20, 2026
@blogh

blogh commented Nov 20, 2026

Copy link
Copy Markdown
Collaborator

Thank you ! merged !

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.

2 participants