Repository navigation
fix: calculate rollback ratio independently of cache hits - #474
Conversation
|
Hi, thank you fo rthe contribution, good catch! |
|
If we are going to add a test, I'd rather have it test all the values that are computed What do you think? Would that be ok for you to add this? |
|
Sure, makes sense. I extended the tests to cover everything computed in that This reply was drafted with the help of an AI assistant (Claude); the change and tests were reviewed before posting. |
|
Thank you ! merged ! |
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 (
Noneinstead of100) 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.