txid_status() off-by-one error

Started by Thomas Munroover 7 years ago2 messageshackers
Jump to latest
#1Thomas Munro
thomas.munro@gmail.com

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

#2Thomas Munro
thomas.munro@gmail.com
In reply to: Thomas Munro (#1)
Re: txid_status() off-by-one error

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