PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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
 
struct  TransamVariablesData
 

Macros

#define InvalidTransactionId   ((TransactionId) 0)
 
#define BootstrapTransactionId   ((TransactionId) 1)
 
#define FrozenTransactionId   ((TransactionId) 2)
 
#define FirstNormalTransactionId   ((TransactionId) 3)
 
#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 FullTransactionIdIsValid(x)   TransactionIdIsValid(XidFromFullTransactionId(x))
 
#define InvalidFullTransactionId   FullTransactionIdFromEpochAndXid(0, InvalidTransactionId)
 
#define FirstNormalFullTransactionId   FullTransactionIdFromEpochAndXid(0, FirstNormalTransactionId)
 
#define FullTransactionIdIsNormal(x)   FullTransactionIdFollowsOrEquals(x, FirstNormalFullTransactionId)
 
#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

typedef struct FullTransactionId FullTransactionId
 
typedef struct TransamVariablesData TransamVariablesData
 

Functions

static FullTransactionId FullTransactionIdFromEpochAndXid (uint32 epoch, TransactionId xid)
 
static FullTransactionId FullTransactionIdFromU64 (uint64 value)
 
static void FullTransactionIdRetreat (FullTransactionId *dest)
 
static void FullTransactionIdAdvance (FullTransactionId *dest)
 
static bool TransactionIdPrecedes (TransactionId id1, TransactionId id2)
 
static bool TransactionIdPrecedesOrEquals (TransactionId id1, TransactionId id2)
 
static bool TransactionIdFollows (TransactionId id1, TransactionId id2)
 
static bool TransactionIdFollowsOrEquals (TransactionId id1, TransactionId id2)
 
bool TransactionStartedDuringRecovery (void)
 
bool TransactionIdDidCommit (TransactionId transactionId)
 
bool TransactionIdDidAbort (TransactionId transactionId)
 
void TransactionIdCommitTree (TransactionId xid, int nxids, TransactionId *xids)
 
void TransactionIdAsyncCommitTree (TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn)
 
void TransactionIdAbortTree (TransactionId xid, int nxids, TransactionId *xids)
 
TransactionId TransactionIdLatest (TransactionId mainxid, int nxids, const TransactionId *xids)
 
XLogRecPtr TransactionIdGetCommitLSN (TransactionId xid)
 
FullTransactionId GetNewTransactionId (bool isSubXact)
 
void AdvanceNextFullTransactionIdPastXid (TransactionId xid)
 
FullTransactionId ReadNextFullTransactionId (void)
 
void SetTransactionIdLimit (TransactionId oldest_datfrozenxid, Oid oldest_datoid)
 
void AdvanceOldestClogXid (TransactionId oldest_datfrozenxid)
 
bool ForceTransactionIdLimitUpdate (void)
 
Oid GetNewObjectId (void)
 
void StopGeneratingPinnedObjectIds (void)
 
static TransactionId ReadNextTransactionId (void)
 
static TransactionId TransactionIdRetreatedBy (TransactionId xid, uint32 amount)
 
static TransactionId TransactionIdOlder (TransactionId a, TransactionId b)
 
static TransactionId NormalTransactionIdOlder (TransactionId a, TransactionId b)
 
static FullTransactionId FullTransactionIdNewer (FullTransactionId a, FullTransactionId b)
 
static FullTransactionId FullTransactionIdFromAllowableAt (FullTransactionId nextFullXid, TransactionId xid)
 

Variables

PGDLLIMPORT TransamVariablesDataTransamVariables
 

Macro Definition Documentation

◆ AssertTransactionIdInAllowableRange

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

Definition at line 361 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:944
int32_t int32
Definition c.h:620
static int fb(int x)
#define TransactionIdIsNormal(xid)
Definition transam.h:42

Definition at line 152 of file transam.h.

209{
210 /*
211 * These fields are protected by OidGenLock.
212 */
213 Oid nextOid; /* next OID to assign */
214 uint32 oidCount; /* OIDs available before must do XLOG work */
215
216 /*
217 * These fields are protected by XidGenLock.
218 */
219 FullTransactionId nextXid; /* next XID to assign */
220
221 TransactionId oldestXid; /* cluster-wide minimum datfrozenxid */
222 TransactionId xidVacLimit; /* start forcing autovacuums here */
223 TransactionId xidWarnLimit; /* start complaining here */
224 TransactionId xidStopLimit; /* refuse to advance nextXid beyond here */
225 TransactionId xidWrapLimit; /* where the world ends */
226 Oid oldestXidDB; /* database with minimum datfrozenxid */
227
228 /*
229 * These fields are protected by CommitTsLock
230 */
231 TransactionId oldestCommitTsXid;
232 TransactionId newestCommitTsXid;
233
234 /*
235 * These fields are protected by ProcArrayLock.
236 */
237 FullTransactionId latestCompletedXid; /* newest full XID that has
238 * committed or aborted */
239
240 /*
241 * Number of top-level transactions with xids (i.e. which may have
242 * modified the database) that completed in some form since the start of
243 * the server. This currently is solely used to check whether
244 * GetSnapshotData() needs to recompute the contents of the snapshot, or
245 * not. There are likely other users of this. Always above 1.
246 */
247 uint64 xactCompletionCount;
248
249 /*
250 * These fields are protected by XactTruncationLock
251 */
252 TransactionId oldestClogXid; /* oldest it's safe to look up in clog */
253
255
256
257
258/*
259 * TransactionIdPrecedes --- is id1 logically < id2?
260 */
261static inline bool
263{
264 /*
265 * If either ID is a permanent XID then we can just do unsigned
266 * comparison. If both are normal, do a modulo-2^32 comparison.
267 */
268 int32 diff;
269
271 return (id1 < id2);
272
273 diff = (int32) (id1 - id2);
274 return (diff < 0);
275}
276
277/*
278 * TransactionIdPrecedesOrEquals --- is id1 logically <= id2?
279 */
280static inline bool
282{
283 int32 diff;
284
286 return (id1 <= id2);
287
288 diff = (int32) (id1 - id2);
289 return (diff <= 0);
290}
291
292/*
293 * TransactionIdFollows --- is id1 logically > id2?
294 */
295static inline bool
297{
298 int32 diff;
299
301 return (id1 > id2);
302
303 diff = (int32) (id1 - id2);
304 return (diff > 0);
305}
306
307/*
308 * TransactionIdFollowsOrEquals --- is id1 logically >= id2?
309 */
310static inline bool
312{
313 int32 diff;
314
316 return (id1 >= id2);
317
318 diff = (int32) (id1 - id2);
319 return (diff >= 0);
320}
321
322
323/* ----------------
324 * extern declarations
325 * ----------------
326 */
327
328/* in transam/xact.c */
329extern bool TransactionStartedDuringRecovery(void);
330
331/* in transam/varsup.c */
333
334/*
335 * prototypes for functions in transam/transam.c
336 */
339extern void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids);
341extern void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId *xids);
343 int nxids, const TransactionId *xids);
345
346/* in transam/varsup.c */
353extern bool ForceTransactionIdLimitUpdate(void);
354extern Oid GetNewObjectId(void);
355extern void StopGeneratingPinnedObjectIds(void);
356
357#ifdef USE_ASSERT_CHECKING
359#else
360#define AssertTransactionIdInAllowableRange(xid) ((void)true)
361#endif
362
363/*
364 * Some frontend programs include this header. For compilers that emit static
365 * inline functions even when they're unused, that leads to unsatisfied
366 * external references; hence hide them with #ifndef FRONTEND.
367 */
368#ifndef FRONTEND
369
370/*
371 * For callers that just need the XID part of the next transaction ID.
372 */
373static inline TransactionId
375{
377}
378
379/* return transaction ID backed up by amount, handling wraparound correctly */
380static inline TransactionId
382{
383 xid -= amount;
384
385 while (xid < FirstNormalTransactionId)
386 xid--;
387
388 return xid;
389}
390
391/* return the older of the two IDs */
392static inline TransactionId
394{
396 return b;
397
399 return a;
400
402 return a;
403 return b;
404}
405
406/* return the older of the two IDs, assuming they're both normal */
407static inline TransactionId
409{
413 return a;
414 return b;
415}
416
417/* return the newer of the two IDs */
418static inline FullTransactionId
420{
422 return b;
423
425 return a;
426
428 return a;
429 return b;
430}
431
432/*
433 * Compute FullTransactionId for the given TransactionId, assuming xid was
434 * between [oldestXid, nextXid] at the time when TransamVariables->nextXid was
435 * nextFullXid. When adding calls, evaluate what prevents xid from preceding
436 * oldestXid if SetTransactionIdLimit() runs between the collection of xid and
437 * the collection of nextFullXid.
438 */
439static inline FullTransactionId
441 TransactionId xid)
442{
444
445 /* Special transaction ID. */
446 if (!TransactionIdIsNormal(xid))
448
451
452 /*
453 * The 64 bit result must be <= nextFullXid, since nextFullXid hadn't been
454 * issued yet when xid was in the past. The xid must therefore be from
455 * the epoch of nextFullXid or the epoch before. We know this because we
456 * must remove (by freezing) an XID before assigning the XID half an epoch
457 * ahead of it.
458 *
459 * The unlikely() branch hint is dubious. It's perfect for the first 2^32
460 * XIDs of a cluster's life. Right at 2^32 XIDs, misprediction shoots to
461 * 100%, then improves until perfection returns 2^31 XIDs later. Since
462 * current callers pass relatively-recent XIDs, expect >90% prediction
463 * accuracy overall. This favors average latency over tail latency.
464 */
467 {
468 Assert(epoch != 0);
469 epoch--;
470 }
471
473}
474
475#endif /* FRONTEND */
476
477#endif /* TRANSAM_H */
#define PGDLLIMPORT
Definition c.h:1421
#define Assert(condition)
Definition c.h:943
uint64_t uint64
Definition c.h:625
#define unlikely(x)
Definition c.h:438
uint32_t uint32
Definition c.h:624
uint32 TransactionId
Definition c.h:736
int b
Definition isn.c:74
int a
Definition isn.c:73
unsigned int Oid
void TransactionIdAsyncCommitTree(TransactionId xid, int nxids, TransactionId *xids, XLogRecPtr lsn)
Definition transam.c:252
static bool TransactionIdFollows(TransactionId id1, TransactionId id2)
Definition transam.h:297
PGDLLIMPORT TransamVariablesData * TransamVariables
Definition varsup.c:37
FullTransactionId ReadNextFullTransactionId(void)
Definition varsup.c:283
void AdvanceNextFullTransactionIdPastXid(TransactionId xid)
Definition varsup.c:299
Oid GetNewObjectId(void)
Definition varsup.c:554
static TransactionId ReadNextTransactionId(void)
Definition transam.h:375
static TransactionId TransactionIdRetreatedBy(TransactionId xid, uint32 amount)
Definition transam.h:382
static FullTransactionId FullTransactionIdNewer(FullTransactionId a, FullTransactionId b)
Definition transam.h:420
TransactionId TransactionIdLatest(TransactionId mainxid, int nxids, const TransactionId *xids)
Definition transam.c:281
static FullTransactionId FullTransactionIdFromAllowableAt(FullTransactionId nextFullXid, TransactionId xid)
Definition transam.h:441
#define EpochFromFullTransactionId(x)
Definition transam.h:47
static bool TransactionIdPrecedesOrEquals(TransactionId id1, TransactionId id2)
Definition transam.h:282
bool TransactionStartedDuringRecovery(void)
Definition xact.c:1044
void SetTransactionIdLimit(TransactionId oldest_datfrozenxid, Oid oldest_datoid)
Definition varsup.c:367
static bool TransactionIdFollowsOrEquals(TransactionId id1, TransactionId id2)
Definition transam.h:312
#define AssertTransactionIdInAllowableRange(xid)
Definition transam.h:361
bool TransactionIdDidCommit(TransactionId transactionId)
Definition transam.c:126
void TransactionIdCommitTree(TransactionId xid, int nxids, TransactionId *xids)
Definition transam.c:240
static TransactionId NormalTransactionIdOlder(TransactionId a, TransactionId b)
Definition transam.h:409
FullTransactionId GetNewTransactionId(bool isSubXact)
Definition varsup.c:68
#define NormalTransactionIdPrecedes(id1, id2)
Definition transam.h:147
void StopGeneratingPinnedObjectIds(void)
Definition varsup.c:651
void TransactionIdAbortTree(TransactionId xid, int nxids, TransactionId *xids)
Definition transam.c:270
bool ForceTransactionIdLimitUpdate(void)
Definition varsup.c:516
#define FullTransactionIdFollows(a, b)
Definition transam.h:53
#define XidFromFullTransactionId(x)
Definition transam.h:48
bool TransactionIdDidAbort(TransactionId transactionId)
Definition transam.c:188
XLogRecPtr TransactionIdGetCommitLSN(TransactionId xid)
Definition transam.c:318
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
Definition varsup.c:350
#define FirstNormalTransactionId
Definition transam.h:34
#define TransactionIdIsValid(xid)
Definition transam.h:41
static FullTransactionId FullTransactionIdFromEpochAndXid(uint32 epoch, TransactionId xid)
Definition transam.h:71
#define FullTransactionIdIsValid(x)
Definition transam.h:55
static TransactionId TransactionIdOlder(TransactionId a, TransactionId b)
Definition transam.h:394
static bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition transam.h:263
static const unsigned __int64 epoch
uint64 XLogRecPtr
Definition xlogdefs.h:21

◆ NormalTransactionIdPrecedes

#define NormalTransactionIdPrecedes (   id1,
  id2 
)
Value:

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)

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)--; \
} while ((dest) < FirstNormalTransactionId)

Definition at line 141 of file transam.h.

142 { \
143 (dest)--; \
144 } while ((dest) < FirstNormalTransactionId)

◆ 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)
extern

Definition at line 299 of file varsup.c.

300{
302 TransactionId next_xid;
304
305 /*
306 * It is safe to read nextXid without a lock, because this is only called
307 * from the startup process or single-process mode, meaning that no other
308 * process can modify it.
309 */
311
312 /* Fast return if this isn't an xid high enough to move the needle. */
314 if (!TransactionIdFollowsOrEquals(xid, next_xid))
315 return;
316
317 /*
318 * Compute the FullTransactionId that comes after the given xid. To do
319 * this, we preserve the existing epoch, but detect when we've wrapped
320 * into a new epoch. This is necessary because WAL records and 2PC state
321 * currently contain 32 bit xids. The wrap logic is safe in those cases
322 * because the span of active xids cannot exceed one epoch at any given
323 * point in the WAL stream.
324 */
327 if (unlikely(xid < next_xid))
328 ++epoch;
330
331 /*
332 * We still need to take a lock to modify the value when there are
333 * concurrent readers.
334 */
338}
bool IsUnderPostmaster
Definition globals.c:120
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
#define AmStartupProcess()
Definition miscadmin.h:393
FullTransactionId nextXid
Definition transam.h:220
#define TransactionIdAdvance(dest)
Definition transam.h:91
TransamVariablesData * TransamVariables
Definition varsup.c:37

References AmStartupProcess, Assert, epoch, EpochFromFullTransactionId, fb(), 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()

◆ ForceTransactionIdLimitUpdate()

bool ForceTransactionIdLimitUpdate ( void  )
extern

Definition at line 516 of file varsup.c.

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

References fb(), 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 ( FullTransactionId dest)
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 FirstNormalFullTransactionId, FirstNormalTransactionId, FullTransactionIdPrecedes, and XidFromFullTransactionId.

Referenced by GetNewTransactionId(), and GetSnapshotData().

◆ FullTransactionIdFromAllowableAt()

static FullTransactionId FullTransactionIdFromAllowableAt ( FullTransactionId  nextFullXid,
TransactionId  xid 
)
inlinestatic

Definition at line 441 of file transam.h.

443{
445
446 /* Special transaction ID. */
447 if (!TransactionIdIsNormal(xid))
449
452
453 /*
454 * The 64 bit result must be <= nextFullXid, since nextFullXid hadn't been
455 * issued yet when xid was in the past. The xid must therefore be from
456 * the epoch of nextFullXid or the epoch before. We know this because we
457 * must remove (by freezing) an XID before assigning the XID half an epoch
458 * ahead of it.
459 *
460 * The unlikely() branch hint is dubious. It's perfect for the first 2^32
461 * XIDs of a cluster's life. Right at 2^32 XIDs, misprediction shoots to
462 * 100%, then improves until perfection returns 2^31 XIDs later. Since
463 * current callers pass relatively-recent XIDs, expect >90% prediction
464 * accuracy overall. This favors average latency over tail latency.
465 */
468 {
469 Assert(epoch != 0);
470 epoch--;
471 }
472
474}

References Assert, epoch, EpochFromFullTransactionId, fb(), 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

◆ FullTransactionIdFromU64()

static FullTransactionId FullTransactionIdFromU64 ( uint64  value)
inlinestatic

◆ FullTransactionIdNewer()

static FullTransactionId FullTransactionIdNewer ( FullTransactionId  a,
FullTransactionId  b 
)
inlinestatic

Definition at line 420 of file transam.h.

421{
423 return b;
424
426 return a;
427
429 return a;
430 return b;
431}

References a, b, FullTransactionIdFollows, and FullTransactionIdIsValid.

Referenced by GetSnapshotData(), and GlobalVisUpdateApply().

◆ FullTransactionIdRetreat()

static void FullTransactionIdRetreat ( FullTransactionId dest)
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 FirstNormalFullTransactionId, FirstNormalTransactionId, FullTransactionIdPrecedes, and XidFromFullTransactionId.

Referenced by ExpireAllKnownAssignedTransactionIds(), and StartupXLOG().

◆ GetNewObjectId()

Oid GetNewObjectId ( void  )
extern

Definition at line 554 of file varsup.c.

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

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

Referenced by GetNewOidWithIndex(), and GetNewRelFileNumber().

◆ GetNewTransactionId()

FullTransactionId GetNewTransactionId ( bool  isSubXact)
extern

Definition at line 68 of file varsup.c.

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

References Assert, BootstrapTransactionId, XidCacheStatus::count, elog, ereport, errcode(), errdetail(), errhint(), errmsg, ERROR, ExtendCLOG(), ExtendCommitTs(), ExtendSUBTRANS(), fb(), FullTransactionIdAdvance(), FullTransactionIdFromEpochAndXid(), get_database_name(), IsBootstrapProcessingMode, IsInParallelMode(), IsUnderPostmaster, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MaxTransactionId, 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,
TransactionId  b 
)
inlinestatic

Definition at line 409 of file transam.h.

410{
414 return a;
415 return b;
416}

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

◆ ReadNextFullTransactionId()

◆ ReadNextTransactionId()

◆ SetTransactionIdLimit()

void SetTransactionIdLimit ( TransactionId  oldest_datfrozenxid,
Oid  oldest_datoid 
)
extern

Definition at line 367 of file varsup.c.

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

References Assert, autovacuum_freeze_max_age, DEBUG1, ereport, errdetail(), errhint(), errmsg, errmsg_internal(), fb(), 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  )
extern

Definition at line 651 of file varsup.c.

652{
654}
#define FirstUnpinnedObjectId
Definition transam.h:196
static void SetNextObjectId(Oid nextOid)
Definition varsup.c:622

References FirstUnpinnedObjectId, and SetNextObjectId().

Referenced by pg_stop_making_pinned_objects().

◆ TransactionIdAbortTree()

void TransactionIdAbortTree ( TransactionId  xid,
int  nxids,
TransactionId xids 
)
extern

Definition at line 270 of file transam.c.

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

References fb(), InvalidXLogRecPtr, TRANSACTION_STATUS_ABORTED, and TransactionIdSetTreeStatus().

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

◆ TransactionIdAsyncCommitTree()

void TransactionIdAsyncCommitTree ( TransactionId  xid,
int  nxids,
TransactionId xids,
XLogRecPtr  lsn 
)
extern

Definition at line 252 of file transam.c.

254{
257}
#define TRANSACTION_STATUS_COMMITTED
Definition clog.h:28

References fb(), TRANSACTION_STATUS_COMMITTED, and TransactionIdSetTreeStatus().

Referenced by RecordTransactionCommit(), and xact_redo_commit().

◆ TransactionIdCommitTree()

void TransactionIdCommitTree ( TransactionId  xid,
int  nxids,
TransactionId xids 
)
extern

◆ TransactionIdDidAbort()

bool TransactionIdDidAbort ( TransactionId  transactionId)
extern

Definition at line 188 of file transam.c.

189{
191
193
194 /*
195 * If it's marked aborted, it's aborted.
196 */
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 */
207 {
209
211 return true;
214 {
215 /* see notes in TransactionIdDidCommit */
216 elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
218 return true;
219 }
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:159
TransactionId SubTransGetParent(TransactionId xid)
Definition subtrans.c:129
static XidStatus TransactionLogFetch(TransactionId transactionId)
Definition transam.c:52
bool TransactionIdDidAbort(TransactionId transactionId)
Definition transam.c:188

References elog, fb(), 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)
extern

Definition at line 126 of file transam.c.

127{
129
131
132 /*
133 * If it's marked committed, it's committed.
134 */
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 */
153 {
155
157 return false;
160 {
161 elog(WARNING, "no pg_subtrans entry for subcommitted XID %u",
163 return false;
164 }
166 }
167
168 /*
169 * It's not committed.
170 */
171 return false;
172}
bool TransactionIdDidCommit(TransactionId transactionId)
Definition transam.c:126

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

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

◆ TransactionIdFollows()

◆ TransactionIdFollowsOrEquals()

◆ TransactionIdGetCommitLSN()

XLogRecPtr TransactionIdGetCommitLSN ( TransactionId  xid)
extern

Definition at line 318 of file transam.c.

319{
321
322 /*
323 * Currently, all uses of this function are for xids that were just
324 * reported to be committed by TransactionLogFetch, so we expect that
325 * checking TransactionLogFetch's cache will usually succeed and avoid an
326 * extra trip to shared memory.
327 */
329 return cachedCommitLSN;
330
331 /* Special XIDs are always known committed */
332 if (!TransactionIdIsNormal(xid))
333 return InvalidXLogRecPtr;
334
335 /*
336 * Get the transaction status.
337 */
339
340 return result;
341}
XidStatus TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
Definition clog.c:744
static TransactionId cachedFetchXid
Definition transam.c:33
static XLogRecPtr cachedCommitLSN
Definition transam.c:35
#define TransactionIdEquals(id1, id2)
Definition transam.h:43

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

Referenced by SetHintBitsExt().

◆ TransactionIdLatest()

TransactionId TransactionIdLatest ( TransactionId  mainxid,
int  nxids,
const TransactionId xids 
)
extern

Definition at line 281 of file transam.c.

283{
285
286 /*
287 * In practice it is highly likely that the xids[] array is sorted, and so
288 * we could save some cycles by just taking the last child XID, but this
289 * probably isn't so performance-critical that it's worth depending on
290 * that assumption. But just to show we're not totally stupid, scan the
291 * array back-to-front to avoid useless assignments.
292 */
293 result = mainxid;
294 while (--nxids >= 0)
295 {
297 result = xids[nxids];
298 }
299 return result;
300}

References fb(), result, and TransactionIdPrecedes().

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

◆ TransactionIdOlder()

static TransactionId TransactionIdOlder ( TransactionId  a,
TransactionId  b 
)
inlinestatic

Definition at line 394 of file transam.h.

395{
397 return b;
398
400 return a;
401
403 return a;
404 return b;
405}

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

Referenced by ComputeXidHorizons(), and GetSnapshotData().

◆ TransactionIdPrecedes()

static bool TransactionIdPrecedes ( TransactionId  id1,
TransactionId  id2 
)
inlinestatic

Definition at line 263 of file transam.h.

264{
265 /*
266 * If either ID is a permanent XID then we can just do unsigned
267 * comparison. If both are normal, do a modulo-2^32 comparison.
268 */
269 int32 diff;
270
272 return (id1 < id2);
273
274 diff = (int32) (id1 - id2);
275 return (diff < 0);
276}

References fb(), and TransactionIdIsNormal.

Referenced by AdvanceOldestClogXid(), AdvanceOldestCommitTsXid(), AsyncNotifyFreezeXids(), 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_will_freeze(), heap_prepare_freeze_tuple(), heap_prune_record_prunable(), 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(), WaitForAllTransactionsToFinish(), XidInMVCCSnapshot(), XidIsConcurrent(), xidLogicalComparator(), xlog_redo(), and xmin_cmp().

◆ TransactionIdPrecedesOrEquals()

◆ TransactionIdRetreatedBy()

static TransactionId TransactionIdRetreatedBy ( TransactionId  xid,
uint32  amount 
)
inlinestatic

Definition at line 382 of file transam.h.

383{
384 xid -= amount;
385
386 while (xid < FirstNormalTransactionId)
387 xid--;
388
389 return xid;
390}

References fb(), and FirstNormalTransactionId.

◆ TransactionStartedDuringRecovery()

bool TransactionStartedDuringRecovery ( void  )
extern

Definition at line 1044 of file xact.c.

1045{
1047}
bool startedInRecovery
Definition xact.c:214
static TransactionState CurrentTransactionState
Definition xact.c:262

References CurrentTransactionState, and TransactionStateData::startedInRecovery.

Referenced by RelationGetIndexScan().

Variable Documentation

◆ TransamVariables