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 "access/xlogutils.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)
 
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)
 
Datum pg_xact_commit_timestamp (PG_FUNCTION_ARGS)
 
Datum pg_last_committed_xact (PG_FUNCTION_ARGS)
 
Datum pg_xact_commit_timestamp_origin (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 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)
 
int committssyncfiletag (const FileTag *ftag, char *path)
 

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

Referenced by CommitTsPagePrecedes(), and CommitTsShmemInit().

◆ CommitTsCtl

◆ SizeOfCommitTimestampEntry

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

Definition at line 64 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 679 of file commit_ts.c.

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

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

680 {
681  TransactionId xid;
682  int pageno;
683 
684  /* If we've done this already, there's nothing to do */
685  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
687  {
688  LWLockRelease(CommitTsLock);
689  return;
690  }
691  LWLockRelease(CommitTsLock);
692 
694  pageno = TransactionIdToCTsPage(xid);
695 
696  /*
697  * Re-Initialize our idea of the latest page number.
698  */
699  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
700  CommitTsCtl->shared->latest_page_number = pageno;
701  LWLockRelease(CommitTsSLRULock);
702 
703  /*
704  * If CommitTs is enabled, but it wasn't in the previous server run, we
705  * need to set the oldest and newest values to the next Xid; that way, we
706  * will not try to read data that might not have been set.
707  *
708  * XXX does this have a problem if a server is started with commitTs
709  * enabled, then started with commitTs disabled, then restarted with it
710  * enabled again? It doesn't look like it does, because there should be a
711  * checkpoint that sets the value to InvalidTransactionId at end of
712  * recovery; and so any chance of injecting new transactions without
713  * CommitTs values would occur after the oldestCommitTsXid has been set to
714  * Invalid temporarily.
715  */
716  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
718  {
721  }
722  LWLockRelease(CommitTsLock);
723 
724  /* Create the current segment file, if necessary */
726  {
727  int slotno;
728 
729  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
730  slotno = ZeroCommitTsPage(pageno, false);
732  Assert(!CommitTsCtl->shared->page_dirty[slotno]);
733  LWLockRelease(CommitTsSLRULock);
734  }
735 
736  /* Change the activation status in shared memory. */
737  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
739  LWLockRelease(CommitTsLock);
740 }
uint32 TransactionId
Definition: c.h:587
#define CommitTsCtl
Definition: commit_ts.c:80
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:589
static TransactionId ReadNextTransactionId(void)
Definition: transam.h:316
FullTransactionId nextXid
Definition: transam.h:220
#define XidFromFullTransactionId(x)
Definition: transam.h:48
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
bool SimpleLruDoesPhysicalPageExist(SlruCtl ctl, int pageno)
Definition: slru.c:626
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:614
TransactionId oldestCommitTsXid
Definition: transam.h:232
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:70
#define Assert(condition)
Definition: c.h:804
TransactionId newestCommitTsXid
Definition: transam.h:233
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100

◆ AdvanceOldestCommitTsXid()

void AdvanceOldestCommitTsXid ( TransactionId  oldestXact)

Definition at line 904 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().

905 {
906  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
910  LWLockRelease(CommitTsLock);
911 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
TransactionId oldestCommitTsXid
Definition: transam.h:232
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199

◆ BootStrapCommitTs()

void BootStrapCommitTs ( void  )

Definition at line 570 of file commit_ts.c.

Referenced by BootStrapXLOG().

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

◆ CheckPointCommitTs()

void CheckPointCommitTs ( void  )

Definition at line 791 of file commit_ts.c.

References CommitTsCtl, and SimpleLruWriteAll().

Referenced by CheckPointGuts().

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

◆ commit_ts_redo()

void commit_ts_redo ( XLogReaderState record)

Definition at line 984 of file commit_ts.c.

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().

985 {
986  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
987 
988  /* Backup blocks are not used in commit_ts records */
989  Assert(!XLogRecHasAnyBlockRefs(record));
990 
991  if (info == COMMIT_TS_ZEROPAGE)
992  {
993  int pageno;
994  int slotno;
995 
996  memcpy(&pageno, XLogRecGetData(record), sizeof(int));
997 
998  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
999 
1000  slotno = ZeroCommitTsPage(pageno, false);
1002  Assert(!CommitTsCtl->shared->page_dirty[slotno]);
1003 
1004  LWLockRelease(CommitTsSLRULock);
1005  }
1006  else if (info == COMMIT_TS_TRUNCATE)
1007  {
1009 
1011 
1012  /*
1013  * During XLOG replay, latest_page_number isn't set up yet; insert a
1014  * suitable value to bypass the sanity test in SimpleLruTruncate.
1015  */
1016  CommitTsCtl->shared->latest_page_number = trunc->pageno;
1017 
1019  }
1020  else
1021  elog(PANIC, "commit_ts_redo: unknown op code %u", info);
1022 }
#define COMMIT_TS_ZEROPAGE
Definition: commit_ts.h:51
#define CommitTsCtl
Definition: commit_ts.c:80
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:589
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1226
unsigned char uint8
Definition: c.h:439
#define PANIC
Definition: elog.h:50
void AdvanceOldestCommitTsXid(TransactionId oldestXact)
Definition: commit_ts.c:904
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
#define XLogRecGetData(decoder)
Definition: xlogreader.h:310
TransactionId oldestXid
Definition: commit_ts.h:68
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:614
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:305
#define COMMIT_TS_TRUNCATE
Definition: commit_ts.h:52
#define Assert(condition)
Definition: c.h:804
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
#define elog(elevel,...)
Definition: elog.h:232
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:312

◆ CommitTsPagePrecedes()

static bool CommitTsPagePrecedes ( int  page1,
int  page2 
)
static

Definition at line 938 of file commit_ts.c.

References COMMIT_TS_XACTS_PER_PAGE, FirstNormalTransactionId, and TransactionIdPrecedes().

Referenced by CommitTsShmemInit().

939 {
940  TransactionId xid1;
941  TransactionId xid2;
942 
943  xid1 = ((TransactionId) page1) * COMMIT_TS_XACTS_PER_PAGE;
944  xid1 += FirstNormalTransactionId + 1;
945  xid2 = ((TransactionId) page2) * COMMIT_TS_XACTS_PER_PAGE;
946  xid2 += FirstNormalTransactionId + 1;
947 
948  return (TransactionIdPrecedes(xid1, xid2) &&
950 }
uint32 TransactionId
Definition: c.h:587
#define FirstNormalTransactionId
Definition: transam.h:34
#define COMMIT_TS_XACTS_PER_PAGE
Definition: commit_ts.c:67
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300

◆ CommitTsParameterChange()

void CommitTsParameterChange ( bool  newvalue,
bool  oldvalue 
)

Definition at line 638 of file commit_ts.c.

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

Referenced by xlog_redo().

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

◆ CommitTsShmemBuffers()

Size CommitTsShmemBuffers ( void  )

Definition at line 515 of file commit_ts.c.

References Max, Min, and NBuffers.

Referenced by CommitTsShmemInit(), and CommitTsShmemSize().

516 {
517  return Min(16, Max(4, NBuffers / 1024));
518 }
#define Min(x, y)
Definition: c.h:986
#define Max(x, y)
Definition: c.h:980
int NBuffers
Definition: globals.c:135

◆ CommitTsShmemInit()

void CommitTsShmemInit ( void  )

Definition at line 535 of file commit_ts.c.

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

536 {
537  bool found;
538 
539  CommitTsCtl->PagePrecedes = CommitTsPagePrecedes;
541  CommitTsSLRULock, "pg_commit_ts",
545 
546  commitTsShared = ShmemInitStruct("CommitTs shared",
547  sizeof(CommitTimestampShared),
548  &found);
549 
550  if (!IsUnderPostmaster)
551  {
552  Assert(!found);
553 
558  }
559  else
560  Assert(found);
561 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:96
#define CommitTsCtl
Definition: commit_ts.c:80
Size CommitTsShmemBuffers(void)
Definition: commit_ts.c:515
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 COMMIT_TS_XACTS_PER_PAGE
Definition: commit_ts.c:67
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:396
bool IsUnderPostmaster
Definition: globals.c:112
#define InvalidTransactionId
Definition: transam.h:31
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:112
TimestampTz time
Definition: commit_ts.c:60
static bool CommitTsPagePrecedes(int page1, int page2)
Definition: commit_ts.c:938
TransactionId xidLastCommit
Definition: commit_ts.c:95
#define Assert(condition)
Definition: c.h:804
#define InvalidRepOriginId
Definition: origin.h:33
#define SlruPagePrecedesUnitTests(ctl, per_page)
Definition: slru.h:156
RepOriginId nodeid
Definition: commit_ts.c:61
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100

◆ CommitTsShmemSize()

Size CommitTsShmemSize ( void  )

Definition at line 524 of file commit_ts.c.

References CommitTsShmemBuffers(), and SimpleLruShmemSize().

Referenced by CreateSharedMemoryAndSemaphores().

525 {
527  sizeof(CommitTimestampShared);
528 }
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:156
Size CommitTsShmemBuffers(void)
Definition: commit_ts.c:515
struct CommitTimestampShared CommitTimestampShared

◆ committssyncfiletag()

int committssyncfiletag ( const FileTag ftag,
char *  path 
)

Definition at line 1028 of file commit_ts.c.

References CommitTsCtl, and SlruSyncFileTag().

1029 {
1030  return SlruSyncFileTag(CommitTsCtl, ftag, path);
1031 }
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
Definition: slru.c:1593
#define CommitTsCtl
Definition: commit_ts.c:80

◆ CompleteCommitTsInitialization()

void CompleteCommitTsInitialization ( void  )

Definition at line 616 of file commit_ts.c.

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

Referenced by StartupXLOG().

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

◆ DeactivateCommitTs()

static void DeactivateCommitTs ( void  )
static

Definition at line 753 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().

754 {
755  /*
756  * Cleanup the status in the shared memory.
757  *
758  * We reset everything in the commitTsShared record to prevent user from
759  * getting confusing data about last committed transaction on the standby
760  * when the module was activated repeatedly on the primary.
761  */
762  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
763 
768 
771 
772  LWLockRelease(CommitTsLock);
773 
774  /*
775  * Remove *all* files. This is necessary so that there are no leftover
776  * files; in the case where this feature is later enabled after running
777  * with it disabled for some time there may be a gap in the file sequence.
778  * (We can probably tolerate out-of-sequence files, as they are going to
779  * be overwritten anyway when we wrap around, but it seems better to be
780  * tidy.)
781  */
782  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
784  LWLockRelease(CommitTsSLRULock);
785 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:96
bool SlruScanDirCbDeleteAll(SlruCtl ctl, char *filename, int segpage, void *data)
Definition: slru.c:1530
#define CommitTsCtl
Definition: commit_ts.c:80
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
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:232
TimestampTz time
Definition: commit_ts.c:60
TransactionId xidLastCommit
Definition: commit_ts.c:95
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1553
TransactionId newestCommitTsXid
Definition: transam.h:233
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
#define InvalidRepOriginId
Definition: origin.h:33
RepOriginId nodeid
Definition: commit_ts.c:61
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100

◆ error_commit_ts_disabled()

static void error_commit_ts_disabled ( void  )
static

Definition at line 373 of file commit_ts.c.

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

Referenced by GetLatestCommitTsData(), and TransactionIdGetCommitTsData().

374 {
375  ereport(ERROR,
376  (errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
377  errmsg("could not get commit timestamp data"),
379  errhint("Make sure the configuration parameter \"%s\" is set on the primary server.",
380  "track_commit_timestamp") :
381  errhint("Make sure the configuration parameter \"%s\" is set.",
382  "track_commit_timestamp")));
383 }
int errhint(const char *fmt,...)
Definition: elog.c:1156
int errcode(int sqlerrcode)
Definition: elog.c:698
bool RecoveryInProgress(void)
Definition: xlog.c:8211
#define ERROR
Definition: elog.h:46
#define ereport(elevel,...)
Definition: elog.h:157
int errmsg(const char *fmt,...)
Definition: elog.c:909

◆ ExtendCommitTs()

void ExtendCommitTs ( TransactionId  newestXact)

Definition at line 813 of file commit_ts.c.

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

Referenced by GetNewTransactionId().

814 {
815  int pageno;
816 
817  /*
818  * Nothing to do if module not enabled. Note we do an unlocked read of
819  * the flag here, which is okay because this routine is only called from
820  * GetNewTransactionId, which is never called in a standby.
821  */
822  Assert(!InRecovery);
824  return;
825 
826  /*
827  * No work except at first XID of a page. But beware: just after
828  * wraparound, the first XID of page zero is FirstNormalTransactionId.
829  */
830  if (TransactionIdToCTsEntry(newestXact) != 0 &&
832  return;
833 
834  pageno = TransactionIdToCTsPage(newestXact);
835 
836  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
837 
838  /* Zero the page and make an XLOG entry about it */
839  ZeroCommitTsPage(pageno, !InRecovery);
840 
841  LWLockRelease(CommitTsSLRULock);
842 }
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
static int ZeroCommitTsPage(int pageno, bool writeXlog)
Definition: commit_ts.c:589
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
#define FirstNormalTransactionId
Definition: transam.h:34
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:70
bool InRecovery
Definition: xlogutils.c:52
#define Assert(condition)
Definition: c.h:804
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:72
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100

◆ GetLatestCommitTsData()

TransactionId GetLatestCommitTsData ( TimestampTz ts,
RepOriginId nodeid 
)

Definition at line 352 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().

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 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:96
uint32 TransactionId
Definition: c.h:587
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
TimestampTz time
Definition: commit_ts.c:60
TransactionId xidLastCommit
Definition: commit_ts.c:95
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
RepOriginId nodeid
Definition: commit_ts.c:61
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:373

◆ pg_last_committed_xact()

Datum pg_last_committed_xact ( PG_FUNCTION_ARGS  )

Definition at line 412 of file commit_ts.c.

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

413 {
414  TransactionId xid;
415  RepOriginId nodeid;
416  TimestampTz ts;
417  Datum values[3];
418  bool nulls[3];
419  TupleDesc tupdesc;
420  HeapTuple htup;
421 
422  /* and construct a tuple with our data */
423  xid = GetLatestCommitTsData(&ts, &nodeid);
424 
425  /*
426  * Construct a tuple descriptor for the result row. This must match this
427  * function's pg_proc entry!
428  */
429  tupdesc = CreateTemplateTupleDesc(3);
430  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "xid",
431  XIDOID, -1, 0);
432  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "timestamp",
433  TIMESTAMPTZOID, -1, 0);
434  TupleDescInitEntry(tupdesc, (AttrNumber) 3, "roident",
435  OIDOID, -1, 0);
436  tupdesc = BlessTupleDesc(tupdesc);
437 
438  if (!TransactionIdIsNormal(xid))
439  {
440  memset(nulls, true, sizeof(nulls));
441  }
442  else
443  {
444  values[0] = TransactionIdGetDatum(xid);
445  nulls[0] = false;
446 
447  values[1] = TimestampTzGetDatum(ts);
448  nulls[1] = false;
449 
450  values[2] = ObjectIdGetDatum((Oid) nodeid);
451  nulls[2] = false;
452  }
453 
454  htup = heap_form_tuple(tupdesc, values, nulls);
455 
457 }
uint32 TransactionId
Definition: c.h:587
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
int64 TimestampTz
Definition: timestamp.h:39
uint16 RepOriginId
Definition: xlogdefs.h:65
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
#define TransactionIdGetDatum(X)
Definition: postgres.h:565
uintptr_t Datum
Definition: postgres.h:411
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
static Datum values[MAXATTR]
Definition: bootstrap.c:166
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
int16 AttrNumber
Definition: attnum.h:21
TransactionId GetLatestCommitTsData(TimestampTz *ts, RepOriginId *nodeid)
Definition: commit_ts.c:352

◆ pg_xact_commit_timestamp()

Datum pg_xact_commit_timestamp ( PG_FUNCTION_ARGS  )

Definition at line 389 of file commit_ts.c.

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

390 {
392  TimestampTz ts;
393  bool found;
394 
395  found = TransactionIdGetCommitTsData(xid, &ts, NULL);
396 
397  if (!found)
398  PG_RETURN_NULL();
399 
401 }
uint32 TransactionId
Definition: c.h:587
int64 TimestampTz
Definition: timestamp.h:39
#define PG_RETURN_TIMESTAMPTZ(x)
Definition: timestamp.h:40
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
bool TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts, RepOriginId *nodeid)
Definition: commit_ts.c:266
#define PG_RETURN_NULL()
Definition: fmgr.h:345

◆ pg_xact_commit_timestamp_origin()

Datum pg_xact_commit_timestamp_origin ( PG_FUNCTION_ARGS  )

Definition at line 466 of file commit_ts.c.

References BlessTupleDesc(), CreateTemplateTupleDesc(), heap_form_tuple(), HeapTupleGetDatum, CommitTimestampEntry::nodeid, ObjectIdGetDatum, PG_GETARG_TRANSACTIONID, PG_RETURN_DATUM, TimestampTzGetDatum, TransactionIdGetCommitTsData(), TupleDescInitEntry(), and values.

467 {
469  RepOriginId nodeid;
470  TimestampTz ts;
471  Datum values[2];
472  bool nulls[2];
473  TupleDesc tupdesc;
474  HeapTuple htup;
475  bool found;
476 
477  found = TransactionIdGetCommitTsData(xid, &ts, &nodeid);
478 
479  /*
480  * Construct a tuple descriptor for the result row. This must match this
481  * function's pg_proc entry!
482  */
483  tupdesc = CreateTemplateTupleDesc(2);
484  TupleDescInitEntry(tupdesc, (AttrNumber) 1, "timestamp",
485  TIMESTAMPTZOID, -1, 0);
486  TupleDescInitEntry(tupdesc, (AttrNumber) 2, "roident",
487  OIDOID, -1, 0);
488  tupdesc = BlessTupleDesc(tupdesc);
489 
490  if (!found)
491  {
492  memset(nulls, true, sizeof(nulls));
493  }
494  else
495  {
496  values[0] = TimestampTzGetDatum(ts);
497  nulls[0] = false;
498 
499  values[1] = ObjectIdGetDatum((Oid) nodeid);
500  nulls[1] = false;
501  }
502 
503  htup = heap_form_tuple(tupdesc, values, nulls);
504 
506 }
uint32 TransactionId
Definition: c.h:587
TupleDesc CreateTemplateTupleDesc(int natts)
Definition: tupdesc.c:45
int64 TimestampTz
Definition: timestamp.h:39
uint16 RepOriginId
Definition: xlogdefs.h:65
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Definition: heaptuple.c:1020
unsigned int Oid
Definition: postgres_ext.h:31
#define ObjectIdGetDatum(X)
Definition: postgres.h:551
#define TimestampTzGetDatum(X)
Definition: timestamp.h:32
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
Definition: execTuples.c:2082
#define PG_GETARG_TRANSACTIONID(n)
Definition: fmgr.h:279
void TupleDescInitEntry(TupleDesc desc, AttrNumber attributeNumber, const char *attributeName, Oid oidtypeid, int32 typmod, int attdim)
Definition: tupdesc.c:583
bool TransactionIdGetCommitTsData(TransactionId xid, TimestampTz *ts, RepOriginId *nodeid)
Definition: commit_ts.c:266
uintptr_t Datum
Definition: postgres.h:411
#define PG_RETURN_DATUM(x)
Definition: fmgr.h:353
#define HeapTupleGetDatum(tuple)
Definition: funcapi.h:220
static Datum values[MAXATTR]
Definition: bootstrap.c:166
int16 AttrNumber
Definition: attnum.h:21

◆ SetCommitTsLimit()

void SetCommitTsLimit ( TransactionId  oldestXact,
TransactionId  newestXact 
)

Definition at line 877 of file commit_ts.c.

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

Referenced by BootStrapXLOG(), and StartupXLOG().

878 {
879  /*
880  * Be careful not to overwrite values that are either further into the
881  * "future" or signal a disabled committs.
882  */
883  LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
885  {
890  }
891  else
892  {
896  }
897  LWLockRelease(CommitTsLock);
898 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define InvalidTransactionId
Definition: transam.h:31
TransactionId oldestCommitTsXid
Definition: transam.h:232
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
#define Assert(condition)
Definition: c.h:804
TransactionId newestCommitTsXid
Definition: transam.h:233
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199

◆ SetXidCommitTsInPage()

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

Definition at line 215 of file commit_ts.c.

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

Referenced by TransactionTreeSetCommitTsData().

218 {
219  int slotno;
220  int i;
221 
222  LWLockAcquire(CommitTsSLRULock, LW_EXCLUSIVE);
223 
224  slotno = SimpleLruReadPage(CommitTsCtl, pageno, true, xid);
225 
226  TransactionIdSetCommitTs(xid, ts, nodeid, slotno);
227  for (i = 0; i < nsubxids; i++)
228  TransactionIdSetCommitTs(subxids[i], ts, nodeid, slotno);
229 
230  CommitTsCtl->shared->page_dirty[slotno] = true;
231 
232  LWLockRelease(CommitTsSLRULock);
233 }
#define CommitTsCtl
Definition: commit_ts.c:80
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
static void TransactionIdSetCommitTs(TransactionId xid, TimestampTz ts, RepOriginId nodeid, int slotno)
Definition: commit_ts.c:241
int SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok, TransactionId xid)
Definition: slru.c:395
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
int i

◆ StartupCommitTs()

void StartupCommitTs ( void  )

Definition at line 606 of file commit_ts.c.

References ActivateCommitTs().

Referenced by StartupXLOG().

607 {
609 }
static void ActivateCommitTs(void)
Definition: commit_ts.c:679

◆ TransactionIdGetCommitTsData()

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

Definition at line 266 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(), and pg_xact_commit_timestamp_origin().

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 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:96
uint32 TransactionId
Definition: c.h:587
#define SizeOfCommitTimestampEntry
Definition: commit_ts.c:64
#define CommitTsCtl
Definition: commit_ts.c:80
int errcode(int sqlerrcode)
Definition: elog.c:698
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
#define ERROR
Definition: elog.h:46
VariableCache ShmemVariableCache
Definition: varsup.c:34
TransactionId oldestCommitTsXid
Definition: transam.h:232
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
TimestampTz time
Definition: commit_ts.c:60
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:70
TransactionId xidLastCommit
Definition: commit_ts.c:95
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
Definition: slru.c:495
#define ereport(elevel,...)
Definition: elog.h:157
#define Assert(condition)
Definition: c.h:804
TransactionId newestCommitTsXid
Definition: transam.h:233
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:72
#define InvalidRepOriginId
Definition: origin.h:33
int errmsg(const char *fmt,...)
Definition: elog.c:909
#define TransactionIdIsValid(xid)
Definition: transam.h:41
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
RepOriginId nodeid
Definition: commit_ts.c:61
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:373

◆ TransactionIdSetCommitTs()

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

Definition at line 241 of file commit_ts.c.

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

Referenced by SetXidCommitTsInPage().

243 {
244  int entryno = TransactionIdToCTsEntry(xid);
245  CommitTimestampEntry entry;
246 
248 
249  entry.time = ts;
250  entry.nodeid = nodeid;
251 
252  memcpy(CommitTsCtl->shared->page_buffer[slotno] +
253  SizeOfCommitTimestampEntry * entryno,
255 }
#define SizeOfCommitTimestampEntry
Definition: commit_ts.c:64
#define CommitTsCtl
Definition: commit_ts.c:80
TimestampTz time
Definition: commit_ts.c:60
#define Assert(condition)
Definition: c.h:804
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:72
#define TransactionIdIsNormal(xid)
Definition: transam.h:42
RepOriginId nodeid
Definition: commit_ts.c:61

◆ TransactionTreeSetCommitTsData()

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

Definition at line 136 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, and CommitTimestampShared::xidLastCommit.

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

139 {
140  int i;
141  TransactionId headxid;
142  TransactionId newestXact;
143 
144  /*
145  * No-op if the module is not active.
146  *
147  * An unlocked read here is fine, because in a standby (the only place
148  * where the flag can change in flight) this routine is only called by the
149  * recovery process, which is also the only process which can change the
150  * flag.
151  */
153  return;
154 
155  /*
156  * Figure out the latest Xid in this batch: either the last subxid if
157  * there's any, otherwise the parent xid.
158  */
159  if (nsubxids > 0)
160  newestXact = subxids[nsubxids - 1];
161  else
162  newestXact = xid;
163 
164  /*
165  * We split the xids to set the timestamp to in groups belonging to the
166  * same SLRU page; the first element in each such set is its head. The
167  * first group has the main XID as the head; subsequent sets use the first
168  * subxid not on the previous page as head. This way, we only have to
169  * lock/modify each SLRU page once.
170  */
171  for (i = 0, headxid = xid;;)
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 + 1 >= 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 - i + 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 }
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:96
uint32 TransactionId
Definition: c.h:587
int64 timestamp
static void SetXidCommitTsInPage(TransactionId xid, int nsubxids, TransactionId *subxids, TimestampTz ts, RepOriginId nodeid, int pageno)
Definition: commit_ts.c:215
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1803
VariableCache ShmemVariableCache
Definition: varsup.c:34
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:300
TimestampTz time
Definition: commit_ts.c:60
#define TransactionIdToCTsPage(xid)
Definition: commit_ts.c:70
TransactionId xidLastCommit
Definition: commit_ts.c:95
TransactionId newestCommitTsXid
Definition: transam.h:233
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1199
int i
RepOriginId nodeid
Definition: commit_ts.c:61
CommitTimestampShared * commitTsShared
Definition: commit_ts.c:100

◆ TruncateCommitTs()

void TruncateCommitTs ( TransactionId  oldestXact)

Definition at line 851 of file commit_ts.c.

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

Referenced by vac_truncate_clog().

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

◆ WriteTruncateXlogRec()

static void WriteTruncateXlogRec ( int  pageno,
TransactionId  oldestXid 
)
static

Definition at line 968 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().

969 {
970  xl_commit_ts_truncate xlrec;
971 
972  xlrec.pageno = pageno;
973  xlrec.oldestXid = oldestXid;
974 
975  XLogBeginInsert();
976  XLogRegisterData((char *) (&xlrec), SizeOfCommitTsTruncate);
977  (void) XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_TRUNCATE);
978 }
TransactionId oldestXid
Definition: commit_ts.h:68
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:340
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:432
#define COMMIT_TS_TRUNCATE
Definition: commit_ts.h:52
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define SizeOfCommitTsTruncate
Definition: commit_ts.h:71

◆ WriteZeroPageXlogRec()

static void WriteZeroPageXlogRec ( int  pageno)
static

Definition at line 957 of file commit_ts.c.

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

Referenced by ZeroCommitTsPage().

958 {
959  XLogBeginInsert();
960  XLogRegisterData((char *) (&pageno), sizeof(int));
961  (void) XLogInsert(RM_COMMIT_TS_ID, COMMIT_TS_ZEROPAGE);
962 }
#define COMMIT_TS_ZEROPAGE
Definition: commit_ts.h:51
void XLogRegisterData(char *data, int len)
Definition: xloginsert.c:340
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:432
void XLogBeginInsert(void)
Definition: xloginsert.c:135

◆ ZeroCommitTsPage()

static int ZeroCommitTsPage ( int  pageno,
bool  writeXlog 
)
static

Definition at line 589 of file commit_ts.c.

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

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

590 {
591  int slotno;
592 
593  slotno = SimpleLruZeroPage(CommitTsCtl, pageno);
594 
595  if (writeXlog)
596  WriteZeroPageXlogRec(pageno);
597 
598  return slotno;
599 }
#define CommitTsCtl
Definition: commit_ts.c:80
static void WriteZeroPageXlogRec(int pageno)
Definition: commit_ts.c:957
int SimpleLruZeroPage(SlruCtl ctl, int pageno)
Definition: slru.c:280

Variable Documentation

◆ CommitTsCtlData

SlruCtlData CommitTsCtlData
static

Definition at line 78 of file commit_ts.c.

◆ commitTsShared

CommitTimestampShared* commitTsShared

Definition at line 100 of file commit_ts.c.

◆ track_commit_timestamp

bool track_commit_timestamp