PostgreSQL Source Code  git master
commit_ts.c File Reference
#include "postgres.h"
#include "access/commit_ts.h"
#include "access/htup_details.h"
#include "access/slru.h"
#include "access/transam.h"
#include "catalog/pg_type.h"
#include "funcapi.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "storage/shmem.h"
#include "utils/builtins.h"
#include "utils/snapmgr.h"
#include "utils/timestamp.h"
Include dependency graph for commit_ts.c:

Go to the source code of this file.

Data Structures

struct  CommitTimestampEntry
 
struct  CommitTimestampShared
 

Macros

#define SizeOfCommitTimestampEntry
 
#define COMMIT_TS_XACTS_PER_PAGE   (BLCKSZ / SizeOfCommitTimestampEntry)
 
#define TransactionIdToCTsPage(xid)   ((xid) / (TransactionId) COMMIT_TS_XACTS_PER_PAGE)
 
#define TransactionIdToCTsEntry(xid)   ((xid) % (TransactionId) COMMIT_TS_XACTS_PER_PAGE)
 
#define CommitTsCtl   (&CommitTsCtlData)
 

Typedefs

typedef struct CommitTimestampEntry CommitTimestampEntry
 
typedef struct CommitTimestampShared CommitTimestampShared
 

Functions

static void SetXidCommitTsInPage (TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz ts, RepOriginId nodeid, int pageno)
 
static void TransactionIdSetCommitTs (TransactionId xid, TimestampTz ts, RepOriginId nodeid, int slotno)
 
static void error_commit_ts_disabled (void)
 
static int ZeroCommitTsPage (int pageno, bool writeXlog)
 
static bool CommitTsPagePrecedes (int page1, int page2)
 
static void ActivateCommitTs (void)
 
static void DeactivateCommitTs (void)
 
static void WriteZeroPageXlogRec (int pageno)
 
static void WriteTruncateXlogRec (int pageno, TransactionId oldestXid)
 
static void WriteSetTimestampXlogRec (TransactionId mainxid, int nsubxids, TransactionId *subxids, TimestampTz timestamp, RepOriginId nodeid)
 
void TransactionTreeSetCommitTsData (TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz timestamp, RepOriginId nodeid, bool write_xlog)
 
bool TransactionIdGetCommitTsData (TransactionId xid, TimestampTz *ts, RepOriginId *nodeid)
 
TransactionId GetLatestCommitTsData (TimestampTz *ts, RepOriginId *nodeid)
 
Datum pg_xact_commit_timestamp (PG_FUNCTION_ARGS)
 
Datum pg_last_committed_xact (PG_FUNCTION_ARGS)
 
Size CommitTsShmemBuffers (void)
 
Size CommitTsShmemSize (void)
 
void CommitTsShmemInit (void)
 
void BootStrapCommitTs (void)
 
void StartupCommitTs (void)
 
void CompleteCommitTsInitialization (void)
 
void CommitTsParameterChange (bool newvalue, bool oldvalue)
 
void ShutdownCommitTs (void)
 
void CheckPointCommitTs (void)
 
void ExtendCommitTs (TransactionId newestXact)
 
void TruncateCommitTs (TransactionId oldestXact)
 
void SetCommitTsLimit (TransactionId oldestXact, TransactionId newestXact)
 
void AdvanceOldestCommitTsXid (TransactionId oldestXact)
 
void commit_ts_redo (XLogReaderState *record)
 

Variables

static SlruCtlData CommitTsCtlData
 
CommitTimestampSharedcommitTsShared
 
bool track_commit_timestamp
 

Macro Definition Documentation

◆ COMMIT_TS_XACTS_PER_PAGE

#define COMMIT_TS_XACTS_PER_PAGE   (BLCKSZ / SizeOfCommitTimestampEntry)

Definition at line 66 of file commit_ts.c.

Referenced by CommitTsPagePrecedes().

◆ CommitTsCtl

◆ SizeOfCommitTimestampEntry

#define SizeOfCommitTimestampEntry
Value:
sizeof(RepOriginId))
uint16 RepOriginId
Definition: xlogdefs.h:58
#define offsetof(type, field)
Definition: c.h:662

Definition at line 63 of file commit_ts.c.

Referenced by TransactionIdGetCommitTsData(), and TransactionIdSetCommitTs().

◆ TransactionIdToCTsEntry

#define TransactionIdToCTsEntry (   xid)    ((xid) % (TransactionId) COMMIT_TS_XACTS_PER_PAGE)

◆ TransactionIdToCTsPage

#define TransactionIdToCTsPage (   xid)    ((xid) / (TransactionId) COMMIT_TS_XACTS_PER_PAGE)

Typedef Documentation

◆ CommitTimestampEntry

◆ CommitTimestampShared

Function Documentation

◆ ActivateCommitTs()

static void ActivateCommitTs ( void  )
static

Definition at line 632 of file commit_ts.c.

References Assert, CommitTimestampShared::commitTsActive, CommitTsCtl, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::newestCommitTsXid, VariableCacheData::nextFullXid, VariableCacheData::oldestCommitTsXid, ReadNewTransactionId(), ShmemVariableCache, SimpleLruDoesPhysicalPageExist(), SimpleLruWritePage(), TransactionIdToCTsPage, XidFromFullTransactionId, and ZeroCommitTsPage().

Referenced by CommitTsParameterChange(), CompleteCommitTsInitialization(), and StartupCommitTs().

633 {
634  TransactionId xid;
635  int pageno;
636 
637  /* If we've done this already, there's nothing to do */
638  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
640  {
641  LWLockRelease(CommitTsLock);
642  return;
643  }
644  LWLockRelease(CommitTsLock);
645 
647  pageno = TransactionIdToCTsPage(xid);
648 
649  /*
650  * Re-Initialize our idea of the latest page number.
651  */
652  LWLockAcquire(CommitTsControlLock, LW_EXCLUSIVE);
653  CommitTsCtl->shared->latest_page_number = pageno;
654  LWLockRelease(CommitTsControlLock);
655 
656  /*
657  * If CommitTs is enabled, but it wasn't in the previous server run, we
658  * need to set the oldest and newest values to the next Xid; that way, we
659  * will not try to read data that might not have been set.
660  *
661  * XXX does this have a problem if a server is started with commitTs
662  * enabled, then started with commitTs disabled, then restarted with it
663  * enabled again? It doesn't look like it does, because there should be a
664  * checkpoint that sets the value to InvalidTransactionId at end of
665  * recovery; and so any chance of injecting new transactions without
666  * CommitTs values would occur after the oldestCommitTsXid has been set to
667  * Invalid temporarily.
668  */
669  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
671  {
674  }
675  LWLockRelease(CommitTsLock);
676 
677  /* Create the current segment file, if necessary */
679  {
680  int slotno;
681 
682  LWLockAcquire(CommitTsControlLock, LW_EXCLUSIVE);
683  slotno = ZeroCommitTsPage(pageno, false);
685  Assert(!CommitTsCtl->shared->page_dirty[slotno]);
686  LWLockRelease(CommitTsControlLock);
687  }
688 
689  /* Change the activation status in shared memory. */
690  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
692  LWLockRelease(CommitTsLock);
693 }
uint32 TransactionId
Definition: c.h:514
#define CommitTsCtl
Definition: commit_ts.c:79
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:542
FullTransactionId nextFullXid
Definition: transam.h:164
#define XidFromFullTransactionId(x)
Definition: transam.h:48
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
bool SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno)
Definition: slru.c:589
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:577
TransactionId oldestCommitTsXid
Definition: transam.h:176
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:69
#define Assert(condition)
Definition: c.h:739
TransactionId newestCommitTsXid
Definition: transam.h:177
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
static TransactionId ReadNewTransactionId(void)
Definition: transam.h:244
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99

◆ AdvanceOldestCommitTsXid()

void AdvanceOldestCommitTsXid ( TransactionId  oldestXact)

Definition at line 875 of file commit_ts.c.

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

Referenced by commit_ts_redo(), and vac_truncate_clog().

876 {
877  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
881  LWLockRelease(CommitTsLock);
882 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
TransactionId oldestCommitTsXid
Definition: transam.h:176
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122

◆ BootStrapCommitTs()

void BootStrapCommitTs ( void  )

Definition at line 523 of file commit_ts.c.

Referenced by BootStrapXLOG().

524 {
525  /*
526  * Nothing to do here at present, unlike most other SLRU modules; segments
527  * are created when the server is started with this module enabled. See
528  * ActivateCommitTs.
529  */
530 }

◆ CheckPointCommitTs()

void CheckPointCommitTs ( void  )

Definition at line 760 of file commit_ts.c.

References CommitTsCtl, fsync_fname(), and SimpleLruFlush().

Referenced by CheckPointGuts().

761 {
762  /* Flush dirty CommitTs pages to disk */
764 
765  /*
766  * fsync pg_commit_ts to ensure that any files flushed previously are
767  * durably on disk.
768  */
769  fsync_fname("pg_commit_ts", true);
770 }
#define CommitTsCtl
Definition: commit_ts.c:79
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:617
void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1119

◆ commit_ts_redo()

void commit_ts_redo ( XLogReaderState record)

Definition at line 963 of file commit_ts.c.

References AdvanceOldestCommitTsXid(), Assert, COMMIT_TS_SETTS, COMMIT_TS_TRUNCATE, COMMIT_TS_ZEROPAGE, CommitTsCtl, elog, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), xl_commit_ts_set::mainxid, xl_commit_ts_set::nodeid, xl_commit_ts_truncate::oldestXid, xl_commit_ts_truncate::pageno, palloc(), PANIC, pfree(), SimpleLruTruncate(), SimpleLruWritePage(), SizeOfCommitTsSet, xl_commit_ts_set::timestamp, TransactionTreeSetCommitTsData(), XLogRecGetData, XLogRecGetDataLen, XLogRecGetInfo, XLogRecHasAnyBlockRefs, XLR_INFO_MASK, and ZeroCommitTsPage().

964 {
965  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
966 
967  /* Backup blocks are not used in commit_ts records */
968  Assert(!XLogRecHasAnyBlockRefs(record));
969 
970  if (info == COMMIT_TS_ZEROPAGE)
971  {
972  int pageno;
973  int slotno;
974 
975  memcpy(&pageno, XLogRecGetData(record), sizeof(int));
976 
977  LWLockAcquire(CommitTsControlLock, LW_EXCLUSIVE);
978 
979  slotno = ZeroCommitTsPage(pageno, false);
981  Assert(!CommitTsCtl->shared->page_dirty[slotno]);
982 
983  LWLockRelease(CommitTsControlLock);
984  }
985  else if (info == COMMIT_TS_TRUNCATE)
986  {
988 
990 
991  /*
992  * During XLOG replay, latest_page_number isn't set up yet; insert a
993  * suitable value to bypass the sanity test in SimpleLruTruncate.
994  */
995  CommitTsCtl->shared->latest_page_number = trunc->pageno;
996 
998  }
999  else if (info == COMMIT_TS_SETTS)
1000  {
1001  xl_commit_ts_set *setts = (xl_commit_ts_set *) XLogRecGetData(record);
1002  int nsubxids;
1003  TransactionId *subxids;
1004 
1005  nsubxids = ((XLogRecGetDataLen(record) - SizeOfCommitTsSet) /
1006  sizeof(TransactionId));
1007  if (nsubxids > 0)
1008  {
1009  subxids = palloc(sizeof(TransactionId) * nsubxids);
1010  memcpy(subxids,
1012  sizeof(TransactionId) * nsubxids);
1013  }
1014  else
1015  subxids = NULL;
1016 
1017  TransactionTreeSetCommitTsData(setts->mainxid, nsubxids, subxids,
1018  setts->timestamp, setts->nodeid, true);
1019  if (subxids)
1020  pfree(subxids);
1021  }
1022  else
1023  elog(PANIC, "commit_ts_redo: unknown op code %u", info);
1024 }
#define COMMIT_TS_ZEROPAGE
Definition: commit_ts.h:49
#define COMMIT_TS_SETTS
Definition: commit_ts.h:51
uint32 TransactionId
Definition: c.h:514
#define CommitTsCtl
Definition: commit_ts.c:79
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:542
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1184
unsigned char uint8
Definition: c.h:357
#define PANIC
Definition: elog.h:53
void AdvanceOldestCommitTsXid(TransactionId oldestXact)
Definition: commit_ts.c:875
TimestampTz timestamp
Definition: commit_ts.h:55
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
void pfree(void *pointer)
Definition: mcxt.c:1056
#define XLogRecGetData(decoder)
Definition: xlogreader.h:283
#define XLogRecGetDataLen(decoder)
Definition: xlogreader.h:284
#define SizeOfCommitTsSet
Definition: commit_ts.h:61
TransactionId oldestXid
Definition: commit_ts.h:67
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:577
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:279
#define COMMIT_TS_TRUNCATE
Definition: commit_ts.h:50
TransactionId mainxid
Definition: commit_ts.h:57
#define Assert(condition)
Definition: c.h:739
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
void * palloc(Size size)
Definition: mcxt.c:949
RepOriginId nodeid
Definition: commit_ts.h:56
#define elog(elevel,...)
Definition: elog.h:228
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:285
void TransactionTreeSetCommitTsData(TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz timestamp, RepOriginId nodeid, bool write_xlog)
Definition: commit_ts.c:145

◆ CommitTsPagePrecedes()

static bool CommitTsPagePrecedes ( int  page1,
int  page2 
)
static

Definition at line 896 of file commit_ts.c.

References COMMIT_TS_XACTS_PER_PAGE, FirstNormalTransactionId, and TransactionIdPrecedes().

Referenced by CommitTsShmemInit().

897 {
898  TransactionId xid1;
899  TransactionId xid2;
900 
901  xid1 = ((TransactionId) page1) * COMMIT_TS_XACTS_PER_PAGE;
902  xid1 += FirstNormalTransactionId;
903  xid2 = ((TransactionId) page2) * COMMIT_TS_XACTS_PER_PAGE;
904  xid2 += FirstNormalTransactionId;
905 
906  return TransactionIdPrecedes(xid1, xid2);
907 }
uint32 TransactionId
Definition: c.h:514
#define FirstNormalTransactionId
Definition: transam.h:34
#define COMMIT_TS_XACTS_PER_PAGE
Definition: commit_ts.c:66
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300

◆ CommitTsParameterChange()

void CommitTsParameterChange ( bool  newvalue,
bool  oldvalue 
)

Definition at line 591 of file commit_ts.c.

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

Referenced by xlog_redo().

592 {
593  /*
594  * If the commit_ts module is disabled in this server and we get word from
595  * the master server that it is enabled there, activate it so that we can
596  * replay future WAL records involving it; also mark it as active on
597  * pg_control. If the old value was already set, we already did this, so
598  * don't do anything.
599  *
600  * If the module is disabled in the master, disable it here too, unless
601  * the module is enabled locally.
602  *
603  * Note this only runs in the recovery process, so an unlocked read is
604  * fine.
605  */
606  if (newvalue)
607  {
610  }
611  else if (commitTsShared->commitTsActive)
613 }
static void ActivateCommitTs(void)
Definition: commit_ts.c:632
static void DeactivateCommitTs(void)
Definition: commit_ts.c:706
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99

◆ CommitTsShmemBuffers()

Size CommitTsShmemBuffers ( void  )

Definition at line 470 of file commit_ts.c.

References Max, Min, and NBuffers.

Referenced by CommitTsShmemInit(), and CommitTsShmemSize().

471 {
472  return Min(16, Max(4, NBuffers / 1024));
473 }
#define Min(x, y)
Definition: c.h:911
#define Max(x, y)
Definition: c.h:905
int NBuffers
Definition: globals.c:131

◆ CommitTsShmemInit()

void CommitTsShmemInit ( void  )

Definition at line 490 of file commit_ts.c.

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

Referenced by CreateSharedMemoryAndSemaphores().

491 {
492  bool found;
493 
494  CommitTsCtl->PagePrecedes = CommitTsPagePrecedes;
495  SimpleLruInit(CommitTsCtl, "commit_timestamp", CommitTsShmemBuffers(), 0,
496  CommitTsControlLock, "pg_commit_ts",
498 
499  commitTsShared = ShmemInitStruct("CommitTs shared",
500  sizeof(CommitTimestampShared),
501  &found);
502 
503  if (!IsUnderPostmaster)
504  {
505  Assert(!found);
506 
511  }
512  else
513  Assert(found);
514 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:95
#define CommitTsCtl
Definition: commit_ts.c:79
Size CommitTsShmemBuffers(void)
Definition: commit_ts.c:470
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:372
bool IsUnderPostmaster
Definition: globals.c:109
#define InvalidTransactionId
Definition: transam.h:31
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
TimestampTz time
Definition: commit_ts.c:59
static bool CommitTsPagePrecedes(int page1, int page2)
Definition: commit_ts.c:896
TransactionId xidLastCommit
Definition: commit_ts.c:94
#define Assert(condition)
Definition: c.h:739
#define InvalidRepOriginId
Definition: origin.h:33
RepOriginId nodeid
Definition: commit_ts.c:60
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99
void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, LWLock *ctllock, const char *subdir, int tranche_id)
Definition: slru.c:164

◆ CommitTsShmemSize()

Size CommitTsShmemSize ( void  )

Definition at line 479 of file commit_ts.c.

References CommitTsShmemBuffers(), and SimpleLruShmemSize().

Referenced by CreateSharedMemoryAndSemaphores().

480 {
482  sizeof(CommitTimestampShared);
483 }
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:144
Size CommitTsShmemBuffers(void)
Definition: commit_ts.c:470
struct CommitTimestampShared CommitTimestampShared

◆ CompleteCommitTsInitialization()

void CompleteCommitTsInitialization ( void  )

Definition at line 569 of file commit_ts.c.

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

Referenced by StartupXLOG().

570 {
571  /*
572  * If the feature is not enabled, turn it off for good. This also removes
573  * any leftover data.
574  *
575  * Conversely, we activate the module if the feature is enabled. This is
576  * necessary for primary and standby as the activation depends on the
577  * control file contents at the beginning of recovery or when a
578  * XLOG_PARAMETER_CHANGE is replayed.
579  */
582  else
584 }
bool track_commit_timestamp
Definition: commit_ts.c:103
static void ActivateCommitTs(void)
Definition: commit_ts.c:632
static void DeactivateCommitTs(void)
Definition: commit_ts.c:706

◆ DeactivateCommitTs()

static void DeactivateCommitTs ( void  )
static

Definition at line 706 of file commit_ts.c.

References CommitTimestampShared::commitTsActive, CommitTsCtl, CommitTimestampShared::dataLastCommit, InvalidRepOriginId, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::newestCommitTsXid, CommitTimestampEntry::nodeid, VariableCacheData::oldestCommitTsXid, ShmemVariableCache, SlruScanDirCbDeleteAll(), SlruScanDirectory(), CommitTimestampEntry::time, TIMESTAMP_NOBEGIN, and CommitTimestampShared::xidLastCommit.

Referenced by CommitTsParameterChange(), and CompleteCommitTsInitialization().

707 {
708  /*
709  * Cleanup the status in the shared memory.
710  *
711  * We reset everything in the commitTsShared record to prevent user from
712  * getting confusing data about last committed transaction on the standby
713  * when the module was activated repeatedly on the primary.
714  */
715  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
716 
721 
724 
725  LWLockRelease(CommitTsLock);
726 
727  /*
728  * Remove *all* files. This is necessary so that there are no leftover
729  * files; in the case where this feature is later enabled after running
730  * with it disabled for some time there may be a gap in the file sequence.
731  * (We can probably tolerate out-of-sequence files, as they are going to
732  * be overwritten anyway when we wrap around, but it seems better to be
733  * tidy.)
734  */
735  LWLockAcquire(CommitTsControlLock, LW_EXCLUSIVE);
737  LWLockRelease(CommitTsControlLock);
738 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:95
bool SlruScanDirCbDeleteAll(SlruCtl ctl, char *filename, int segpage, void *data)
Definition: slru.c:1369
#define CommitTsCtl
Definition: commit_ts.c:79
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
TransactionId oldestCommitTsXid
Definition: transam.h:176
TimestampTz time
Definition: commit_ts.c:59
TransactionId xidLastCommit
Definition: commit_ts.c:94
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1392
TransactionId newestCommitTsXid
Definition: transam.h:177
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define InvalidRepOriginId
Definition: origin.h:33
RepOriginId nodeid
Definition: commit_ts.c:60
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99

◆ error_commit_ts_disabled()

static void error_commit_ts_disabled ( void  )
static

Definition at line 389 of file commit_ts.c.

References ereport, errcode(), errhint(), errmsg(), ERROR, and RecoveryInProgress().

Referenced by GetLatestCommitTsData(), and TransactionIdGetCommitTsData().

390 {
391  ereport(ERROR,
392  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
393  errmsg("could not get commit timestamp data"),
395  errhint("Make sure the configuration parameter \"%s\" is set on the master server.",
396  "track_commit_timestamp") :
397  errhint("Make sure the configuration parameter \"%s\" is set.",
398  "track_commit_timestamp")));
399 }
int errhint(const char *fmt,...)
Definition: elog.c:1069
int errcode(int sqlerrcode)
Definition: elog.c:608
bool RecoveryInProgress(void)
Definition: xlog.c:7935
#define ERROR
Definition: elog.h:43
#define ereport(elevel, rest)
Definition: elog.h:141
int errmsg(const char *fmt,...)
Definition: elog.c:822

◆ ExtendCommitTs()

void ExtendCommitTs ( TransactionId  newestXact)

Definition at line 784 of file commit_ts.c.

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

Referenced by GetNewTransactionId().

785 {
786  int pageno;
787 
788  /*
789  * Nothing to do if module not enabled. Note we do an unlocked read of
790  * the flag here, which is okay because this routine is only called from
791  * GetNewTransactionId, which is never called in a standby.
792  */
793  Assert(!InRecovery);
795  return;
796 
797  /*
798  * No work except at first XID of a page. But beware: just after
799  * wraparound, the first XID of page zero is FirstNormalTransactionId.
800  */
801  if (TransactionIdToCTsEntry(newestXact) != 0 &&
803  return;
804 
805  pageno = TransactionIdToCTsPage(newestXact);
806 
807  LWLockAcquire(CommitTsControlLock, LW_EXCLUSIVE);
808 
809  /* Zero the page and make an XLOG entry about it */
810  ZeroCommitTsPage(pageno, !InRecovery);
811 
812  LWLockRelease(CommitTsControlLock);
813 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:542
bool InRecovery
Definition: xlog.c:200
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define FirstNormalTransactionId
Definition: transam.h:34
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:69
#define Assert(condition)
Definition: c.h:739
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:71
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99

◆ GetLatestCommitTsData()

TransactionId GetLatestCommitTsData ( TimestampTz ts,
RepOriginId nodeid 
)

Definition at line 368 of file commit_ts.c.

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

Referenced by pg_last_committed_xact().

369 {
370  TransactionId xid;
371 
372  LWLockAcquire(CommitTsLock, LW_SHARED);
373 
374  /* Error if module not enabled */
377 
379  if (ts)
381  if (nodeid)
383  LWLockRelease(CommitTsLock);
384 
385  return xid;
386 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:95
uint32 TransactionId
Definition: c.h:514
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
TimestampTz time
Definition: commit_ts.c:59
TransactionId xidLastCommit
Definition: commit_ts.c:94
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
RepOriginId nodeid
Definition: commit_ts.c:60
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:389

◆ pg_last_committed_xact()

Datum pg_last_committed_xact ( PG_FUNCTION_ARGS  )

Definition at line 421 of file commit_ts.c.

References BlessTupleDesc(), CreateTemplateTupleDesc(), GetLatestCommitTsData(), heap_form_tuple(), HeapTupleGetDatum, PG_RETURN_DATUM, TimestampTzGetDatum, TransactionIdGetDatum, TransactionIdIsNormal, TupleDescInitEntry(), and values.

422 {
423  TransactionId xid;
424  TimestampTz ts;
425  Datum values[2];
426  bool nulls[2];
427  TupleDesc tupdesc;
428  HeapTuple htup;
429 
430  /* and construct a tuple with our data */
431  xid = GetLatestCommitTsData(&ts, NULL);
432 
433  /*
434  * Construct a tuple descriptor for the result row. This must match this
435  * function's pg_proc entry!
436  */
437  tupdesc = CreateTemplateTupleDesc(2);
438  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "xid",
439  XIDOID, -1, 0);
440  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "timestamp",
441  TIMESTAMPTZOID, -1, 0);
442  tupdesc = BlessTupleDesc(tupdesc);
443 
444  if (!TransactionIdIsNormal(xid))
445  {
446  memset(nulls, true, sizeof(nulls));
447  }
448  else
449  {
450  values[0] = TransactionIdGetDatum(xid);
451  nulls[0] = false;
452 
453  values[1] = TimestampTzGetDatum(ts);
454  nulls[1] = false;
455  }
456 
457  htup = heap_form_tuple(tupdesc, values, nulls);
458 
460 }
uint32 TransactionId
Definition: c.h:514
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:44
int64 TimestampTz
Definition: timestamp.h:39
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2052
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:603
#define TransactionIdGetDatum(X)
Definition: postgres.h:521
uintptr_t Datum
Definition: postgres.h:367
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:343
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
static Datum values[MAXATTR]
Definition: bootstrap.c:167
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
int16 AttrNumber
Definition: attnum.h:21
TransactionId GetLatestCommitTsData(TimestampTz *ts, RepOriginId *nodeid)
Definition: commit_ts.c:368

◆ pg_xact_commit_timestamp()

Datum pg_xact_commit_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 405 of file commit_ts.c.

References PG_GETARG_UINT32, PG_RETURN_NULL, PG_RETURN_TIMESTAMPTZ, and TransactionIdGetCommitTsData().

406 {
408  TimestampTz ts;
409  bool found;
410 
411  found = TransactionIdGetCommitTsData(xid, &ts, NULL);
412 
413  if (!found)
414  PG_RETURN_NULL();
415 
417 }
#define PG_GETARG_UINT32(n)
Definition: fmgr.h:265
uint32 TransactionId
Definition: c.h:514
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
bool TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts, RepOriginId *nodeid)
Definition: commit_ts.c:282
#define PG_RETURN_NULL()
Definition: fmgr.h:335

◆ SetCommitTsLimit()

void SetCommitTsLimit ( TransactionId  oldestXact,
TransactionId  newestXact 
)

Definition at line 848 of file commit_ts.c.

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

Referenced by BootStrapXLOG(), and StartupXLOG().

849 {
850  /*
851  * Be careful not to overwrite values that are either further into the
852  * "future" or signal a disabled committs.
853  */
854  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
856  {
861  }
862  else
863  {
867  }
868  LWLockRelease(CommitTsLock);
869 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
TransactionId oldestCommitTsXid
Definition: transam.h:176
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
#define Assert(condition)
Definition: c.h:739
TransactionId newestCommitTsXid
Definition: transam.h:177
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122

◆ SetXidCommitTsInPage()

static void SetXidCommitTsInPage ( TransactionId  xid,
int  nsubxids,
TransactionId subxids,
TimestampTz  ts,
RepOriginId  nodeid,
int  pageno 
)
static

Definition at line 231 of file commit_ts.c.

References CommitTsCtl, i, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), SimpleLruReadPage(), and TransactionIdSetCommitTs().

Referenced by TransactionTreeSetCommitTsData().

234 {
235  int slotno;
236  int i;
237 
238  LWLockAcquire(CommitTsControlLock, LW_EXCLUSIVE);
239 
240  slotno = SimpleLruReadPage(CommitTsCtl, pageno, true, xid);
241 
242  TransactionIdSetCommitTs(xid, ts, nodeid, slotno);
243  for (i = 0; i < nsubxids; i++)
244  TransactionIdSetCommitTs(subxids[i], ts, nodeid, slotno);
245 
246  CommitTsCtl->shared->page_dirty[slotno] = true;
247 
248  LWLockRelease(CommitTsControlLock);
249 }
#define CommitTsCtl
Definition: commit_ts.c:79
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
static void TransactionIdSetCommitTs(TransactionId xid, TimestampTz ts, RepOriginId nodeid, int slotno)
Definition: commit_ts.c:257
int SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok, TransactionId xid)
Definition: slru.c:374
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
int i

◆ ShutdownCommitTs()

void ShutdownCommitTs ( void  )

Definition at line 744 of file commit_ts.c.

References CommitTsCtl, fsync_fname(), and SimpleLruFlush().

Referenced by ShutdownXLOG().

745 {
746  /* Flush dirty CommitTs pages to disk */
747  SimpleLruFlush(CommitTsCtl, false);
748 
749  /*
750  * fsync pg_commit_ts to ensure that any files flushed previously are
751  * durably on disk.
752  */
753  fsync_fname("pg_commit_ts", true);
754 }
#define CommitTsCtl
Definition: commit_ts.c:79
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:617
void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1119

◆ StartupCommitTs()

void StartupCommitTs ( void  )

Definition at line 559 of file commit_ts.c.

References ActivateCommitTs().

Referenced by StartupXLOG().

560 {
562 }
static void ActivateCommitTs(void)
Definition: commit_ts.c:632

◆ TransactionIdGetCommitTsData()

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

Definition at line 282 of file commit_ts.c.

References Assert, CommitTimestampShared::commitTsActive, CommitTsCtl, 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().

284 {
285  int pageno = TransactionIdToCTsPage(xid);
286  int entryno = TransactionIdToCTsEntry(xid);
287  int slotno;
288  CommitTimestampEntry entry;
289  TransactionId oldestCommitTsXid;
290  TransactionId newestCommitTsXid;
291 
292  if (!TransactionIdIsValid(xid))
293  ereport(ERROR,
294  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
295  errmsg("cannot retrieve commit timestamp for transaction %u", xid)));
296  else if (!TransactionIdIsNormal(xid))
297  {
298  /* frozen and bootstrap xids are always committed far in the past */
299  *ts = 0;
300  if (nodeid)
301  *nodeid = 0;
302  return false;
303  }
304 
305  LWLockAcquire(CommitTsLock, LW_SHARED);
306 
307  /* Error if module not enabled */
310 
311  /*
312  * If we're asked for the cached value, return that. Otherwise, fall
313  * through to read from SLRU.
314  */
315  if (commitTsShared->xidLastCommit == xid)
316  {
318  if (nodeid)
320 
321  LWLockRelease(CommitTsLock);
322  return *ts != 0;
323  }
324 
325  oldestCommitTsXid = ShmemVariableCache->oldestCommitTsXid;
326  newestCommitTsXid = ShmemVariableCache->newestCommitTsXid;
327  /* neither is invalid, or both are */
328  Assert(TransactionIdIsValid(oldestCommitTsXid) == TransactionIdIsValid(newestCommitTsXid));
329  LWLockRelease(CommitTsLock);
330 
331  /*
332  * Return empty if the requested value is outside our valid range.
333  */
334  if (!TransactionIdIsValid(oldestCommitTsXid) ||
335  TransactionIdPrecedes(xid, oldestCommitTsXid) ||
336  TransactionIdPrecedes(newestCommitTsXid, xid))
337  {
338  *ts = 0;
339  if (nodeid)
340  *nodeid = InvalidRepOriginId;
341  return false;
342  }
343 
344  /* lock is acquired by SimpleLruReadPage_ReadOnly */
345  slotno = SimpleLruReadPage_ReadOnly(CommitTsCtl, pageno, xid);
346  memcpy(&entry,
347  CommitTsCtl->shared->page_buffer[slotno] +
348  SizeOfCommitTimestampEntry * entryno,
350 
351  *ts = entry.time;
352  if (nodeid)
353  *nodeid = entry.nodeid;
354 
355  LWLockRelease(CommitTsControlLock);
356  return *ts != 0;
357 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:95
uint32 TransactionId
Definition: c.h:514
#define SizeOfCommitTimestampEntry
Definition: commit_ts.c:63
#define CommitTsCtl
Definition: commit_ts.c:79
int errcode(int sqlerrcode)
Definition: elog.c:608
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ERROR
Definition: elog.h:43
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define ereport(elevel, rest)
Definition: elog.h:141
TransactionId oldestCommitTsXid
Definition: transam.h:176
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
TimestampTz time
Definition: commit_ts.c:59
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:69
TransactionId xidLastCommit
Definition: commit_ts.c:94
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
Definition: slru.c:466
#define Assert(condition)
Definition: c.h:739
TransactionId newestCommitTsXid
Definition: transam.h:177
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:71
#define InvalidRepOriginId
Definition: origin.h:33
int errmsg(const char *fmt,...)
Definition: elog.c:822
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
RepOriginId nodeid
Definition: commit_ts.c:60
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:389

◆ TransactionIdSetCommitTs()

static void TransactionIdSetCommitTs ( TransactionId  xid,
TimestampTz  ts,
RepOriginId  nodeid,
int  slotno 
)
static

Definition at line 257 of file commit_ts.c.

References Assert, CommitTsCtl, CommitTimestampEntry::nodeid, SizeOfCommitTimestampEntry, CommitTimestampEntry::time, TransactionIdIsNormal, and TransactionIdToCTsEntry.

Referenced by SetXidCommitTsInPage().

259 {
260  int entryno = TransactionIdToCTsEntry(xid);
261  CommitTimestampEntry entry;
262 
264 
265  entry.time = ts;
266  entry.nodeid = nodeid;
267 
268  memcpy(CommitTsCtl->shared->page_buffer[slotno] +
269  SizeOfCommitTimestampEntry * entryno,
271 }
#define SizeOfCommitTimestampEntry
Definition: commit_ts.c:63
#define CommitTsCtl
Definition: commit_ts.c:79
TimestampTz time
Definition: commit_ts.c:59
#define Assert(condition)
Definition: c.h:739
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:71
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
RepOriginId nodeid
Definition: commit_ts.c:60

◆ TransactionTreeSetCommitTsData()

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

Definition at line 145 of file commit_ts.c.

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

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

148 {
149  int i;
150  TransactionId headxid;
151  TransactionId newestXact;
152 
153  /*
154  * No-op if the module is not active.
155  *
156  * An unlocked read here is fine, because in a standby (the only place
157  * where the flag can change in flight) this routine is only called by the
158  * recovery process, which is also the only process which can change the
159  * flag.
160  */
162  return;
163 
164  /*
165  * Comply with the WAL-before-data rule: if caller specified it wants this
166  * value to be recorded in WAL, do so before touching the data.
167  */
168  if (write_xlog)
169  WriteSetTimestampXlogRec(xid, nsubxids, subxids, timestamp, nodeid);
170 
171  /*
172  * Figure out the latest Xid in this batch: either the last subxid if
173  * there's any, otherwise the parent xid.
174  */
175  if (nsubxids > 0)
176  newestXact = subxids[nsubxids - 1];
177  else
178  newestXact = xid;
179 
180  /*
181  * We split the xids to set the timestamp to in groups belonging to the
182  * same SLRU page; the first element in each such set is its head. The
183  * first group has the main XID as the head; subsequent sets use the first
184  * subxid not on the previous page as head. This way, we only have to
185  * lock/modify each SLRU page once.
186  */
187  for (i = 0, headxid = xid;;)
188  {
189  int pageno = TransactionIdToCTsPage(headxid);
190  int j;
191 
192  for (j = i; j < nsubxids; j++)
193  {
194  if (TransactionIdToCTsPage(subxids[j]) != pageno)
195  break;
196  }
197  /* subxids[i..j] are on the same page as the head */
198 
199  SetXidCommitTsInPage(headxid, j - i, subxids + i, timestamp, nodeid,
200  pageno);
201 
202  /* if we wrote out all subxids, we're done. */
203  if (j + 1 >= nsubxids)
204  break;
205 
206  /*
207  * Set the new head and skip over it, as well as over the subxids we
208  * just wrote.
209  */
210  headxid = subxids[j];
211  i += j - i + 1;
212  }
213 
214  /* update the cached value in shared memory */
215  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
219 
220  /* and move forwards our endpoint, if needed */
223  LWLockRelease(CommitTsLock);
224 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:95
uint32 TransactionId
Definition: c.h:514
static void WriteSetTimestampXlogRec(TransactionId mainxid, int nsubxids, TransactionId *subxids, TimestampTz timestamp, RepOriginId nodeid)
Definition: commit_ts.c:941
int64 timestamp
static void SetXidCommitTsInPage(TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz ts, RepOriginId nodeid, int pageno)
Definition: commit_ts.c:231
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
VariableCache ShmemVariableCache
Definition: varsup.c:34
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
TimestampTz time
Definition: commit_ts.c:59
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:69
TransactionId xidLastCommit
Definition: commit_ts.c:94
TransactionId newestCommitTsXid
Definition: transam.h:177
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
int i
RepOriginId nodeid
Definition: commit_ts.c:60
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:99

◆ TruncateCommitTs()

void TruncateCommitTs ( TransactionId  oldestXact)

Definition at line 822 of file commit_ts.c.

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

Referenced by vac_truncate_clog().

823 {
824  int cutoffPage;
825 
826  /*
827  * The cutoff point is the start of the segment containing oldestXact. We
828  * pass the *page* containing oldestXact to SimpleLruTruncate.
829  */
830  cutoffPage = TransactionIdToCTsPage(oldestXact);
831 
832  /* Check to see if there's any files that could be removed */
834  &cutoffPage))
835  return; /* nothing to remove */
836 
837  /* Write XLOG record */
838  WriteTruncateXlogRec(cutoffPage, oldestXact);
839 
840  /* Now we can remove the old CommitTs segment(s) */
841  SimpleLruTruncate(CommitTsCtl, cutoffPage);
842 }
#define CommitTsCtl
Definition: commit_ts.c:79
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1184
static void WriteTruncateXlogRec(int pageno, TransactionId oldestXid)
Definition: commit_ts.c:925
bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename, int segpage, void *data)
Definition: slru.c:1337
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:69
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1392

◆ WriteSetTimestampXlogRec()

static void WriteSetTimestampXlogRec ( TransactionId  mainxid,
int  nsubxids,
TransactionId subxids,
TimestampTz  timestamp,
RepOriginId  nodeid 
)
static

Definition at line 941 of file commit_ts.c.

References COMMIT_TS_SETTS, xl_commit_ts_set::mainxid, xl_commit_ts_set::nodeid, CommitTimestampEntry::nodeid, offsetof, xl_commit_ts_set::timestamp, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().

Referenced by TransactionTreeSetCommitTsData().

944 {
945  xl_commit_ts_set record;
946 
947  record.timestamp = timestamp;
948  record.nodeid = nodeid;
949  record.mainxid = mainxid;
950 
951  XLogBeginInsert();
952  XLogRegisterData((char *) &record,
953  offsetof(xl_commit_ts_set, mainxid) +
954  sizeof(TransactionId));
955  XLogRegisterData((char *) subxids, nsubxids * sizeof(TransactionId));
956  XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_SETTS);
957 }
#define COMMIT_TS_SETTS
Definition: commit_ts.h:51
uint32 TransactionId
Definition: c.h:514
int64 timestamp
TimestampTz timestamp
Definition: commit_ts.h:55
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
TransactionId mainxid
Definition: commit_ts.h:57
RepOriginId nodeid
Definition: commit_ts.h:56
void XLogBeginInsert(void)
Definition: xloginsert.c:120
#define offsetof(type, field)
Definition: c.h:662

◆ WriteTruncateXlogRec()

static void WriteTruncateXlogRec ( int  pageno,
TransactionId  oldestXid 
)
static

Definition at line 925 of file commit_ts.c.

References COMMIT_TS_TRUNCATE, xl_commit_ts_truncate::oldestXid, xl_commit_ts_truncate::pageno, SizeOfCommitTsTruncate, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().

Referenced by TruncateCommitTs().

926 {
927  xl_commit_ts_truncate xlrec;
928 
929  xlrec.pageno = pageno;
930  xlrec.oldestXid = oldestXid;
931 
932  XLogBeginInsert();
933  XLogRegisterData((char *) (&xlrec), SizeOfCommitTsTruncate);
934  (void) XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_TRUNCATE);
935 }
TransactionId oldestXid
Definition: commit_ts.h:67
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
#define COMMIT_TS_TRUNCATE
Definition: commit_ts.h:50
void XLogBeginInsert(void)
Definition: xloginsert.c:120
#define SizeOfCommitTsTruncate
Definition: commit_ts.h:70

◆ WriteZeroPageXlogRec()

static void WriteZeroPageXlogRec ( int  pageno)
static

Definition at line 914 of file commit_ts.c.

References COMMIT_TS_ZEROPAGE, XLogBeginInsert(), XLogInsert(), and XLogRegisterData().

Referenced by ZeroCommitTsPage().

915 {
916  XLogBeginInsert();
917  XLogRegisterData((char *) (&pageno), sizeof(int));
918  (void) XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_ZEROPAGE);
919 }
#define COMMIT_TS_ZEROPAGE
Definition: commit_ts.h:49
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:323
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:415
void XLogBeginInsert(void)
Definition: xloginsert.c:120

◆ ZeroCommitTsPage()

static int ZeroCommitTsPage ( int  pageno,
bool  writeXlog 
)
static

Definition at line 542 of file commit_ts.c.

References CommitTsCtl, SimpleLruZeroPage(), and WriteZeroPageXlogRec().

Referenced by ActivateCommitTs(), commit_ts_redo(), and ExtendCommitTs().

543 {
544  int slotno;
545 
546  slotno = SimpleLruZeroPage(CommitTsCtl, pageno);
547 
548  if (writeXlog)
549  WriteZeroPageXlogRec(pageno);
550 
551  return slotno;
552 }
#define CommitTsCtl
Definition: commit_ts.c:79
static void WriteZeroPageXlogRec(int pageno)
Definition: commit_ts.c:914
int SimpleLruZeroPage(SlruCtl ctl, int pageno)
Definition: slru.c:262

Variable Documentation

◆ CommitTsCtlData

SlruCtlData CommitTsCtlData
static

Definition at line 77 of file commit_ts.c.

◆ commitTsShared

CommitTimestampShared* commitTsShared

Definition at line 99 of file commit_ts.c.

◆ track_commit_timestamp

bool track_commit_timestamp