txid_status() off-by-one error

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: txid_status() off-by-one error
Date: 2019-03-27 06:55:57
Message-ID: CA+hUKG+uua_BV5cyfsioKVN2d61Lukg28ECsWTXKvh=BtN2DPA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Fabien COELHO 2019-03-27 07:19:55 RE: Timeout parameters
Previous Message Amit Langote 2019-03-27 06:48:33 Re: Ordered Partitioned Table Scans