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))
uint32 TransactionId
Definition: c.h:588

Definition at line 58 of file commit_ts.h.

◆ SizeOfCommitTsTruncate

#define SizeOfCommitTsTruncate
Value:
(offsetof(xl_commit_ts_truncate, oldestXid) + \
sizeof(TransactionId))

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 905 of file commit_ts.c.

906 {
907  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
911  LWLockRelease(CommitTsLock);
912 }
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1194
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1802
@ LW_EXCLUSIVE
Definition: lwlock.h:112
TransactionId oldestCommitTsXid
Definition: transam.h:232
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:273
#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 571 of file commit_ts.c.

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

Referenced by BootStrapXLOG().

◆ CheckPointCommitTs()

void CheckPointCommitTs ( void  )

Definition at line 792 of file commit_ts.c.

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

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:440
#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:411
#define XLogRecGetData(decoder)
Definition: xlogreader.h:416
#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 985 of file commit_ts.c.

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

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 639 of file commit_ts.c.

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

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

Referenced by xlog_redo().

◆ CommitTsShmemBuffers()

Size CommitTsShmemBuffers ( void  )

Definition at line 516 of file commit_ts.c.

517 {
518  return Min(256, Max(4, NBuffers / 256));
519 }
#define Min(x, y)
Definition: c.h:937
#define Max(x, y)
Definition: c.h:931
int NBuffers
Definition: globals.c:136

References Max, Min, and NBuffers.

Referenced by CommitTsShmemInit(), and CommitTsShmemSize().

◆ CommitTsShmemInit()

void CommitTsShmemInit ( void  )

Definition at line 536 of file commit_ts.c.

537 {
538  bool found;
539 
540  CommitTsCtl->PagePrecedes = CommitTsPagePrecedes;
542  CommitTsSLRULock, "pg_commit_ts",
546 
547  commitTsShared = ShmemInitStruct("CommitTs shared",
548  sizeof(CommitTimestampShared),
549  &found);
550 
551  if (!IsUnderPostmaster)
552  {
553  Assert(!found);
554 
559  }
560  else
561  Assert(found);
562 }
Size CommitTsShmemBuffers(void)
Definition: commit_ts.c:516
#define COMMIT_TS_XACTS_PER_PAGE
Definition: commit_ts.c:65
static bool CommitTsPagePrecedes(int page1, int page2)
Definition: commit_ts.c:939
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:151
bool IsUnderPostmaster
Definition: globals.c:113
@ LWTRANCHE_COMMITTS_BUFFER
Definition: lwlock.h:178
#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:188
#define SlruPagePrecedesUnitTests(ctl, per_page)
Definition: slru.h:156
TimestampTz time
Definition: commit_ts.c:58
RepOriginId nodeid
Definition: commit_ts.c:59
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:94
TransactionId xidLastCommit
Definition: commit_ts.c:93
@ 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 525 of file commit_ts.c.

526 {
528  sizeof(CommitTimestampShared);
529 }
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 1029 of file commit_ts.c.

1030 {
1031  return SlruSyncFileTag(CommitTsCtl, ftag, path);
1032 }
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
Definition: slru.c:1594

References CommitTsCtl, and SlruSyncFileTag().

◆ CompleteCommitTsInitialization()

void CompleteCommitTsInitialization ( void  )

Definition at line 617 of file commit_ts.c.

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

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

Referenced by StartupXLOG().

◆ ExtendCommitTs()

void ExtendCommitTs ( TransactionId  newestXact)

Definition at line 814 of file commit_ts.c.

815 {
816  int pageno;
817 
818  /*
819  * Nothing to do if module not enabled. Note we do an unlocked read of
820  * the flag here, which is okay because this routine is only called from
821  * GetNewTransactionId, which is never called in a standby.
822  */
823  Assert(!InRecovery);
825  return;
826 
827  /*
828  * No work except at first XID of a page. But beware: just after
829  * wraparound, the first XID of page zero is FirstNormalTransactionId.
830  */
831  if (TransactionIdToCTsEntry(newestXact) != 0 &&
833  return;
834 
835  pageno = TransactionIdToCTsPage(newestXact);
836 
837  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
838 
839  /* Zero the page and make an XLOG entry about it */
840  ZeroCommitTsPage(pageno, !InRecovery);
841 
842  LWLockRelease(CommitTsSLRULock);
843 }
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:70
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:68
#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 352 of file commit_ts.c.

353 {
354  TransactionId xid;
355 
356  LWLockAcquire(CommitTsLock, LW_SHARED);
357 
358  /* Error if module not enabled */
361 
363  if (ts)
365  if (nodeid)
367  LWLockRelease(CommitTsLock);
368 
369  return xid;
370 }
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:373
@ LW_SHARED
Definition: lwlock.h:113

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 878 of file commit_ts.c.

879 {
880  /*
881  * Be careful not to overwrite values that are either further into the
882  * "future" or signal a disabled committs.
883  */
884  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
886  {
891  }
892  else
893  {
897  }
898  LWLockRelease(CommitTsLock);
899 }
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 607 of file commit_ts.c.

608 {
610 }

References ActivateCommitTs().

Referenced by StartupXLOG().

◆ TransactionIdGetCommitTsData()

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

Definition at line 266 of file commit_ts.c.

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

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

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

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

Referenced by vac_truncate_clog().

Variable Documentation

◆ track_commit_timestamp

PGDLLIMPORT bool track_commit_timestamp
extern