Commit ad308058 authored by Thomas Munro's avatar Thomas Munro

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
parent 2fc7af5e
...@@ -35,7 +35,8 @@ VariableCache ShmemVariableCache = NULL; ...@@ -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. * The new XID is also stored into MyPgXact before returning.
* *
...@@ -44,9 +45,10 @@ VariableCache ShmemVariableCache = NULL; ...@@ -44,9 +45,10 @@ VariableCache ShmemVariableCache = NULL;
* does something. So it is safe to do a database lookup if we want to * does something. So it is safe to do a database lookup if we want to
* issue a warning about XID wrap. * issue a warning about XID wrap.
*/ */
TransactionId FullTransactionId
GetNewTransactionId(bool isSubXact) GetNewTransactionId(bool isSubXact)
{ {
FullTransactionId full_xid;
TransactionId xid; TransactionId xid;
/* /*
...@@ -64,7 +66,7 @@ GetNewTransactionId(bool isSubXact) ...@@ -64,7 +66,7 @@ GetNewTransactionId(bool isSubXact)
{ {
Assert(!isSubXact); Assert(!isSubXact);
MyPgXact->xid = BootstrapTransactionId; MyPgXact->xid = BootstrapTransactionId;
return BootstrapTransactionId; return FullTransactionIdFromEpochAndXid(0, BootstrapTransactionId);
} }
/* safety check, we should never get this far in a HS standby */ /* safety check, we should never get this far in a HS standby */
...@@ -73,7 +75,8 @@ GetNewTransactionId(bool isSubXact) ...@@ -73,7 +75,8 @@ GetNewTransactionId(bool isSubXact)
LWLockAcquire(XidGenLock, LW_EXCLUSIVE); 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 * Check to see if it's safe to assign another XID. This protects against
...@@ -232,7 +235,7 @@ GetNewTransactionId(bool isSubXact) ...@@ -232,7 +235,7 @@ GetNewTransactionId(bool isSubXact)
LWLockRelease(XidGenLock); LWLockRelease(XidGenLock);
return xid; return full_xid;
} }
/* /*
......
This diff is collapsed.
...@@ -49,6 +49,7 @@ ...@@ -49,6 +49,7 @@
#define U64FromFullTransactionId(x) ((x).value) #define U64FromFullTransactionId(x) ((x).value)
#define FullTransactionIdPrecedes(a, b) ((a).value < (b).value) #define FullTransactionIdPrecedes(a, b) ((a).value < (b).value)
#define FullTransactionIdIsValid(x) TransactionIdIsValid(XidFromFullTransactionId(x)) #define FullTransactionIdIsValid(x) TransactionIdIsValid(XidFromFullTransactionId(x))
#define InvalidFullTransactionId FullTransactionIdFromEpochAndXid(0, InvalidTransactionId)
/* /*
* A 64 bit value that contains an epoch and a TransactionId. This is * A 64 bit value that contains an epoch and a TransactionId. This is
...@@ -221,7 +222,7 @@ extern TransactionId TransactionIdLatest(TransactionId mainxid, ...@@ -221,7 +222,7 @@ extern TransactionId TransactionIdLatest(TransactionId mainxid,
extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid); extern XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid);
/* in transam/varsup.c */ /* in transam/varsup.c */
extern TransactionId GetNewTransactionId(bool isSubXact); extern FullTransactionId GetNewTransactionId(bool isSubXact);
extern void AdvanceNextFullTransactionIdPastXid(TransactionId xid); extern void AdvanceNextFullTransactionIdPastXid(TransactionId xid);
extern FullTransactionId ReadNextFullTransactionId(void); extern FullTransactionId ReadNextFullTransactionId(void);
extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, extern void SetTransactionIdLimit(TransactionId oldest_datfrozenxid,
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#ifndef XACT_H #ifndef XACT_H
#define XACT_H #define XACT_H
#include "access/transam.h"
#include "access/xlogreader.h" #include "access/xlogreader.h"
#include "lib/stringinfo.h" #include "lib/stringinfo.h"
#include "nodes/pg_list.h" #include "nodes/pg_list.h"
...@@ -355,6 +356,10 @@ extern TransactionId GetCurrentTransactionId(void); ...@@ -355,6 +356,10 @@ extern TransactionId GetCurrentTransactionId(void);
extern TransactionId GetCurrentTransactionIdIfAny(void); extern TransactionId GetCurrentTransactionIdIfAny(void);
extern TransactionId GetStableLatestTransactionId(void); extern TransactionId GetStableLatestTransactionId(void);
extern SubTransactionId GetCurrentSubTransactionId(void); extern SubTransactionId GetCurrentSubTransactionId(void);
extern FullTransactionId GetTopFullTransactionId(void);
extern FullTransactionId GetTopFullTransactionIdIfAny(void);
extern FullTransactionId GetCurrentFullTransactionId(void);
extern FullTransactionId GetCurrentFullTransactionIdIfAny(void);
extern void MarkCurrentTransactionIdLoggedIfAny(void); extern void MarkCurrentTransactionIdLoggedIfAny(void);
extern bool SubTransactionIsActive(SubTransactionId subxid); extern bool SubTransactionIsActive(SubTransactionId subxid);
extern CommandId GetCurrentCommandId(bool used); extern CommandId GetCurrentCommandId(bool used);
......
...@@ -2107,6 +2107,7 @@ SeqTableData ...@@ -2107,6 +2107,7 @@ SeqTableData
SerCommitSeqNo SerCommitSeqNo
SerializedReindexState SerializedReindexState
SerializedSnapshotData SerializedSnapshotData
SerializedTransactionState
Session Session
SessionBackupState SessionBackupState
SetConstraintState SetConstraintState
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment