Thread
Commits
-
Fix off-by-one error in txid_status().
- 339927797c87 10.8 landed
- 26d4fda37ea1 11.3 landed
- d2fd7f74ee61 12.0 landed
-
txid_status() off-by-one error
Thomas Munro <thomas.munro@gmail.com> — 2019-03-27T06:55:57Z
Hello hackers, postgres=> select txid_status(txid_current() + 3); ERROR: transaction ID 627 is in the future postgres=> select txid_status(txid_current() + 2); ERROR: transaction ID 627 is in the future postgres=> select txid_status(txid_current() + 1); txid_status ------------- in progress (1 row) If you keep asking for txid_status(txid_current() + 1) in new transactions, you eventually hit: ERROR: could not access status of transaction 32768 DETAIL: Could not read from file "pg_xact/0000" at offset 8192: No error: 0. I think the fix is: --- a/src/backend/utils/adt/txid.c +++ b/src/backend/utils/adt/txid.c @@ -129,7 +129,7 @@ TransactionIdInRecentPast(uint64 xid_with_epoch, TransactionId *extracted_xid) /* If the transaction ID is in the future, throw an error. */ if (xid_epoch > now_epoch - || (xid_epoch == now_epoch && xid > now_epoch_last_xid)) + || (xid_epoch == now_epoch && xid >= now_epoch_last_xid)) ereport(ERROR, (errcode(ERRCODE_INVALID_PARAMETER_VALUE), errmsg("transaction ID %s is in the future", -- Thomas Munro https://enterprisedb.com -
Re: txid_status() off-by-one error
Thomas Munro <thomas.munro@gmail.com> — 2019-03-27T08:49:45Z
On Wed, Mar 27, 2019 at 7:55 PM Thomas Munro <thomas.munro@gmail.com> wrote: > If you keep asking for txid_status(txid_current() + 1) in new > transactions, you eventually hit: > > ERROR: could not access status of transaction 32768 > DETAIL: Could not read from file "pg_xact/0000" at offset 8192: No error: 0. > - || (xid_epoch == now_epoch && xid > now_epoch_last_xid)) > + || (xid_epoch == now_epoch && xid >= now_epoch_last_xid)) Pushed and back-patched, along with renaming of that variable, s/last/next/. -- Thomas Munro https://enterprisedb.com