PostgreSQL Source Code  git master
commit_ts.h File Reference
#include "access/xlog.h"
#include "datatype/timestamp.h"
#include "replication/origin.h"
#include "storage/sync.h"
Include dependency graph for commit_ts.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xl_commit_ts_set
 
struct  xl_commit_ts_truncate
 

Macros

#define COMMIT_TS_ZEROPAGE   0x00
 
#define COMMIT_TS_TRUNCATE   0x10
 
#define SizeOfCommitTsSet
 
#define SizeOfCommitTsTruncate
 

Typedefs

typedef struct xl_commit_ts_set xl_commit_ts_set
 
typedef struct xl_commit_ts_truncate xl_commit_ts_truncate
 

Functions

void TransactionTreeSetCommitTsData (TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz timestamp, RepOriginId nodeid)
 
bool TransactionIdGetCommitTsData (TransactionId xid, TimestampTz *ts, RepOriginId *nodeid)
 
TransactionId GetLatestCommitTsData (TimestampTz *ts, RepOriginId *nodeid)
 
Size CommitTsShmemBuffers (void)
 
Size CommitTsShmemSize (void)
 
void CommitTsShmemInit (void)
 
void BootStrapCommitTs (void)
 
void StartupCommitTs (void)
 
void CommitTsParameterChange (bool newvalue, bool oldvalue)
 
void CompleteCommitTsInitialization (void)
 
void CheckPointCommitTs (void)
 
void ExtendCommitTs (TransactionId newestXact)
 
void TruncateCommitTs (TransactionId oldestXact)
 
void SetCommitTsLimit (TransactionId oldestXact, TransactionId newestXact)
 
void AdvanceOldestCommitTsXid (TransactionId oldestXact)
 
int committssyncfiletag (const FileTag *ftag, char *path)
 
void commit_ts_redo (XLogReaderState *record)
 
void commit_ts_desc (StringInfo buf, XLogReaderState *record)
 
const char * commit_ts_identify (uint8 info)
 

Variables

PGDLLIMPORT bool track_commit_timestamp
 

Macro Definition Documentation

◆ COMMIT_TS_TRUNCATE

#define COMMIT_TS_TRUNCATE   0x10

Definition at line 48 of file commit_ts.h.

◆ COMMIT_TS_ZEROPAGE

#define COMMIT_TS_ZEROPAGE   0x00

Definition at line 47 of file commit_ts.h.

◆ SizeOfCommitTsSet

#define SizeOfCommitTsSet
Value:
(offsetof(xl_commit_ts_set, mainxid) + \
sizeof(TransactionId))
#define offsetof(type, field)
Definition: c.h:727
uint32 TransactionId
Definition: c.h:587

Definition at line 58 of file commit_ts.h.

◆ SizeOfCommitTsTruncate

#define SizeOfCommitTsTruncate
Value:

Definition at line 67 of file commit_ts.h.

Typedef Documentation

◆ xl_commit_ts_set

◆ xl_commit_ts_truncate

Function Documentation

◆ AdvanceOldestCommitTsXid()

void AdvanceOldestCommitTsXid ( TransactionId  oldestXact)

Definition at line 908 of file commit_ts.c.

909 {
910  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
914  LWLockRelease(CommitTsLock);
915 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1196
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1800
@ LW_EXCLUSIVE
Definition: lwlock.h:104
TransactionId oldestCommitTsXid
Definition: transam.h:232
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
#define InvalidTransactionId
Definition: transam.h:31
VariableCache ShmemVariableCache
Definition: varsup.c:34

References InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::oldestCommitTsXid, ShmemVariableCache, and TransactionIdPrecedes().

Referenced by commit_ts_redo(), and vac_truncate_clog().

◆ BootStrapCommitTs()

void BootStrapCommitTs ( void  )

Definition at line 574 of file commit_ts.c.

575 {
576  /*
577  * Nothing to do here at present, unlike most other SLRU modules; segments
578  * are created when the server is started with this module enabled. See
579  * ActivateCommitTs.
580  */
581 }

Referenced by BootStrapXLOG().

◆ CheckPointCommitTs()

void CheckPointCommitTs ( void  )

Definition at line 795 of file commit_ts.c.

796 {
797  /*
798  * Write dirty CommitTs pages to disk. This may result in sync requests
799  * queued for later handling by ProcessSyncRequests(), as part of the
800  * checkpoint.
801  */
803 }
#define CommitTsCtl
Definition: commit_ts.c:81
void SimpleLruWriteAll(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1156

References CommitTsCtl, and SimpleLruWriteAll().

Referenced by CheckPointGuts().

◆ commit_ts_desc()

void commit_ts_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 22 of file committsdesc.c.

23 {
24  char *rec = XLogRecGetData(record);
25  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
26 
27  if (info == COMMIT_TS_ZEROPAGE)
28  {
29  int pageno;
30 
31  memcpy(&pageno, rec, sizeof(int));
32  appendStringInfo(buf, "%d", pageno);
33  }
34  else if (info == COMMIT_TS_TRUNCATE)
35  {
37 
38  appendStringInfo(buf, "pageno %d, oldestXid %u",
39  trunc->pageno, trunc->oldestXid);
40  }
41 }
unsigned char uint8
Definition: c.h:439
#define COMMIT_TS_ZEROPAGE
Definition: commit_ts.h:47
#define COMMIT_TS_TRUNCATE
Definition: commit_ts.h:48
static char * buf
Definition: pg_test_fsync.c:67
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
TransactionId oldestXid
Definition: commit_ts.h:64
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:408
#define XLogRecGetData(decoder)
Definition: xlogreader.h:413
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

References appendStringInfo(), buf, COMMIT_TS_TRUNCATE, COMMIT_TS_ZEROPAGE, xl_commit_ts_truncate::oldestXid, xl_commit_ts_truncate::pageno, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

◆ commit_ts_identify()

const char* commit_ts_identify ( uint8  info)

Definition at line 44 of file committsdesc.c.

45 {
46  switch (info)
47  {
48  case COMMIT_TS_ZEROPAGE:
49  return "ZEROPAGE";
50  case COMMIT_TS_TRUNCATE:
51  return "TRUNCATE";
52  default:
53  return NULL;
54  }
55 }

References COMMIT_TS_TRUNCATE, and COMMIT_TS_ZEROPAGE.

◆ commit_ts_redo()

void commit_ts_redo ( XLogReaderState record)

Definition at line 988 of file commit_ts.c.

989 {
990  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
991 
992  /* Backup blocks are not used in commit_ts records */
993  Assert(!XLogRecHasAnyBlockRefs(record));
994 
995  if (info == COMMIT_TS_ZEROPAGE)
996  {
997  int pageno;
998  int slotno;
999 
1000  memcpy(&pageno, XLogRecGetData(record), sizeof(int));
1001 
1002  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
1003 
1004  slotno = ZeroCommitTsPage(pageno, false);
1006  Assert(!CommitTsCtl->shared->page_dirty[slotno]);
1007 
1008  LWLockRelease(CommitTsSLRULock);
1009  }
1010  else if (info == COMMIT_TS_TRUNCATE)
1011  {
1013 
1015 
1016  /*
1017  * During XLOG replay, latest_page_number isn't set up yet; insert a
1018  * suitable value to bypass the sanity test in SimpleLruTruncate.
1019  */
1020  CommitTsCtl->shared->latest_page_number = trunc->pageno;
1021 
1023  }
1024  else
1025  elog(PANIC, "commit_ts_redo: unknown op code %u", info);
1026 }
void AdvanceOldestCommitTsXid(TransactionId oldestXact)
Definition: commit_ts.c:908
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:593
#define PANIC
Definition: elog.h:36
#define elog(elevel,...)
Definition: elog.h:218
Assert(fmt[strlen(fmt) - 1] !='\n')
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:614
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1226
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:415

References AdvanceOldestCommitTsXid(), Assert(), COMMIT_TS_TRUNCATE, COMMIT_TS_ZEROPAGE, CommitTsCtl, elog, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), xl_commit_ts_truncate::oldestXid, xl_commit_ts_truncate::pageno, PANIC, SimpleLruTruncate(), SimpleLruWritePage(), XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, XLR_INFO_MASK, and ZeroCommitTsPage().

◆ CommitTsParameterChange()

void CommitTsParameterChange ( bool  newvalue,
bool  oldvalue 
)

Definition at line 642 of file commit_ts.c.

643 {
644  /*
645  * If the commit_ts module is disabled in this server and we get word from
646  * the primary server that it is enabled there, activate it so that we can
647  * replay future WAL records involving it; also mark it as active on
648  * pg_control. If the old value was already set, we already did this, so
649  * don't do anything.
650  *
651  * If the module is disabled in the primary, disable it here too, unless
652  * the module is enabled locally.
653  *
654  * Note this only runs in the recovery process, so an unlocked read is
655  * fine.
656  */
657  if (newvalue)
658  {
661  }
662  else if (commitTsShared->commitTsActive)
664 }
static void DeactivateCommitTs(void)
Definition: commit_ts.c:757
static CommitTimestampShared * commitTsShared
Definition: commit_ts.c:101
static void ActivateCommitTs(void)
Definition: commit_ts.c:683

References ActivateCommitTs(), CommitTimestampShared::commitTsActive, commitTsShared, and DeactivateCommitTs().

Referenced by xlog_redo().

◆ CommitTsShmemBuffers()

Size CommitTsShmemBuffers ( void  )

Definition at line 519 of file commit_ts.c.

520 {
521  return Min(256, Max(4, NBuffers / 256));
522 }
#define Min(x, y)
Definition: c.h:986
#define Max(x, y)
Definition: c.h:980
int NBuffers
Definition: globals.c:136

References Max, Min, and NBuffers.

Referenced by CommitTsShmemInit(), and CommitTsShmemSize().

◆ CommitTsShmemInit()

void CommitTsShmemInit ( void  )

Definition at line 539 of file commit_ts.c.

540 {
541  bool found;
542 
543  CommitTsCtl->PagePrecedes = CommitTsPagePrecedes;
545  CommitTsSLRULock, "pg_commit_ts",
549 
550  commitTsShared = ShmemInitStruct("CommitTs shared",
551  sizeof(CommitTimestampShared),
552  &found);
553 
554  if (!IsUnderPostmaster)
555  {
556  Assert(!found);
557 
562  }
563  else
564  Assert(found);
565 }
Size CommitTsShmemBuffers(void)
Definition: commit_ts.c:519
#define COMMIT_TS_XACTS_PER_PAGE
Definition: commit_ts.c:68
static bool CommitTsPagePrecedes(int page1, int page2)
Definition: commit_ts.c:942
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:151
bool IsUnderPostmaster
Definition: globals.c:113
@ LWTRANCHE_COMMITTS_BUFFER
Definition: lwlock.h:170
#define InvalidRepOriginId
Definition: origin.h:33
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, LWLock *ctllock, const char *subdir, int tranche_id, SyncRequestHandler sync_handler)
Definition: slru.c:187
#define SlruPagePrecedesUnitTests(ctl, per_page)
Definition: slru.h:156
TimestampTz time
Definition: commit_ts.c:61
RepOriginId nodeid
Definition: commit_ts.c:62
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:97
TransactionId xidLastCommit
Definition: commit_ts.c:96
@ SYNC_HANDLER_COMMIT_TS
Definition: sync.h:39

References Assert(), COMMIT_TS_XACTS_PER_PAGE, CommitTimestampShared::commitTsActive, CommitTsCtl, CommitTsPagePrecedes(), commitTsShared, CommitTsShmemBuffers(), CommitTimestampShared::dataLastCommit, InvalidRepOriginId, InvalidTransactionId, IsUnderPostmaster, LWTRANCHE_COMMITTS_BUFFER, CommitTimestampEntry::nodeid, ShmemInitStruct(), SimpleLruInit(), SlruPagePrecedesUnitTests, SYNC_HANDLER_COMMIT_TS, CommitTimestampEntry::time, TIMESTAMP_NOBEGIN, and CommitTimestampShared::xidLastCommit.

Referenced by CreateSharedMemoryAndSemaphores().

◆ CommitTsShmemSize()

Size CommitTsShmemSize ( void  )

Definition at line 528 of file commit_ts.c.

529 {
531  sizeof(CommitTimestampShared);
532 }
struct CommitTimestampShared CommitTimestampShared
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:156

References CommitTsShmemBuffers(), and SimpleLruShmemSize().

Referenced by CalculateShmemSize().

◆ committssyncfiletag()

int committssyncfiletag ( const FileTag ftag,
char *  path 
)

Definition at line 1032 of file commit_ts.c.

1033 {
1034  return SlruSyncFileTag(CommitTsCtl, ftag, path);
1035 }
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
Definition: slru.c:1593

References CommitTsCtl, and SlruSyncFileTag().

◆ CompleteCommitTsInitialization()

void CompleteCommitTsInitialization ( void  )

Definition at line 620 of file commit_ts.c.

621 {
622  /*
623  * If the feature is not enabled, turn it off for good. This also removes
624  * any leftover data.
625  *
626  * Conversely, we activate the module if the feature is enabled. This is
627  * necessary for primary and standby as the activation depends on the
628  * control file contents at the beginning of recovery or when a
629  * XLOG_PARAMETER_CHANGE is replayed.
630  */
633  else
635 }
bool track_commit_timestamp
Definition: commit_ts.c:105

References ActivateCommitTs(), DeactivateCommitTs(), and track_commit_timestamp.

Referenced by StartupXLOG().

◆ ExtendCommitTs()

void ExtendCommitTs ( TransactionId  newestXact)

Definition at line 817 of file commit_ts.c.

818 {
819  int pageno;
820 
821  /*
822  * Nothing to do if module not enabled. Note we do an unlocked read of
823  * the flag here, which is okay because this routine is only called from
824  * GetNewTransactionId, which is never called in a standby.
825  */
826  Assert(!InRecovery);
828  return;
829 
830  /*
831  * No work except at first XID of a page. But beware: just after
832  * wraparound, the first XID of page zero is FirstNormalTransactionId.
833  */
834  if (TransactionIdToCTsEntry(newestXact) != 0 &&
836  return;
837 
838  pageno = TransactionIdToCTsPage(newestXact);
839 
840  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
841 
842  /* Zero the page and make an XLOG entry about it */
843  ZeroCommitTsPage(pageno, !InRecovery);
844 
845  LWLockRelease(CommitTsSLRULock);
846 }
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:73
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:71
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define FirstNormalTransactionId
Definition: transam.h:34
bool InRecovery
Definition: xlogutils.c:53

References Assert(), CommitTimestampShared::commitTsActive, commitTsShared, FirstNormalTransactionId, InRecovery, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransactionIdEquals, TransactionIdToCTsEntry, TransactionIdToCTsPage, and ZeroCommitTsPage().

Referenced by GetNewTransactionId().

◆ GetLatestCommitTsData()

TransactionId GetLatestCommitTsData ( TimestampTz ts,
RepOriginId nodeid 
)

Definition at line 355 of file commit_ts.c.

356 {
357  TransactionId xid;
358 
359  LWLockAcquire(CommitTsLock, LW_SHARED);
360 
361  /* Error if module not enabled */
364 
366  if (ts)
368  if (nodeid)
370  LWLockRelease(CommitTsLock);
371 
372  return xid;
373 }
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:376
@ LW_SHARED
Definition: lwlock.h:105

References CommitTimestampShared::commitTsActive, commitTsShared, CommitTimestampShared::dataLastCommit, error_commit_ts_disabled(), LW_SHARED, LWLockAcquire(), LWLockRelease(), CommitTimestampEntry::nodeid, CommitTimestampEntry::time, and CommitTimestampShared::xidLastCommit.

Referenced by pg_last_committed_xact().

◆ SetCommitTsLimit()

void SetCommitTsLimit ( TransactionId  oldestXact,
TransactionId  newestXact 
)

Definition at line 881 of file commit_ts.c.

882 {
883  /*
884  * Be careful not to overwrite values that are either further into the
885  * "future" or signal a disabled committs.
886  */
887  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
889  {
894  }
895  else
896  {
900  }
901  LWLockRelease(CommitTsLock);
902 }
TransactionId newestCommitTsXid
Definition: transam.h:233

References Assert(), InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::newestCommitTsXid, VariableCacheData::oldestCommitTsXid, ShmemVariableCache, and TransactionIdPrecedes().

Referenced by BootStrapXLOG(), and StartupXLOG().

◆ StartupCommitTs()

void StartupCommitTs ( void  )

Definition at line 610 of file commit_ts.c.

611 {
613 }

References ActivateCommitTs().

Referenced by StartupXLOG().

◆ TransactionIdGetCommitTsData()

bool TransactionIdGetCommitTsData ( TransactionId  xid,
TimestampTz ts,
RepOriginId nodeid 
)

Definition at line 269 of file commit_ts.c.

271 {
272  int pageno = TransactionIdToCTsPage(xid);
273  int entryno = TransactionIdToCTsEntry(xid);
274  int slotno;
275  CommitTimestampEntry entry;
276  TransactionId oldestCommitTsXid;
277  TransactionId newestCommitTsXid;
278 
279  if (!TransactionIdIsValid(xid))
280  ereport(ERROR,
281  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
282  errmsg("cannot retrieve commit timestamp for transaction %u", xid)));
283  else if (!TransactionIdIsNormal(xid))
284  {
285  /* frozen and bootstrap xids are always committed far in the past */
286  *ts = 0;
287  if (nodeid)
288  *nodeid = 0;
289  return false;
290  }
291 
292  LWLockAcquire(CommitTsLock, LW_SHARED);
293 
294  /* Error if module not enabled */
297 
298  /*
299  * If we're asked for the cached value, return that. Otherwise, fall
300  * through to read from SLRU.
301  */
302  if (commitTsShared->xidLastCommit == xid)
303  {
305  if (nodeid)
307 
308  LWLockRelease(CommitTsLock);
309  return *ts != 0;
310  }
311 
312  oldestCommitTsXid = ShmemVariableCache->oldestCommitTsXid;
313  newestCommitTsXid = ShmemVariableCache->newestCommitTsXid;
314  /* neither is invalid, or both are */
315  Assert(TransactionIdIsValid(oldestCommitTsXid) == TransactionIdIsValid(newestCommitTsXid));
316  LWLockRelease(CommitTsLock);
317 
318  /*
319  * Return empty if the requested value is outside our valid range.
320  */
321  if (!TransactionIdIsValid(oldestCommitTsXid) ||
322  TransactionIdPrecedes(xid, oldestCommitTsXid) ||
323  TransactionIdPrecedes(newestCommitTsXid, xid))
324  {
325  *ts = 0;
326  if (nodeid)
327  *nodeid = InvalidRepOriginId;
328  return false;
329  }
330 
331  /* lock is acquired by SimpleLruReadPage_ReadOnly */
332  slotno = SimpleLruReadPage_ReadOnly(CommitTsCtl, pageno, xid);
333  memcpy(&entry,
334  CommitTsCtl->shared->page_buffer[slotno] +
335  SizeOfCommitTimestampEntry * entryno,
337 
338  *ts = entry.time;
339  if (nodeid)
340  *nodeid = entry.nodeid;
341 
342  LWLockRelease(CommitTsSLRULock);
343  return *ts != 0;
344 }
#define SizeOfCommitTimestampEntry
Definition: commit_ts.c:65
int errcode(int sqlerrcode)
Definition: elog.c:693
int errmsg(const char *fmt,...)
Definition: elog.c:904
#define ERROR
Definition: elog.h:33
#define ereport(elevel,...)
Definition: elog.h:143
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
Definition: slru.c:495
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define TransactionIdIsNormal(xid)
Definition: transam.h:42

References Assert(), CommitTimestampShared::commitTsActive, CommitTsCtl, commitTsShared, CommitTimestampShared::dataLastCommit, ereport, errcode(), errmsg(), ERROR, error_commit_ts_disabled(), InvalidRepOriginId, LW_SHARED, LWLockAcquire(), LWLockRelease(), VariableCacheData::newestCommitTsXid, CommitTimestampEntry::nodeid, VariableCacheData::oldestCommitTsXid, ShmemVariableCache, SimpleLruReadPage_ReadOnly(), SizeOfCommitTimestampEntry, CommitTimestampEntry::time, TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), TransactionIdToCTsEntry, TransactionIdToCTsPage, and CommitTimestampShared::xidLastCommit.

Referenced by pg_xact_commit_timestamp(), and pg_xact_commit_timestamp_origin().

◆ TransactionTreeSetCommitTsData()

void TransactionTreeSetCommitTsData ( TransactionId  xid,
int  nsubxids,
TransactionId subxids,
TimestampTz  timestamp,
RepOriginId  nodeid 
)

Definition at line 137 of file commit_ts.c.

140 {
141  int i;
142  TransactionId headxid;
143  TransactionId newestXact;
144 
145  /*
146  * No-op if the module is not active.
147  *
148  * An unlocked read here is fine, because in a standby (the only place
149  * where the flag can change in flight) this routine is only called by the
150  * recovery process, which is also the only process which can change the
151  * flag.
152  */
154  return;
155 
156  /*
157  * Figure out the latest Xid in this batch: either the last subxid if
158  * there's any, otherwise the parent xid.
159  */
160  if (nsubxids > 0)
161  newestXact = subxids[nsubxids - 1];
162  else
163  newestXact = xid;
164 
165  /*
166  * We split the xids to set the timestamp to in groups belonging to the
167  * same SLRU page; the first element in each such set is its head. The
168  * first group has the main XID as the head; subsequent sets use the first
169  * subxid not on the previous page as head. This way, we only have to
170  * lock/modify each SLRU page once.
171  */
172  headxid = xid;
173  i = 0;
174  for (;;)
175  {
176  int pageno = TransactionIdToCTsPage(headxid);
177  int j;
178 
179  for (j = i; j < nsubxids; j++)
180  {
181  if (TransactionIdToCTsPage(subxids[j]) != pageno)
182  break;
183  }
184  /* subxids[i..j] are on the same page as the head */
185 
186  SetXidCommitTsInPage(headxid, j - i, subxids + i, timestamp, nodeid,
187  pageno);
188 
189  /* if we wrote out all subxids, we're done. */
190  if (j >= nsubxids)
191  break;
192 
193  /*
194  * Set the new head and skip over it, as well as over the subxids we
195  * just wrote.
196  */
197  headxid = subxids[j];
198  i = j + 1;
199  }
200 
201  /* update the cached value in shared memory */
202  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
206 
207  /* and move forwards our endpoint, if needed */
210  LWLockRelease(CommitTsLock);
211 }
static void SetXidCommitTsInPage(TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz ts, RepOriginId nodeid, int pageno)
Definition: commit_ts.c:218
int j
Definition: isn.c:74
int i
Definition: isn.c:73
int64 timestamp

References CommitTimestampShared::commitTsActive, commitTsShared, CommitTimestampShared::dataLastCommit, i, j, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::newestCommitTsXid, CommitTimestampEntry::nodeid, SetXidCommitTsInPage(), ShmemVariableCache, CommitTimestampEntry::time, TransactionIdPrecedes(), TransactionIdToCTsPage, and CommitTimestampShared::xidLastCommit.

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

◆ TruncateCommitTs()

void TruncateCommitTs ( TransactionId  oldestXact)

Definition at line 855 of file commit_ts.c.

856 {
857  int cutoffPage;
858 
859  /*
860  * The cutoff point is the start of the segment containing oldestXact. We
861  * pass the *page* containing oldestXact to SimpleLruTruncate.
862  */
863  cutoffPage = TransactionIdToCTsPage(oldestXact);
864 
865  /* Check to see if there's any files that could be removed */
867  &cutoffPage))
868  return; /* nothing to remove */
869 
870  /* Write XLOG record */
871  WriteTruncateXlogRec(cutoffPage, oldestXact);
872 
873  /* Now we can remove the old CommitTs segment(s) */
874  SimpleLruTruncate(CommitTsCtl, cutoffPage);
875 }
static void WriteTruncateXlogRec(int pageno, TransactionId oldestXid)
Definition: commit_ts.c:972
bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename, int segpage, void *data)
Definition: slru.c:1500
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1553

References CommitTsCtl, SimpleLruTruncate(), SlruScanDirCbReportPresence(), SlruScanDirectory(), TransactionIdToCTsPage, and WriteTruncateXlogRec().

Referenced by vac_truncate_clog().

Variable Documentation

◆ track_commit_timestamp

PGDLLIMPORT bool track_commit_timestamp
extern