Commit 3a28d78
committed
Improve TimestampDifferenceMilliseconds to cope with overflow sanely.
We'd like to use TimestampDifferenceMilliseconds with the stop_time
possibly being TIMESTAMP_INFINITY, but up to now it's disclaimed
responsibility for overflow cases. Define it to clamp its output to
the range [0, INT_MAX], handling overflow correctly. (INT_MAX rather
than LONG_MAX seems appropriate, because the function is already
described as being intended for calculating wait times for WaitLatch
et al, and that infrastructure only handles waits up to INT_MAX.
Also, this choice gets rid of cross-platform behavioral differences.)
Having done that, we can replace some ad-hoc code in walreceiver.c
with a simple call to TimestampDifferenceMilliseconds.
While at it, fix some buglets in existing callers of
TimestampDifferenceMilliseconds: basebackup_copy.c had not read the
memo about TimestampDifferenceMilliseconds never returning a negative
value, and postmaster.c had not read the memo about Min() and Max()
being macros with multiple-evaluation hazards. Neither of these
quite seem worth back-patching.
Patch by me; thanks to Nathan Bossart for review.
Discussion: https://postgr.es/m/3126727.1674759248@sss.pgh.pa.us1 parent 24ff700 commit 3a28d78
File tree
4 files changed
+24
-23
lines changed- src/backend
- backup
- postmaster
- replication
- utils/adt
4 files changed
+24
-23
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
215 | 215 | | |
216 | 216 | | |
217 | 217 | | |
218 | | - | |
| 218 | + | |
| 219 | + | |
219 | 220 | | |
220 | 221 | | |
221 | 222 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1670 | 1670 | | |
1671 | 1671 | | |
1672 | 1672 | | |
1673 | | - | |
1674 | | - | |
1675 | | - | |
1676 | | - | |
1677 | | - | |
| 1673 | + | |
| 1674 | + | |
| 1675 | + | |
| 1676 | + | |
| 1677 | + | |
| 1678 | + | |
1678 | 1679 | | |
1679 | 1680 | | |
1680 | 1681 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
445 | 445 | | |
446 | 446 | | |
447 | 447 | | |
448 | | - | |
| 448 | + | |
449 | 449 | | |
450 | 450 | | |
451 | 451 | | |
| |||
528 | 528 | | |
529 | 529 | | |
530 | 530 | | |
531 | | - | |
532 | | - | |
533 | | - | |
534 | | - | |
535 | | - | |
536 | | - | |
537 | | - | |
| 531 | + | |
538 | 532 | | |
539 | | - | |
| 533 | + | |
540 | 534 | | |
541 | 535 | | |
542 | 536 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1690 | 1690 | | |
1691 | 1691 | | |
1692 | 1692 | | |
1693 | | - | |
1694 | | - | |
1695 | | - | |
1696 | | - | |
1697 | | - | |
1698 | | - | |
| 1693 | + | |
| 1694 | + | |
1699 | 1695 | | |
1700 | 1696 | | |
1701 | 1697 | | |
1702 | 1698 | | |
| 1699 | + | |
| 1700 | + | |
| 1701 | + | |
1703 | 1702 | | |
1704 | 1703 | | |
1705 | 1704 | | |
1706 | 1705 | | |
1707 | 1706 | | |
1708 | 1707 | | |
1709 | | - | |
| 1708 | + | |
1710 | 1709 | | |
1711 | | - | |
| 1710 | + | |
| 1711 | + | |
1712 | 1712 | | |
| 1713 | + | |
| 1714 | + | |
| 1715 | + | |
| 1716 | + | |
| 1717 | + | |
1713 | 1718 | | |
1714 | 1719 | | |
1715 | 1720 | | |
| |||
0 commit comments