1
0
mirror of https://github.com/postgres/postgres.git synced 2025-11-25 12:03:53 +03:00

Use FullTransactionId for the transaction stack.

Provide GetTopFullTransactionId() and GetCurrentFullTransactionId().
The intended users of these interfaces are access methods that use
xids for visibility checks but don't want to have to go back and
"freeze" existing references some time later before the 32 bit xid
counter wraps around.

Use a new struct to serialize the transaction state for parallel
query, because FullTransactionId doesn't fit into the previous
serialization scheme very well.

Author: Thomas Munro
Reviewed-by: Heikki Linnakangas
Discussion: https://postgr.es/m/CAA4eK1%2BMv%2Bmb0HFfWM9Srtc6MVe160WFurXV68iAFMcagRZ0dQ%40mail.gmail.com
This commit is contained in:
Thomas Munro
2019-03-28 10:59:19 +13:00
parent 2fc7af5e96
commit ad308058cc
5 changed files with 170 additions and 81 deletions

View File

@@ -35,7 +35,8 @@ VariableCache ShmemVariableCache = NULL;
/*
* Allocate the next XID for a new transaction or subtransaction.
* Allocate the next FullTransactionId for a new transaction or
* subtransaction.
*
* The new XID is also stored into MyPgXact before returning.
*
@@ -44,9 +45,10 @@ VariableCache ShmemVariableCache = NULL;
* does something. So it is safe to do a database lookup if we want to
* issue a warning about XID wrap.
*/
TransactionId
FullTransactionId
GetNewTransactionId(bool isSubXact)
{
FullTransactionId full_xid;
TransactionId xid;
/*
@@ -64,7 +66,7 @@ GetNewTransactionId(bool isSubXact)
{
Assert(!isSubXact);
MyPgXact->xid = BootstrapTransactionId;
return BootstrapTransactionId;
return FullTransactionIdFromEpochAndXid(0, BootstrapTransactionId);
}
/* safety check, we should never get this far in a HS standby */
@@ -73,7 +75,8 @@ GetNewTransactionId(bool isSubXact)
LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
xid = XidFromFullTransactionId(ShmemVariableCache->nextFullXid);
full_xid = ShmemVariableCache->nextFullXid;
xid = XidFromFullTransactionId(full_xid);
/*----------
* Check to see if it's safe to assign another XID. This protects against
@@ -232,7 +235,7 @@ GetNewTransactionId(bool isSubXact)
LWLockRelease(XidGenLock);
return xid;
return full_xid;
}
/*