PostgreSQL Source Code git master
Data Structures | Macros | Typedefs | Functions | Variables
transam.h File Reference
#include "access/xlogdefs.h"
Include dependency graph for transam.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct   FullTransactionId
 
 

Macros

#define  InvalidTransactionId   ((TransactionId) 0)
 
 
#define  FrozenTransactionId   ((TransactionId) 2)
 
 
#define  MaxTransactionId   ((TransactionId) 0xFFFFFFFF)
 
#define  TransactionIdIsValid(xid)   ((xid) != InvalidTransactionId)
 
#define  TransactionIdIsNormal(xid)   ((xid) >= FirstNormalTransactionId)
 
#define  TransactionIdEquals(id1, id2)   ((id1) == (id2))
 
#define  TransactionIdStore(xid, dest)   (*(dest) = (xid))
 
#define  StoreInvalidTransactionId(dest)   (*(dest) = InvalidTransactionId)
 
#define  EpochFromFullTransactionId(x)   ((uint32) ((x).value >> 32))
 
#define  XidFromFullTransactionId(x)   ((uint32) (x).value)
 
#define  U64FromFullTransactionId(x)   ((x).value)
 
#define  FullTransactionIdEquals(a, b)   ((a).value == (b).value)
 
#define  FullTransactionIdPrecedes(a, b)   ((a).value < (b).value)
 
#define  FullTransactionIdPrecedesOrEquals(a, b)   ((a).value <= (b).value)
 
#define  FullTransactionIdFollows(a, b)   ((a).value > (b).value)
 
#define  FullTransactionIdFollowsOrEquals(a, b)   ((a).value >= (b).value)
 
 
 
 
 
#define  TransactionIdAdvance(dest)
 
#define  TransactionIdRetreat(dest)
 
#define  NormalTransactionIdPrecedes(id1, id2)
 
#define  NormalTransactionIdFollows(id1, id2)
 
#define  FirstGenbkiObjectId   10000
 
#define  FirstUnpinnedObjectId   12000
 
#define  FirstNormalObjectId   16384
 
#define  AssertTransactionIdInAllowableRange(xid)   ((void)true)
 

Typedefs

 
 

Functions

 
 
 
 
 
bool  TransactionIdDidCommit (TransactionId transactionId)
 
bool  TransactionIdDidAbort (TransactionId transactionId)
 
void  TransactionIdCommitTree (TransactionId xid, int nxids, TransactionId *xids)
 
 
void  TransactionIdAbortTree (TransactionId xid, int nxids, TransactionId *xids)
 
 
 
 
 
TransactionId  TransactionIdLatest (TransactionId mainxid, int nxids, const TransactionId *xids)
 
 
 
void  VarsupShmemInit (void)
 
 
 
 
void  SetTransactionIdLimit (TransactionId oldest_datfrozenxid, Oid oldest_datoid)
 
void  AdvanceOldestClogXid (TransactionId oldest_datfrozenxid)
 
 
 
 
 
 
 
 
 
 

Variables

 

Macro Definition Documentation

AssertTransactionIdInAllowableRange

#define AssertTransactionIdInAllowableRange (   xid )    ((void)true)

Definition at line 301 of file transam.h.

BootstrapTransactionId

#define BootstrapTransactionId   ((TransactionId) 1)

Definition at line 32 of file transam.h.

EpochFromFullTransactionId

#define EpochFromFullTransactionId (   x )    ((uint32) ((x).value >> 32))

Definition at line 47 of file transam.h.

FirstGenbkiObjectId

#define FirstGenbkiObjectId   10000

Definition at line 195 of file transam.h.

FirstNormalFullTransactionId

#define FirstNormalFullTransactionId   FullTransactionIdFromEpochAndXid(0, FirstNormalTransactionId)

Definition at line 57 of file transam.h.

FirstNormalObjectId

#define FirstNormalObjectId   16384

Definition at line 197 of file transam.h.

FirstNormalTransactionId

#define FirstNormalTransactionId   ((TransactionId) 3)

Definition at line 34 of file transam.h.

FirstUnpinnedObjectId

#define FirstUnpinnedObjectId   12000

Definition at line 196 of file transam.h.

FrozenTransactionId

#define FrozenTransactionId   ((TransactionId) 2)

Definition at line 33 of file transam.h.

FullTransactionIdEquals

#define FullTransactionIdEquals (   a,
  b 
)    ((a).value == (b).value)

Definition at line 50 of file transam.h.

FullTransactionIdFollows

#define FullTransactionIdFollows (   a,
  b 
)    ((a).value > (b).value)

Definition at line 53 of file transam.h.

FullTransactionIdFollowsOrEquals

#define FullTransactionIdFollowsOrEquals (   a,
  b 
)    ((a).value >= (b).value)

Definition at line 54 of file transam.h.

FullTransactionIdIsNormal

#define FullTransactionIdIsNormal (   x )    FullTransactionIdFollowsOrEquals(x, FirstNormalFullTransactionId)

Definition at line 58 of file transam.h.

FullTransactionIdIsValid

#define FullTransactionIdIsValid (   x )    TransactionIdIsValid(XidFromFullTransactionId(x))

Definition at line 55 of file transam.h.

FullTransactionIdPrecedes

#define FullTransactionIdPrecedes (   a,
  b 
)    ((a).value < (b).value)

Definition at line 51 of file transam.h.

FullTransactionIdPrecedesOrEquals

#define FullTransactionIdPrecedesOrEquals (   a,
  b 
)    ((a).value <= (b).value)

Definition at line 52 of file transam.h.

InvalidFullTransactionId

#define InvalidFullTransactionId   FullTransactionIdFromEpochAndXid(0, InvalidTransactionId)

Definition at line 56 of file transam.h.

InvalidTransactionId

#define InvalidTransactionId   ((TransactionId) 0)

Definition at line 31 of file transam.h.

MaxTransactionId

#define MaxTransactionId   ((TransactionId) 0xFFFFFFFF)

Definition at line 35 of file transam.h.

NormalTransactionIdFollows

#define NormalTransactionIdFollows (   id1,
  id2 
)
Value:
(int32) ((id1) - (id2)) > 0)
#define AssertMacro(condition)
Definition: c.h:858
int32_t int32
Definition: c.h:534
#define TransactionIdIsNormal(xid)
Definition: transam.h:42

Definition at line 152 of file transam.h.

NormalTransactionIdPrecedes

#define NormalTransactionIdPrecedes (   id1,
  id2 
)
Value:
(int32) ((id1) - (id2)) < 0)

Definition at line 147 of file transam.h.

StoreInvalidTransactionId

#define StoreInvalidTransactionId (   dest )    (*(dest) = InvalidTransactionId)

Definition at line 45 of file transam.h.

TransactionIdAdvance

#define TransactionIdAdvance (   dest )
Value:
do { \
(dest)++; \
} while(0)
#define FirstNormalTransactionId
Definition: transam.h:34

Definition at line 91 of file transam.h.

TransactionIdEquals

#define TransactionIdEquals (   id1,
  id2 
)    ((id1) == (id2))

Definition at line 43 of file transam.h.

TransactionIdIsNormal

#define TransactionIdIsNormal (   xid )    ((xid) >= FirstNormalTransactionId)

Definition at line 42 of file transam.h.

TransactionIdIsValid

#define TransactionIdIsValid (   xid )    ((xid) != InvalidTransactionId)

Definition at line 41 of file transam.h.

TransactionIdRetreat

#define TransactionIdRetreat (   dest )
Value:
do { \
(dest)--; \

Definition at line 141 of file transam.h.

TransactionIdStore

#define TransactionIdStore (   xid,
  dest 
)    (*(dest) = (xid))

Definition at line 44 of file transam.h.

U64FromFullTransactionId

#define U64FromFullTransactionId (   x )    ((x).value)

Definition at line 49 of file transam.h.

XidFromFullTransactionId

#define XidFromFullTransactionId (   x )    ((uint32) (x).value)

Definition at line 48 of file transam.h.

Typedef Documentation

FullTransactionId

TransamVariablesData

Function Documentation

AdvanceNextFullTransactionIdPastXid()

void AdvanceNextFullTransactionIdPastXid ( TransactionId  xid )

Definition at line 304 of file varsup.c.

305{
306 FullTransactionId newNextFullXid;
307 TransactionId next_xid;
309
310 /*
311 * It is safe to read nextXid without a lock, because this is only called
312 * from the startup process or single-process mode, meaning that no other
313 * process can modify it.
314 */
316
317 /* Fast return if this isn't an xid high enough to move the needle. */
319 if (!TransactionIdFollowsOrEquals(xid, next_xid))
320 return;
321
322 /*
323 * Compute the FullTransactionId that comes after the given xid. To do
324 * this, we preserve the existing epoch, but detect when we've wrapped
325 * into a new epoch. This is necessary because WAL records and 2PC state
326 * currently contain 32 bit xids. The wrap logic is safe in those cases
327 * because the span of active xids cannot exceed one epoch at any given
328 * point in the WAL stream.
329 */
332 if (unlikely(xid < next_xid))
333 ++epoch;
334 newNextFullXid = FullTransactionIdFromEpochAndXid(epoch, xid);
335
336 /*
337 * We still need to take a lock to modify the value when there are
338 * concurrent readers.
339 */
340 LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
341 TransamVariables->nextXid = newNextFullXid;
342 LWLockRelease(XidGenLock);
343}
#define unlikely(x)
Definition: c.h:402
uint32_t uint32
Definition: c.h:538
uint32 TransactionId
Definition: c.h:657
bool IsUnderPostmaster
Definition: globals.c:120
Assert(PointerIsAligned(start, uint64))
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1174
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1894
@ LW_EXCLUSIVE
Definition: lwlock.h:112
#define AmStartupProcess()
Definition: miscadmin.h:389
FullTransactionId nextXid
Definition: transam.h:220
bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:329
#define EpochFromFullTransactionId(x)
Definition: transam.h:47
#define XidFromFullTransactionId(x)
Definition: transam.h:48
static FullTransactionId FullTransactionIdFromEpochAndXid(uint32 epoch, TransactionId xid)
Definition: transam.h:71
#define TransactionIdAdvance(dest)
Definition: transam.h:91
TransamVariablesData * TransamVariables
Definition: varsup.c:34
static const unsigned __int64 epoch

References AmStartupProcess, Assert(), epoch, EpochFromFullTransactionId, FullTransactionIdFromEpochAndXid(), IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextXid, TransactionIdAdvance, TransactionIdFollowsOrEquals(), TransamVariables, unlikely, and XidFromFullTransactionId.

Referenced by ApplyWalRecord(), multixact_redo(), ProcArrayApplyRecoveryInfo(), ProcessTwoPhaseBuffer(), RecordKnownAssignedTransactionIds(), xact_redo_abort(), and xact_redo_commit().

AdvanceOldestClogXid()

void AdvanceOldestClogXid ( TransactionId  oldest_datfrozenxid )

Definition at line 355 of file varsup.c.

356{
357 LWLockAcquire(XactTruncationLock, LW_EXCLUSIVE);
359 oldest_datfrozenxid))
360 {
361 TransamVariables->oldestClogXid = oldest_datfrozenxid;
362 }
363 LWLockRelease(XactTruncationLock);
364}
TransactionId oldestClogXid
Definition: transam.h:253
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280

References LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransamVariablesData::oldestClogXid, TransactionIdPrecedes(), and TransamVariables.

Referenced by BootStrapXLOG(), clog_redo(), StartupXLOG(), and TruncateCLOG().

ForceTransactionIdLimitUpdate()

bool ForceTransactionIdLimitUpdate ( void  )

Definition at line 517 of file varsup.c.

518{
519 TransactionId nextXid;
520 TransactionId xidVacLimit;
521 TransactionId oldestXid;
522 Oid oldestXidDB;
523
524 /* Locking is probably not really necessary, but let's be careful */
525 LWLockAcquire(XidGenLock, LW_SHARED);
527 xidVacLimit = TransamVariables->xidVacLimit;
528 oldestXid = TransamVariables->oldestXid;
529 oldestXidDB = TransamVariables->oldestXidDB;
530 LWLockRelease(XidGenLock);
531
532 if (!TransactionIdIsNormal(oldestXid))
533 return true; /* shouldn't happen, but just in case */
534 if (!TransactionIdIsValid(xidVacLimit))
535 return true; /* this shouldn't happen anymore either */
536 if (TransactionIdFollowsOrEquals(nextXid, xidVacLimit))
537 return true; /* past xidVacLimit, don't delay updating */
538 if (!SearchSysCacheExists1(DATABASEOID, ObjectIdGetDatum(oldestXidDB)))
539 return true; /* could happen, per comments above */
540 return false;
541}
@ LW_SHARED
Definition: lwlock.h:113
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:262
unsigned int Oid
Definition: postgres_ext.h:32
TransactionId xidVacLimit
Definition: transam.h:223
TransactionId oldestXid
Definition: transam.h:222
#define SearchSysCacheExists1(cacheId, key1)
Definition: syscache.h:100
#define TransactionIdIsValid(xid)
Definition: transam.h:41

References LW_SHARED, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextXid, ObjectIdGetDatum(), TransamVariablesData::oldestXid, TransamVariablesData::oldestXidDB, SearchSysCacheExists1, TransactionIdFollowsOrEquals(), TransactionIdIsNormal, TransactionIdIsValid, TransamVariables, XidFromFullTransactionId, and TransamVariablesData::xidVacLimit.

Referenced by vac_update_datfrozenxid().

FullTransactionIdAdvance()

static void FullTransactionIdAdvance ( FullTransactionIddest )
inlinestatic

Definition at line 128 of file transam.h.

129{
130 dest->value++;
131
132 /* see FullTransactionIdAdvance() */
134 return;
135
137 dest->value++;
138}
#define FirstNormalFullTransactionId
Definition: transam.h:57
#define FullTransactionIdPrecedes(a, b)
Definition: transam.h:51

References generate_unaccent_rules::dest, FirstNormalFullTransactionId, FirstNormalTransactionId, FullTransactionIdPrecedes, and XidFromFullTransactionId.

Referenced by GetNewTransactionId(), and GetSnapshotData().

FullTransactionIdFromAllowableAt()

static FullTransactionId FullTransactionIdFromAllowableAt ( FullTransactionId  nextFullXid,
TransactionId  xid 
)
inlinestatic

Definition at line 381 of file transam.h.

383{
385
386 /* Special transaction ID. */
387 if (!TransactionIdIsNormal(xid))
389
391 XidFromFullTransactionId(nextFullXid)));
392
393 /*
394 * The 64 bit result must be <= nextFullXid, since nextFullXid hadn't been
395 * issued yet when xid was in the past. The xid must therefore be from
396 * the epoch of nextFullXid or the epoch before. We know this because we
397 * must remove (by freezing) an XID before assigning the XID half an epoch
398 * ahead of it.
399 *
400 * The unlikely() branch hint is dubious. It's perfect for the first 2^32
401 * XIDs of a cluster's life. Right at 2^32 XIDs, misprediction shoots to
402 * 100%, then improves until perfection returns 2^31 XIDs later. Since
403 * current callers pass relatively-recent XIDs, expect >90% prediction
404 * accuracy overall. This favors average latency over tail latency.
405 */
406 epoch = EpochFromFullTransactionId(nextFullXid);
407 if (unlikely(xid > XidFromFullTransactionId(nextFullXid)))
408 {
409 Assert(epoch != 0);
410 epoch--;
411 }
412
414}
bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
Definition: transam.c:299

References Assert(), epoch, EpochFromFullTransactionId, FullTransactionIdFromEpochAndXid(), TransactionIdIsNormal, TransactionIdPrecedesOrEquals(), unlikely, and XidFromFullTransactionId.

Referenced by AdjustToFullTransactionId(), pg_current_snapshot(), PrepareRedoAdd(), PrepareRedoRemove(), ProcessStandbyPSRequestMessage(), removable_cutoff(), TransactionIdInRecentPast(), and XLogRecGetFullXid().

FullTransactionIdFromEpochAndXid()

static FullTransactionId FullTransactionIdFromEpochAndXid ( uint32  epoch,
TransactionId  xid 
)
inlinestatic

Definition at line 71 of file transam.h.

72{
73 FullTransactionId result;
74
75 result.value = ((uint64) epoch) << 32 | xid;
76
77 return result;
78}
uint64_t uint64
Definition: c.h:539
uint64 value
Definition: transam.h:67

References epoch, and FullTransactionId::value.

Referenced by AdvanceNextFullTransactionIdPastXid(), BootStrapXLOG(), FullTransactionIdFromAllowableAt(), FullTransactionIdFromXidAndCtx(), GetNewTransactionId(), GistPageGetDeleteXid(), GuessControlValues(), and main().

FullTransactionIdFromU64()

static FullTransactionId FullTransactionIdFromU64 ( uint64  value )
inlinestatic

Definition at line 81 of file transam.h.

82{
83 FullTransactionId result;
84
85 result.value = value;
86
87 return result;
88}
static struct @169 value

References FullTransactionId::value, and value.

Referenced by DatumGetFullTransactionId(), FullTransactionIdFromXidAndCtx(), FullXidRelativeTo(), LogicalRepApplyLoop(), parse_snapshot(), pg_snapshot_recv(), restoreTwoPhaseData(), xid8in(), and xid8recv().

FullTransactionIdNewer()

static FullTransactionId FullTransactionIdNewer ( FullTransactionId  a,
)
inlinestatic

Definition at line 360 of file transam.h.

361{
363 return b;
364
366 return a;
367
369 return a;
370 return b;
371}
b
int b
Definition: isn.c:74
a
int a
Definition: isn.c:73
#define FullTransactionIdFollows(a, b)
Definition: transam.h:53
#define FullTransactionIdIsValid(x)
Definition: transam.h:55

References a, b, FullTransactionIdFollows, and FullTransactionIdIsValid.

Referenced by GetSnapshotData(), and GlobalVisUpdateApply().

FullTransactionIdRetreat()

static void FullTransactionIdRetreat ( FullTransactionIddest )
inlinestatic

Definition at line 103 of file transam.h.

104{
105 dest->value--;
106
107 /*
108 * In contrast to 32bit XIDs don't step over the "actual" special xids.
109 * For 64bit xids these can't be reached as part of a wraparound as they
110 * can in the 32bit case.
111 */
113 return;
114
115 /*
116 * But we do need to step over XIDs that'd appear special only for 32bit
117 * XIDs.
118 */
120 dest->value--;
121}

References generate_unaccent_rules::dest, FirstNormalFullTransactionId, FirstNormalTransactionId, FullTransactionIdPrecedes, and XidFromFullTransactionId.

Referenced by ExpireAllKnownAssignedTransactionIds(), and StartupXLOG().

GetNewObjectId()

Oid GetNewObjectId ( void  )

Definition at line 555 of file varsup.c.

556{
557 Oid result;
558
559 /* safety check, we should never get this far in a HS standby */
560 if (RecoveryInProgress())
561 elog(ERROR, "cannot assign OIDs during recovery");
562
563 LWLockAcquire(OidGenLock, LW_EXCLUSIVE);
564
565 /*
566 * Check for wraparound of the OID counter. We *must* not return 0
567 * (InvalidOid), and in normal operation we mustn't return anything below
568 * FirstNormalObjectId since that range is reserved for initdb (see
569 * IsCatalogRelationOid()). Note we are relying on unsigned comparison.
570 *
571 * During initdb, we start the OID generator at FirstGenbkiObjectId, so we
572 * only wrap if before that point when in bootstrap or standalone mode.
573 * The first time through this routine after normal postmaster start, the
574 * counter will be forced up to FirstNormalObjectId. This mechanism
575 * leaves the OIDs between FirstGenbkiObjectId and FirstNormalObjectId
576 * available for automatic assignment during initdb, while ensuring they
577 * will never conflict with user-assigned OIDs.
578 */
580 {
582 {
583 /* wraparound, or first post-initdb assignment, in normal mode */
586 }
587 else
588 {
589 /* we may be bootstrapping, so don't enforce the full range */
591 {
592 /* wraparound in standalone mode (unlikely but possible) */
595 }
596 }
597 }
598
599 /* If we run out of logged for use oids then we must log more */
600 if (TransamVariables->oidCount == 0)
601 {
604 }
605
606 result = TransamVariables->nextOid;
607
610
611 LWLockRelease(OidGenLock);
612
613 return result;
614}
#define ERROR
Definition: elog.h:39
#define elog(elevel,...)
Definition: elog.h:226
bool IsPostmasterEnvironment
Definition: globals.c:119
uint32 oidCount
Definition: transam.h:215
#define FirstGenbkiObjectId
Definition: transam.h:195
#define FirstNormalObjectId
Definition: transam.h:197
#define VAR_OID_PREFETCH
Definition: varsup.c:31
bool RecoveryInProgress(void)
Definition: xlog.c:6386
void XLogPutNextOid(Oid nextOid)
Definition: xlog.c:8073

References elog, ERROR, FirstGenbkiObjectId, FirstNormalObjectId, IsPostmasterEnvironment, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextOid, TransamVariablesData::oidCount, RecoveryInProgress(), TransamVariables, VAR_OID_PREFETCH, and XLogPutNextOid().

Referenced by GetNewOidWithIndex(), and GetNewRelFileNumber().

GetNewTransactionId()

FullTransactionId GetNewTransactionId ( bool  isSubXact )

Definition at line 77 of file varsup.c.

78{
79 FullTransactionId full_xid;
80 TransactionId xid;
81
82 /*
83 * Workers synchronize transaction state at the beginning of each parallel
84 * operation, so we can't account for new XIDs after that point.
85 */
86 if (IsInParallelMode())
87 elog(ERROR, "cannot assign TransactionIds during a parallel operation");
88
89 /*
90 * During bootstrap initialization, we return the special bootstrap
91 * transaction id.
92 */
94 {
95 Assert(!isSubXact);
99 }
100
101 /* safety check, we should never get this far in a HS standby */
102 if (RecoveryInProgress())
103 elog(ERROR, "cannot assign TransactionIds during recovery");
104
105 LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
106
107 full_xid = TransamVariables->nextXid;
108 xid = XidFromFullTransactionId(full_xid);
109
110 /*----------
111 * Check to see if it's safe to assign another XID. This protects against
112 * catastrophic data loss due to XID wraparound. The basic rules are:
113 *
114 * If we're past xidVacLimit, start trying to force autovacuum cycles.
115 * If we're past xidWarnLimit, start issuing warnings.
116 * If we're past xidStopLimit, refuse to execute transactions, unless
117 * we are running in single-user mode (which gives an escape hatch
118 * to the DBA who somehow got past the earlier defenses).
119 *
120 * Note that this coding also appears in GetNewMultiXactId.
121 *----------
122 */
124 {
125 /*
126 * For safety's sake, we release XidGenLock while sending signals,
127 * warnings, etc. This is not so much because we care about
128 * preserving concurrency in this situation, as to avoid any
129 * possibility of deadlock while doing get_database_name(). First,
130 * copy all the shared values we'll need in this path.
131 */
135 Oid oldest_datoid = TransamVariables->oldestXidDB;
136
137 LWLockRelease(XidGenLock);
138
139 /*
140 * To avoid swamping the postmaster with signals, we issue the autovac
141 * request only once per 64K transaction starts. This still gives
142 * plenty of chances before we get into real trouble.
143 */
144 if (IsUnderPostmaster && (xid % 65536) == 0)
146
147 if (IsUnderPostmaster &&
148 TransactionIdFollowsOrEquals(xid, xidStopLimit))
149 {
150 char *oldest_datname = get_database_name(oldest_datoid);
151
152 /* complain even if that DB has disappeared */
153 if (oldest_datname)
155 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
156 errmsg("database is not accepting commands that assign new transaction IDs to avoid wraparound data loss in database \"%s\"",
157 oldest_datname),
158 errhint("Execute a database-wide VACUUM in that database.\n"
159 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
160 else
162 (errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
163 errmsg("database is not accepting commands that assign new transaction IDs to avoid wraparound data loss in database with OID %u",
164 oldest_datoid),
165 errhint("Execute a database-wide VACUUM in that database.\n"
166 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
167 }
168 else if (TransactionIdFollowsOrEquals(xid, xidWarnLimit))
169 {
170 char *oldest_datname = get_database_name(oldest_datoid);
171
172 /* complain even if that DB has disappeared */
173 if (oldest_datname)
175 (errmsg("database \"%s\" must be vacuumed within %u transactions",
176 oldest_datname,
177 xidWrapLimit - xid),
178 errhint("To avoid transaction ID assignment failures, execute a database-wide VACUUM in that database.\n"
179 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
180 else
182 (errmsg("database with OID %u must be vacuumed within %u transactions",
183 oldest_datoid,
184 xidWrapLimit - xid),
185 errhint("To avoid XID assignment failures, execute a database-wide VACUUM in that database.\n"
186 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
187 }
188
189 /* Re-acquire lock and start over */
190 LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
191 full_xid = TransamVariables->nextXid;
192 xid = XidFromFullTransactionId(full_xid);
193 }
194
195 /*
196 * If we are allocating the first XID of a new page of the commit log,
197 * zero out that commit-log page before returning. We must do this while
198 * holding XidGenLock, else another xact could acquire and commit a later
199 * XID before we zero the page. Fortunately, a page of the commit log
200 * holds 32K or more transactions, so we don't have to do this very often.
201 *
202 * Extend pg_subtrans and pg_commit_ts too.
203 */
204 ExtendCLOG(xid);
205 ExtendCommitTs(xid);
206 ExtendSUBTRANS(xid);
207
208 /*
209 * Now advance the nextXid counter. This must not happen until after we
210 * have successfully completed ExtendCLOG() --- if that routine fails, we
211 * want the next incoming transaction to try it again. We cannot assign
212 * more XIDs until there is CLOG space for them.
213 */
215
216 /*
217 * We must store the new XID into the shared ProcArray before releasing
218 * XidGenLock. This ensures that every active XID older than
219 * latestCompletedXid is present in the ProcArray, which is essential for
220 * correct OldestXmin tracking; see src/backend/access/transam/README.
221 *
222 * Note that readers of ProcGlobal->xids/PGPROC->xid should be careful to
223 * fetch the value for each proc only once, rather than assume they can
224 * read a value multiple times and get the same answer each time. Note we
225 * are assuming that TransactionId and int fetch/store are atomic.
226 *
227 * The same comments apply to the subxact xid count and overflow fields.
228 *
229 * Use of a write barrier prevents dangerous code rearrangement in this
230 * function; other backends could otherwise e.g. be examining my subxids
231 * info concurrently, and we don't want them to see an invalid
232 * intermediate state, such as an incremented nxids before the array entry
233 * is filled.
234 *
235 * Other processes that read nxids should do so before reading xids
236 * elements with a pg_read_barrier() in between, so that they can be sure
237 * not to read an uninitialized array element; see
238 * src/backend/storage/lmgr/README.barrier.
239 *
240 * If there's no room to fit a subtransaction XID into PGPROC, set the
241 * cache-overflowed flag instead. This forces readers to look in
242 * pg_subtrans to map subtransaction XIDs up to top-level XIDs. There is a
243 * race-condition window, in that the new XID will not appear as running
244 * until its parent link has been placed into pg_subtrans. However, that
245 * will happen before anyone could possibly have a reason to inquire about
246 * the status of the XID, so it seems OK. (Snapshots taken during this
247 * window *will* include the parent XID, so they will deliver the correct
248 * answer later on when someone does have a reason to inquire.)
249 */
250 if (!isSubXact)
251 {
256
257 /* LWLockRelease acts as barrier */
258 MyProc->xid = xid;
260 }
261 else
262 {
264 int nxids = MyProc->subxidStatus.count;
265
266 Assert(substat->count == MyProc->subxidStatus.count);
268
269 if (nxids < PGPROC_MAX_CACHED_SUBXIDS)
270 {
271 MyProc->subxids.xids[nxids] = xid;
273 MyProc->subxidStatus.count = substat->count = nxids + 1;
274 }
275 else
276 MyProc->subxidStatus.overflowed = substat->overflowed = true;
277 }
278
279 LWLockRelease(XidGenLock);
280
281 return full_xid;
282}
#define pg_write_barrier()
Definition: atomics.h:155
void ExtendCLOG(TransactionId newestXact)
Definition: clog.c:924
void ExtendCommitTs(TransactionId newestXact)
Definition: commit_ts.c:816
int errhint(const char *fmt,...)
Definition: elog.c:1321
int errcode(int sqlerrcode)
Definition: elog.c:854
int errmsg(const char *fmt,...)
Definition: elog.c:1071
#define WARNING
Definition: elog.h:36
#define ereport(elevel,...)
Definition: elog.h:150
char * get_database_name(Oid dbid)
Definition: lsyscache.c:1259
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:476
void SendPostmasterSignal(PMSignalReason reason)
Definition: pmsignal.c:165
@ PMSIGNAL_START_AUTOVAC_LAUNCHER
Definition: pmsignal.h:39
#define PGPROC_MAX_CACHED_SUBXIDS
Definition: proc.h:39
PGPROC * MyProc
Definition: proc.c:66
PROC_HDR * ProcGlobal
Definition: proc.c:78
int pgxactoff
Definition: proc.h:201
XidCacheStatus subxidStatus
Definition: proc.h:280
TransactionId xid
Definition: proc.h:189
struct XidCache subxids
Definition: proc.h:282
XidCacheStatus * subxidStates
Definition: proc.h:397
TransactionId * xids
Definition: proc.h:391
TransactionId xidStopLimit
Definition: transam.h:225
TransactionId xidWarnLimit
Definition: transam.h:224
TransactionId xidWrapLimit
Definition: transam.h:226
bool overflowed
Definition: proc.h:46
uint8 count
Definition: proc.h:44
TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS]
Definition: proc.h:51
void ExtendSUBTRANS(TransactionId newestXact)
Definition: subtrans.c:353
#define BootstrapTransactionId
Definition: transam.h:32
static void FullTransactionIdAdvance(FullTransactionId *dest)
Definition: transam.h:128
bool IsInParallelMode(void)
Definition: xact.c:1089

References Assert(), BootstrapTransactionId, XidCacheStatus::count, elog, ereport, errcode(), errhint(), errmsg(), ERROR, ExtendCLOG(), ExtendCommitTs(), ExtendSUBTRANS(), FullTransactionIdAdvance(), FullTransactionIdFromEpochAndXid(), get_database_name(), IsBootstrapProcessingMode, IsInParallelMode(), IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MyProc, TransamVariablesData::nextXid, TransamVariablesData::oldestXidDB, XidCacheStatus::overflowed, pg_write_barrier, PGPROC_MAX_CACHED_SUBXIDS, PGPROC::pgxactoff, PMSIGNAL_START_AUTOVAC_LAUNCHER, ProcGlobal, RecoveryInProgress(), SendPostmasterSignal(), PGPROC::subxids, PROC_HDR::subxidStates, PGPROC::subxidStatus, TransactionIdFollowsOrEquals(), TransamVariables, WARNING, PGPROC::xid, XidFromFullTransactionId, XidCache::xids, PROC_HDR::xids, TransamVariablesData::xidStopLimit, TransamVariablesData::xidVacLimit, TransamVariablesData::xidWarnLimit, and TransamVariablesData::xidWrapLimit.

Referenced by AssignTransactionId(), and consume_xids_common().

NormalTransactionIdOlder()

static TransactionId NormalTransactionIdOlder ( TransactionId  a,
)
inlinestatic

Definition at line 349 of file transam.h.

350{
354 return a;
355 return b;
356}
#define NormalTransactionIdPrecedes(id1, id2)
Definition: transam.h:147

References a, Assert(), b, NormalTransactionIdPrecedes, and TransactionIdIsNormal.

ReadNextFullTransactionId()

FullTransactionId ReadNextFullTransactionId ( void  )

Definition at line 288 of file varsup.c.

289{
290 FullTransactionId fullXid;
291
292 LWLockAcquire(XidGenLock, LW_SHARED);
293 fullXid = TransamVariables->nextXid;
294 LWLockRelease(XidGenLock);
295
296 return fullXid;
297}

References LW_SHARED, LWLockAcquire(), LWLockRelease(), TransamVariablesData::nextXid, and TransamVariables.

Referenced by _bt_unlink_halfdead_page(), AdjustToFullTransactionId(), consume_xids(), consume_xids_common(), gistdeletepage(), pg_current_snapshot(), ProcessStandbyPSRequestMessage(), ReadNextTransactionId(), removable_cutoff(), ResolveRecoveryConflictWithSnapshotFullXid(), TransactionIdInRecentPast(), and XLogWalRcvSendHSFeedback().

ReadNextTransactionId()

static TransactionId ReadNextTransactionId ( void  )
inlinestatic

Definition at line 315 of file transam.h.

316{
318}
FullTransactionId ReadNextFullTransactionId(void)
Definition: varsup.c:288

References ReadNextFullTransactionId(), and XidFromFullTransactionId.

Referenced by ActivateCommitTs(), AutoVacWorkerMain(), do_start_worker(), GetStableLatestTransactionId(), ginDeletePage(), heap_vacuum_rel(), vac_truncate_clog(), vac_update_datfrozenxid(), vac_update_relstats(), vacuum_get_cutoffs(), and vacuum_xid_failsafe_check().

SetTransactionIdLimit()

void SetTransactionIdLimit ( TransactionId  oldest_datfrozenxid,
Oid  oldest_datoid 
)

Definition at line 372 of file varsup.c.

373{
374 TransactionId xidVacLimit;
375 TransactionId xidWarnLimit;
376 TransactionId xidStopLimit;
377 TransactionId xidWrapLimit;
378 TransactionId curXid;
379
380 Assert(TransactionIdIsNormal(oldest_datfrozenxid));
381
382 /*
383 * The place where we actually get into deep trouble is halfway around
384 * from the oldest potentially-existing XID. (This calculation is
385 * probably off by one or two counts, because the special XIDs reduce the
386 * size of the loop a little bit. But we throw in plenty of slop below,
387 * so it doesn't matter.)
388 */
389 xidWrapLimit = oldest_datfrozenxid + (MaxTransactionId >> 1);
390 if (xidWrapLimit < FirstNormalTransactionId)
391 xidWrapLimit += FirstNormalTransactionId;
392
393 /*
394 * We'll refuse to continue assigning XIDs in interactive mode once we get
395 * within 3M transactions of data loss. This leaves lots of room for the
396 * DBA to fool around fixing things in a standalone backend, while not
397 * being significant compared to total XID space. (VACUUM requires an XID
398 * if it truncates at wal_level!=minimal. "VACUUM (ANALYZE)", which a DBA
399 * might do by reflex, assigns an XID. Hence, we had better be sure
400 * there's lots of XIDs left...) Also, at default BLCKSZ, this leaves two
401 * completely-idle segments. In the event of edge-case bugs involving
402 * page or segment arithmetic, idle segments render the bugs unreachable
403 * outside of single-user mode.
404 */
405 xidStopLimit = xidWrapLimit - 3000000;
406 if (xidStopLimit < FirstNormalTransactionId)
407 xidStopLimit -= FirstNormalTransactionId;
408
409 /*
410 * We'll start complaining loudly when we get within 40M transactions of
411 * data loss. This is kind of arbitrary, but if you let your gas gauge
412 * get down to 2% of full, would you be looking for the next gas station?
413 * We need to be fairly liberal about this number because there are lots
414 * of scenarios where most transactions are done by automatic clients that
415 * won't pay attention to warnings. (No, we're not gonna make this
416 * configurable. If you know enough to configure it, you know enough to
417 * not get in this kind of trouble in the first place.)
418 */
419 xidWarnLimit = xidWrapLimit - 40000000;
420 if (xidWarnLimit < FirstNormalTransactionId)
421 xidWarnLimit -= FirstNormalTransactionId;
422
423 /*
424 * We'll start trying to force autovacuums when oldest_datfrozenxid gets
425 * to be more than autovacuum_freeze_max_age transactions old.
426 *
427 * Note: guc.c ensures that autovacuum_freeze_max_age is in a sane range,
428 * so that xidVacLimit will be well before xidWarnLimit.
429 *
430 * Note: autovacuum_freeze_max_age is a PGC_POSTMASTER parameter so that
431 * we don't have to worry about dealing with on-the-fly changes in its
432 * value. It doesn't look practical to update shared state from a GUC
433 * assign hook (too many processes would try to execute the hook,
434 * resulting in race conditions as well as crashes of those not connected
435 * to shared memory). Perhaps this can be improved someday. See also
436 * SetMultiXactIdLimit.
437 */
438 xidVacLimit = oldest_datfrozenxid + autovacuum_freeze_max_age;
439 if (xidVacLimit < FirstNormalTransactionId)
440 xidVacLimit += FirstNormalTransactionId;
441
442 /* Grab lock for just long enough to set the new limit values */
443 LWLockAcquire(XidGenLock, LW_EXCLUSIVE);
444 TransamVariables->oldestXid = oldest_datfrozenxid;
445 TransamVariables->xidVacLimit = xidVacLimit;
446 TransamVariables->xidWarnLimit = xidWarnLimit;
447 TransamVariables->xidStopLimit = xidStopLimit;
448 TransamVariables->xidWrapLimit = xidWrapLimit;
449 TransamVariables->oldestXidDB = oldest_datoid;
451 LWLockRelease(XidGenLock);
452
453 /* Log the info */
455 (errmsg_internal("transaction ID wrap limit is %u, limited by database with OID %u",
456 xidWrapLimit, oldest_datoid)));
457
458 /*
459 * If past the autovacuum force point, immediately signal an autovac
460 * request. The reason for this is that autovac only processes one
461 * database per invocation. Once it's finished cleaning up the oldest
462 * database, it'll call here, and we'll signal the postmaster to start
463 * another iteration immediately if there are still any old databases.
464 */
465 if (TransactionIdFollowsOrEquals(curXid, xidVacLimit) &&
468
469 /* Give an immediate warning if past the wrap warn point */
470 if (TransactionIdFollowsOrEquals(curXid, xidWarnLimit) && !InRecovery)
471 {
472 char *oldest_datname;
473
474 /*
475 * We can be called when not inside a transaction, for example during
476 * StartupXLOG(). In such a case we cannot do database access, so we
477 * must just report the oldest DB's OID.
478 *
479 * Note: it's also possible that get_database_name fails and returns
480 * NULL, for example because the database just got dropped. We'll
481 * still warn, even though the warning might now be unnecessary.
482 */
483 if (IsTransactionState())
484 oldest_datname = get_database_name(oldest_datoid);
485 else
486 oldest_datname = NULL;
487
488 if (oldest_datname)
490 (errmsg("database \"%s\" must be vacuumed within %u transactions",
491 oldest_datname,
492 xidWrapLimit - curXid),
493 errhint("To avoid XID assignment failures, execute a database-wide VACUUM in that database.\n"
494 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
495 else
497 (errmsg("database with OID %u must be vacuumed within %u transactions",
498 oldest_datoid,
499 xidWrapLimit - curXid),
500 errhint("To avoid XID assignment failures, execute a database-wide VACUUM in that database.\n"
501 "You might also need to commit or roll back old prepared transactions, or drop stale replication slots.")));
502 }
503}
int autovacuum_freeze_max_age
Definition: autovacuum.c:129
int errmsg_internal(const char *fmt,...)
Definition: elog.c:1161
#define DEBUG1
Definition: elog.h:30
#define MaxTransactionId
Definition: transam.h:35
bool IsTransactionState(void)
Definition: xact.c:387
bool InRecovery
Definition: xlogutils.c:50

References Assert(), autovacuum_freeze_max_age, DEBUG1, ereport, errhint(), errmsg(), errmsg_internal(), FirstNormalTransactionId, get_database_name(), InRecovery, IsTransactionState(), IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaxTransactionId, TransamVariablesData::nextXid, TransamVariablesData::oldestXid, TransamVariablesData::oldestXidDB, PMSIGNAL_START_AUTOVAC_LAUNCHER, SendPostmasterSignal(), TransactionIdFollowsOrEquals(), TransactionIdIsNormal, TransamVariables, WARNING, XidFromFullTransactionId, TransamVariablesData::xidStopLimit, TransamVariablesData::xidVacLimit, TransamVariablesData::xidWarnLimit, and TransamVariablesData::xidWrapLimit.

Referenced by BootStrapXLOG(), StartupXLOG(), vac_truncate_clog(), and xlog_redo().

StopGeneratingPinnedObjectIds()

void StopGeneratingPinnedObjectIds ( void  )

Definition at line 652 of file varsup.c.

653{
655}
#define FirstUnpinnedObjectId
Definition: transam.h:196
static void SetNextObjectId(Oid nextOid)
Definition: varsup.c:623

References FirstUnpinnedObjectId, and SetNextObjectId().

Referenced by pg_stop_making_pinned_objects().

TransactionIdAbortTree()

void TransactionIdAbortTree ( TransactionId  xid,
int  nxids,
TransactionIdxids 
)

Definition at line 270 of file transam.c.

271{
272 TransactionIdSetTreeStatus(xid, nxids, xids,
274}
void TransactionIdSetTreeStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
Definition: clog.c:181
#define TRANSACTION_STATUS_ABORTED
Definition: clog.h:29
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28

References InvalidXLogRecPtr, TRANSACTION_STATUS_ABORTED, and TransactionIdSetTreeStatus().

Referenced by RecordTransactionAbort(), RecordTransactionAbortPrepared(), and xact_redo_abort().

TransactionIdAsyncCommitTree()

void TransactionIdAsyncCommitTree ( TransactionId  xid,
int  nxids,
TransactionIdxids,
XLogRecPtr  lsn 
)

Definition at line 252 of file transam.c.

254{
255 TransactionIdSetTreeStatus(xid, nxids, xids,
257}
#define TRANSACTION_STATUS_COMMITTED
Definition: clog.h:28

References TRANSACTION_STATUS_COMMITTED, and TransactionIdSetTreeStatus().

Referenced by RecordTransactionCommit(), and xact_redo_commit().

TransactionIdCommitTree()

void TransactionIdCommitTree ( TransactionId  xid,
int  nxids,
TransactionIdxids 
)

Definition at line 240 of file transam.c.

References InvalidXLogRecPtr, TRANSACTION_STATUS_COMMITTED, and TransactionIdSetTreeStatus().

Referenced by RecordTransactionCommit(), RecordTransactionCommitPrepared(), and xact_redo_commit().

TransactionIdDidAbort()

bool TransactionIdDidAbort ( TransactionId  transactionId )

Definition at line 188 of file transam.c.

189{
190 XidStatus xidstatus;
191
192 xidstatus = TransactionLogFetch(transactionId);
193
194 /*
195 * If it's marked aborted, it's aborted.
196 */
197 if (xidstatus == TRANSACTION_STATUS_ABORTED)
198 return true;
199
200 /*
201 * If it's marked subcommitted, we have to check the parent recursively.
202 * However, if it's older than TransactionXmin, we can't look at
203 * pg_subtrans; instead assume that the parent crashed without cleaning up
204 * its children.
205 */
206 if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
207 {
208 TransactionId parentXid;
209
210 if (TransactionIdPrecedes(transactionId, TransactionXmin))
211 return true;
212 parentXid = SubTransGetParent(transactionId);
213 if (!TransactionIdIsValid(parentXid))
214 {
215 /* see notes in TransactionIdDidCommit */
216 elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
217 transactionId);
218 return true;
219 }
220 return TransactionIdDidAbort(parentXid);
221 }
222
223 /*
224 * It's not aborted.
225 */
226 return false;
227}
int XidStatus
Definition: clog.h:25
#define TRANSACTION_STATUS_SUB_COMMITTED
Definition: clog.h:30
TransactionId TransactionXmin
Definition: snapmgr.c:158
TransactionId SubTransGetParent(TransactionId xid)
Definition: subtrans.c:121
static XidStatus TransactionLogFetch(TransactionId transactionId)
Definition: transam.c:52
bool TransactionIdDidAbort(TransactionId transactionId)
Definition: transam.c:188

References elog, SubTransGetParent(), TRANSACTION_STATUS_ABORTED, TRANSACTION_STATUS_SUB_COMMITTED, TransactionIdDidAbort(), TransactionIdIsValid, TransactionIdPrecedes(), TransactionLogFetch(), TransactionXmin, and WARNING.

Referenced by DoesMultiXactIdConflict(), heap_lock_updated_tuple_rec(), heap_update(), ProcArrayApplyRecoveryInfo(), ProcessTwoPhaseBuffer(), StandbyAcquireAccessExclusiveLock(), test_lockmode_for_conflict(), TransactionIdDidAbort(), and TransactionIdIsInProgress().

TransactionIdDidCommit()

bool TransactionIdDidCommit ( TransactionId  transactionId )

Definition at line 126 of file transam.c.

127{
128 XidStatus xidstatus;
129
130 xidstatus = TransactionLogFetch(transactionId);
131
132 /*
133 * If it's marked committed, it's committed.
134 */
135 if (xidstatus == TRANSACTION_STATUS_COMMITTED)
136 return true;
137
138 /*
139 * If it's marked subcommitted, we have to check the parent recursively.
140 * However, if it's older than TransactionXmin, we can't look at
141 * pg_subtrans; instead assume that the parent crashed without cleaning up
142 * its children.
143 *
144 * Originally we Assert'ed that the result of SubTransGetParent was not
145 * zero. However with the introduction of prepared transactions, there can
146 * be a window just after database startup where we do not have complete
147 * knowledge in pg_subtrans of the transactions after TransactionXmin.
148 * StartupSUBTRANS() has ensured that any missing information will be
149 * zeroed. Since this case should not happen under normal conditions, it
150 * seems reasonable to emit a WARNING for it.
151 */
152 if (xidstatus == TRANSACTION_STATUS_SUB_COMMITTED)
153 {
154 TransactionId parentXid;
155
156 if (TransactionIdPrecedes(transactionId, TransactionXmin))
157 return false;
158 parentXid = SubTransGetParent(transactionId);
159 if (!TransactionIdIsValid(parentXid))
160 {
161 elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
162 transactionId);
163 return false;
164 }
165 return TransactionIdDidCommit(parentXid);
166 }
167
168 /*
169 * It's not committed.
170 */
171 return false;
172}
bool TransactionIdDidCommit(TransactionId transactionId)
Definition: transam.c:126

References elog, SubTransGetParent(), TRANSACTION_STATUS_COMMITTED, TRANSACTION_STATUS_SUB_COMMITTED, TransactionIdDidCommit(), TransactionIdIsValid, TransactionIdPrecedes(), TransactionLogFetch(), TransactionXmin, and WARNING.

Referenced by asyncQueueProcessPageEntries(), check_safe_enum_use(), compute_new_xmax_infomask(), FreezeMultiXactId(), get_xid_status(), HandleConcurrentAbort(), heap_pre_freeze_checks(), HeapTupleHeaderAdvanceConflictHorizon(), HeapTupleHeaderIsOnlyLocked(), HeapTupleSatisfiesDirty(), HeapTupleSatisfiesHistoricMVCC(), HeapTupleSatisfiesMVCC(), HeapTupleSatisfiesSelf(), HeapTupleSatisfiesToast(), HeapTupleSatisfiesUpdate(), HeapTupleSatisfiesVacuumHorizon(), MultiXactIdExpand(), pg_xact_status(), ProcArrayApplyRecoveryInfo(), ProcessTwoPhaseBuffer(), RecordTransactionAbort(), RecordTransactionAbortPrepared(), ReorderBufferCheckAndTruncateAbortedTXN(), SetupCheckXidLive(), StandbyAcquireAccessExclusiveLock(), test_lockmode_for_conflict(), TransactionIdDidCommit(), UpdateLogicalMappings(), and UpdateXmaxHintBits().

TransactionIdFollows()

bool TransactionIdFollows ( TransactionId  id1,
TransactionId  id2 
)

Definition at line 314 of file transam.c.

315{
316 int32 diff;
317
319 return (id1 > id2);
320
321 diff = (int32) (id1 - id2);
322 return (diff > 0);
323}

References TransactionIdIsNormal.

Referenced by find_inheritance_children_extended(), GetConflictingVirtualXIDs(), GetSerializableTransactionSnapshotInt(), heap_page_is_all_visible(), heap_page_prune_and_freeze(), heap_prune_record_unchanged_lp_normal(), HeapTupleHeaderAdvanceConflictHorizon(), predicatelock_twophase_recover(), ProcessTwoPhaseBuffer(), RecordKnownAssignedTransactionIds(), SerialAdd(), SerialGetMinConflictCommitSeqNo(), SerialSetActiveSerXmin(), SnapBuildInitialSnapshot(), SnapBuildWaitSnapshot(), SubTransSetParent(), update_local_synced_slot(), and xmin_cmp().

TransactionIdFollowsOrEquals()

bool TransactionIdFollowsOrEquals ( TransactionId  id1,
TransactionId  id2 
)

Definition at line 329 of file transam.c.

330{
331 int32 diff;
332
334 return (id1 >= id2);
335
336 diff = (int32) (id1 - id2);
337 return (diff >= 0);
338}

References TransactionIdIsNormal.

Referenced by AdvanceNextFullTransactionIdPastXid(), ForceTransactionIdLimitUpdate(), GetNewTransactionId(), HeapCheckForSerializableConflictOut(), HeapTupleSatisfiesHistoricMVCC(), KnownAssignedXidsAdd(), KnownAssignedXidsGetAndSetXmin(), KnownAssignedXidsRemovePreceding(), SetTransactionIdLimit(), SnapBuildCommitTxn(), SnapBuildPurgeOlderTxn(), SubTransGetParent(), SubTransGetTopmostTransaction(), vacuumLeafPage(), XidInMVCCSnapshot(), and XidIsConcurrent().

TransactionIdGetCommitLSN()

XLogRecPtr TransactionIdGetCommitLSN ( TransactionId  xid )

Definition at line 382 of file transam.c.

383{
384 XLogRecPtr result;
385
386 /*
387 * Currently, all uses of this function are for xids that were just
388 * reported to be committed by TransactionLogFetch, so we expect that
389 * checking TransactionLogFetch's cache will usually succeed and avoid an
390 * extra trip to shared memory.
391 */
393 return cachedCommitLSN;
394
395 /* Special XIDs are always known committed */
396 if (!TransactionIdIsNormal(xid))
397 return InvalidXLogRecPtr;
398
399 /*
400 * Get the transaction status.
401 */
402 (void) TransactionIdGetStatus(xid, &result);
403
404 return result;
405}
XidStatus TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
Definition: clog.c:733
static TransactionId cachedFetchXid
Definition: transam.c:33
static XLogRecPtr cachedCommitLSN
Definition: transam.c:35
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
uint64 XLogRecPtr
Definition: xlogdefs.h:21

References cachedCommitLSN, cachedFetchXid, InvalidXLogRecPtr, TransactionIdEquals, TransactionIdGetStatus(), and TransactionIdIsNormal.

Referenced by SetHintBits().

TransactionIdLatest()

TransactionId TransactionIdLatest ( TransactionId  mainxid,
int  nxids,
const TransactionIdxids 
)

Definition at line 345 of file transam.c.

347{
348 TransactionId result;
349
350 /*
351 * In practice it is highly likely that the xids[] array is sorted, and so
352 * we could save some cycles by just taking the last child XID, but this
353 * probably isn't so performance-critical that it's worth depending on
354 * that assumption. But just to show we're not totally stupid, scan the
355 * array back-to-front to avoid useless assignments.
356 */
357 result = mainxid;
358 while (--nxids >= 0)
359 {
360 if (TransactionIdPrecedes(result, xids[nxids]))
361 result = xids[nxids];
362 }
363 return result;
364}

References TransactionIdPrecedes().

Referenced by FinishPreparedTransaction(), ProcArrayApplyXidAssignment(), RecordTransactionAbort(), RecordTransactionCommit(), xact_redo_abort(), and xact_redo_commit().

TransactionIdOlder()

static TransactionId TransactionIdOlder ( TransactionId  a,
)
inlinestatic

Definition at line 334 of file transam.h.

335{
337 return b;
338
340 return a;
341
343 return a;
344 return b;
345}
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280

References a, b, TransactionIdIsValid, and TransactionIdPrecedes().

Referenced by ComputeXidHorizons(), and GetSnapshotData().

TransactionIdPrecedes()

bool TransactionIdPrecedes ( TransactionId  id1,
TransactionId  id2 
)

Definition at line 280 of file transam.c.

281{
282 /*
283 * If either ID is a permanent XID then we can just do unsigned
284 * comparison. If both are normal, do a modulo-2^32 comparison.
285 */
286 int32 diff;
287
289 return (id1 < id2);
290
291 diff = (int32) (id1 - id2);
292 return (diff < 0);
293}

References TransactionIdIsNormal.

Referenced by AdvanceOldestClogXid(), AdvanceOldestCommitTsXid(), bt_check_every_level(), check_exclusion_or_unique_constraint(), check_tuple_visibility(), CheckTargetForConflictsIn(), CLOGPagePrecedes(), collect_corrupt_items(), CommitTsPagePrecedes(), compute_min_nonremovable_xid(), copy_table_data(), do_start_worker(), ExpireOldKnownAssignedTransactionIds(), ExportSnapshot(), FreezeMultiXactId(), get_relation_info(), GetOldestActiveTransactionId(), GetOldestSafeDecodingTransactionId(), GetRunningTransactionData(), heap_abort_speculative(), heap_page_is_all_visible(), heap_prepare_freeze_tuple(), heap_prune_record_prunable(), heap_prune_record_unchanged_lp_normal(), heap_tuple_should_freeze(), heap_vacuum_eager_scan_setup(), HeapCheckForSerializableConflictOut(), HeapTupleHeaderAdvanceConflictHorizon(), HeapTupleSatisfiesHistoricMVCC(), HeapTupleSatisfiesVacuum(), IsIndexUsableForFindingDeletedTuple(), KnownAssignedXidsAdd(), KnownAssignedXidsGetAndSetXmin(), KnownAssignedXidsSearch(), logical_rewrite_heap_tuple(), MaintainLatestCompletedXid(), MaintainLatestCompletedXidRecovery(), multixact_redo(), PhysicalReplicationSlotNewXmin(), PrescanPreparedTransactions(), ProcArrayApplyRecoveryInfo(), ProcArrayApplyXidAssignment(), ProcessStandbyHSFeedbackMessage(), ProcessStandbyPSRequestMessage(), RecordKnownAssignedTransactionIds(), relation_needs_vacanalyze(), ReorderBufferAbortOld(), ReplicationSlotsComputeRequiredXmin(), rewrite_heap_tuple(), SerialAdd(), SerialGetMinConflictCommitSeqNo(), SerialPagePrecedesLogically(), SerialSetActiveSerXmin(), SetCommitTsLimit(), SetNewSxactGlobalXmin(), SnapBuildCommitTxn(), SnapBuildProcessChange(), SnapBuildRestore(), SnapshotResetXmin(), StandbyReleaseOldLocks(), SubTransGetTopmostTransaction(), SubTransPagePrecedes(), TransactionIdDidAbort(), TransactionIdDidCommit(), TransactionIdGetCommitTsData(), TransactionIdIsCurrentTransactionId(), TransactionIdIsInProgress(), TransactionIdLatest(), TransactionIdOlder(), TransactionTreeSetCommitTsData(), tuple_all_visible(), TwoPhaseGetOldestXidInCommit(), update_local_synced_slot(), vac_truncate_clog(), vac_update_datfrozenxid(), vac_update_relstats(), vacuum_get_cutoffs(), vacuum_xid_failsafe_check(), vacuumRedirectAndPlaceholder(), XidInMVCCSnapshot(), XidIsConcurrent(), xidLogicalComparator(), xlog_redo(), and xmin_cmp().

TransactionIdPrecedesOrEquals()

bool TransactionIdPrecedesOrEquals ( TransactionId  id1,
TransactionId  id2 
)

Definition at line 299 of file transam.c.

300{
301 int32 diff;
302
304 return (id1 <= id2);
305
306 diff = (int32) (id1 - id2);
307 return (diff <= 0);
308}

References TransactionIdIsNormal.

Referenced by ClearOldPredicateLocks(), ComputeXidHorizons(), DetermineSlotInvalidationCause(), FullTransactionIdFromAllowableAt(), get_candidate_xid(), GetCurrentVirtualXIDs(), GetSnapshotData(), GetSnapshotDataReuse(), heap_prepare_freeze_tuple(), heap_tuple_should_freeze(), heap_vacuum_rel(), KnownAssignedXidsAdd(), LogicalIncreaseXminForSlot(), ProcArrayInstallImportedXmin(), ProcArrayInstallRestoredXmin(), SnapBuildFindSnapshot(), TransactionIdInRecentPast(), TransactionIdIsInProgress(), update_conflict_slot_xmin(), and vacuum_get_cutoffs().

TransactionIdRetreatedBy()

static TransactionId TransactionIdRetreatedBy ( TransactionId  xid,
uint32  amount 
)
inlinestatic

Definition at line 322 of file transam.h.

323{
324 xid -= amount;
325
326 while (xid < FirstNormalTransactionId)
327 xid--;
328
329 return xid;
330}

References FirstNormalTransactionId.

TransactionStartedDuringRecovery()

bool TransactionStartedDuringRecovery ( void  )

Definition at line 1042 of file xact.c.

1043{
1045}
bool startedInRecovery
Definition: xact.c:212
static TransactionState CurrentTransactionState
Definition: xact.c:260

References CurrentTransactionState, and TransactionStateData::startedInRecovery.

Referenced by RelationGetIndexScan().

VarsupShmemInit()

void VarsupShmemInit ( void  )

Definition at line 47 of file varsup.c.

48{
49 bool found;
50
51 /* Initialize our shared state struct */
52 TransamVariables = ShmemInitStruct("TransamVariables",
54 &found);
56 {
57 Assert(!found);
58 memset(TransamVariables, 0, sizeof(TransamVariablesData));
59 }
60 else
61 Assert(found);
62}
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:387

References Assert(), IsUnderPostmaster, ShmemInitStruct(), and TransamVariables.

Referenced by CreateOrAttachShmemStructs().

VarsupShmemSize()

Size VarsupShmemSize ( void  )

Definition at line 41 of file varsup.c.

42{
43 return sizeof(TransamVariablesData);
44}
struct TransamVariablesData TransamVariablesData

Referenced by CalculateShmemSize().

Variable Documentation

TransamVariables

PGDLLIMPORT TransamVariablesData* TransamVariables
extern

Definition at line 34 of file varsup.c.

Referenced by ActivateCommitTs(), AdvanceNextFullTransactionIdPastXid(), AdvanceOldestClogXid(), AdvanceOldestCommitTsXid(), BootStrapXLOG(), ComputeXidHorizons(), consume_xids_shortcut(), CreateCheckPoint(), DeactivateCommitTs(), ExpireAllKnownAssignedTransactionIds(), ExpireOldKnownAssignedTransactionIds(), ExpireTreeKnownAssignedTransactionIds(), ForceTransactionIdLimitUpdate(), get_xid_status(), GetNewObjectId(), GetNewTransactionId(), GetOldestActiveTransactionId(), GetOldestSafeDecodingTransactionId(), GetRunningTransactionData(), GetSnapshotData(), GetSnapshotDataReuse(), GetStrictOldestNonRemovableTransactionId(), MaintainLatestCompletedXid(), MaintainLatestCompletedXidRecovery(), PrepareRedoAdd(), PrepareRedoRemove(), PrescanPreparedTransactions(), ProcArrayApplyRecoveryInfo(), ProcArrayClearTransaction(), ProcArrayEndTransactionInternal(), ProcArrayRemove(), ProcArrayShmemInit(), ProcessTwoPhaseBuffer(), ReadNextFullTransactionId(), ReleasePredicateLocks(), SetCommitTsLimit(), SetNextObjectId(), SetTransactionIdLimit(), StartupCLOG(), StartupSUBTRANS(), StartupXLOG(), TransactionIdGetCommitTsData(), TransactionIdInRecentPast(), TransactionIdIsInProgress(), TransactionTreeSetCommitTsData(), TrimCLOG(), update_cached_xid_range(), VarsupShmemInit(), XidCacheRemoveRunningXids(), xlog_redo(), and XLogRecGetFullXid().

AltStyle によって変換されたページ (->オリジナル) /