PostgreSQL Source Code git master
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 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 47 of file commit_ts.h.

◆ COMMIT_TS_ZEROPAGE

#define COMMIT_TS_ZEROPAGE   0x00

Definition at line 46 of file commit_ts.h.

◆ SizeOfCommitTsSet

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

Definition at line 57 of file commit_ts.h.

◆ SizeOfCommitTsTruncate

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

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

937{
938 LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
942 LWLockRelease(CommitTsLock);
943}
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1168
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1781
@ LW_EXCLUSIVE
Definition: lwlock.h:114
TransactionId oldestCommitTsXid
Definition: transam.h:232
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
Definition: transam.c:280
#define InvalidTransactionId
Definition: transam.h:31
TransamVariablesData * TransamVariables
Definition: varsup.c:34

References InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransamVariablesData::oldestCommitTsXid, TransactionIdPrecedes(), and TransamVariables.

Referenced by commit_ts_redo(), and vac_truncate_clog().

◆ BootStrapCommitTs()

void BootStrapCommitTs ( void  )

Definition at line 596 of file commit_ts.c.

597{
598 /*
599 * Nothing to do here at present, unlike most other SLRU modules; segments
600 * are created when the server is started with this module enabled. See
601 * ActivateCommitTs.
602 */
603}

Referenced by BootStrapXLOG().

◆ CheckPointCommitTs()

void CheckPointCommitTs ( void  )

Definition at line 820 of file commit_ts.c.

821{
822 /*
823 * Write dirty CommitTs pages to disk. This may result in sync requests
824 * queued for later handling by ProcessSyncRequests(), as part of the
825 * checkpoint.
826 */
828}
#define CommitTsCtl
Definition: commit_ts.c:85
void SimpleLruWriteAll(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1322

References CommitTsCtl, and SimpleLruWriteAll().

Referenced by CheckPointGuts().

◆ commit_ts_desc()

void commit_ts_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 21 of file committsdesc.c.

22{
23 char *rec = XLogRecGetData(record);
24 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
25
26 if (info == COMMIT_TS_ZEROPAGE)
27 {
28 int64 pageno;
29
30 memcpy(&pageno, rec, sizeof(pageno));
31 appendStringInfo(buf, "%lld", (long long) pageno);
32 }
33 else if (info == COMMIT_TS_TRUNCATE)
34 {
36
37 appendStringInfo(buf, "pageno %lld, oldestXid %u",
38 (long long) trunc->pageno, trunc->oldestXid);
39 }
40}
uint8_t uint8
Definition: c.h:483
int64_t int64
Definition: c.h:482
#define COMMIT_TS_ZEROPAGE
Definition: commit_ts.h:46
#define COMMIT_TS_TRUNCATE
Definition: commit_ts.h:47
static char * buf
Definition: pg_test_fsync.c:72
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:94
TransactionId oldestXid
Definition: commit_ts.h:63
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:410
#define XLogRecGetData(decoder)
Definition: xlogreader.h:415

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

◆ commit_ts_identify()

const char * commit_ts_identify ( uint8  info)

Definition at line 43 of file committsdesc.c.

44{
45 switch (info)
46 {
48 return "ZEROPAGE";
50 return "TRUNCATE";
51 default:
52 return NULL;
53 }
54}

References COMMIT_TS_TRUNCATE, and COMMIT_TS_ZEROPAGE.

◆ commit_ts_redo()

void commit_ts_redo ( XLogReaderState record)

Definition at line 1016 of file commit_ts.c.

1017{
1018 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
1019
1020 /* Backup blocks are not used in commit_ts records */
1022
1023 if (info == COMMIT_TS_ZEROPAGE)
1024 {
1025 int64 pageno;
1026 int slotno;
1027 LWLock *lock;
1028
1029 memcpy(&pageno, XLogRecGetData(record), sizeof(pageno));
1030
1031 lock = SimpleLruGetBankLock(CommitTsCtl, pageno);
1033
1034 slotno = ZeroCommitTsPage(pageno, false);
1036 Assert(!CommitTsCtl->shared->page_dirty[slotno]);
1037
1038 LWLockRelease(lock);
1039 }
1040 else if (info == COMMIT_TS_TRUNCATE)
1041 {
1043
1045
1046 /*
1047 * During XLOG replay, latest_page_number isn't set up yet; insert a
1048 * suitable value to bypass the sanity test in SimpleLruTruncate.
1049 */
1050 pg_atomic_write_u64(&CommitTsCtl->shared->latest_page_number,
1051 trunc->pageno);
1052
1054 }
1055 else
1056 elog(PANIC, "commit_ts_redo: unknown op code %u", info);
1057}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition: atomics.h:485
#define Assert(condition)
Definition: c.h:812
void AdvanceOldestCommitTsXid(TransactionId oldestXact)
Definition: commit_ts.c:936
static int ZeroCommitTsPage(int64 pageno, bool writeXlog)
Definition: commit_ts.c:615
#define PANIC
Definition: elog.h:42
#define elog(elevel,...)
Definition: elog.h:225
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:732
void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage)
Definition: slru.c:1408
static LWLock * SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
Definition: slru.h:178
Definition: lwlock.h:42
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:417

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, pg_atomic_write_u64(), SimpleLruGetBankLock(), SimpleLruTruncate(), SimpleLruWritePage(), XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, and ZeroCommitTsPage().

◆ CommitTsParameterChange()

void CommitTsParameterChange ( bool  newvalue,
bool  oldvalue 
)

Definition at line 664 of file commit_ts.c.

665{
666 /*
667 * If the commit_ts module is disabled in this server and we get word from
668 * the primary server that it is enabled there, activate it so that we can
669 * replay future WAL records involving it; also mark it as active on
670 * pg_control. If the old value was already set, we already did this, so
671 * don't do anything.
672 *
673 * If the module is disabled in the primary, disable it here too, unless
674 * the module is enabled locally.
675 *
676 * Note this only runs in the recovery process, so an unlocked read is
677 * fine.
678 */
679 if (newvalue)
680 {
683 }
686}
static void DeactivateCommitTs(void)
Definition: commit_ts.c:778
static CommitTimestampShared * commitTsShared
Definition: commit_ts.c:105
static void ActivateCommitTs(void)
Definition: commit_ts.c:705

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

Referenced by xlog_redo().

◆ CommitTsShmemInit()

void CommitTsShmemInit ( void  )

Definition at line 530 of file commit_ts.c.

531{
532 bool found;
533
534 /* If auto-tuning is requested, now is the time to do it */
536 {
537 char buf[32];
538
539 snprintf(buf, sizeof(buf), "%d", CommitTsShmemBuffers());
540 SetConfigOption("commit_timestamp_buffers", buf, PGC_POSTMASTER,
542
543 /*
544 * We prefer to report this value's source as PGC_S_DYNAMIC_DEFAULT.
545 * However, if the DBA explicitly set commit_timestamp_buffers = 0 in
546 * the config file, then PGC_S_DYNAMIC_DEFAULT will fail to override
547 * that and we must force the matter with PGC_S_OVERRIDE.
548 */
549 if (commit_timestamp_buffers == 0) /* failed to apply it? */
550 SetConfigOption("commit_timestamp_buffers", buf, PGC_POSTMASTER,
552 }
554
555 CommitTsCtl->PagePrecedes = CommitTsPagePrecedes;
556 SimpleLruInit(CommitTsCtl, "commit_timestamp", CommitTsShmemBuffers(), 0,
557 "pg_commit_ts", LWTRANCHE_COMMITTS_BUFFER,
560 false);
562
563 commitTsShared = ShmemInitStruct("CommitTs shared",
564 sizeof(CommitTimestampShared),
565 &found);
566
568 {
569 Assert(!found);
570
575 }
576 else
577 Assert(found);
578}
#define COMMIT_TS_XACTS_PER_PAGE
Definition: commit_ts.c:63
static int CommitTsShmemBuffers(void)
Definition: commit_ts.c:506
static bool CommitTsPagePrecedes(int64 page1, int64 page2)
Definition: commit_ts.c:970
#define TIMESTAMP_NOBEGIN(j)
Definition: timestamp.h:159
bool IsUnderPostmaster
Definition: globals.c:119
int commit_timestamp_buffers
Definition: globals.c:160
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
Definition: guc.c:4332
@ PGC_S_DYNAMIC_DEFAULT
Definition: guc.h:110
@ PGC_S_OVERRIDE
Definition: guc.h:119
@ PGC_POSTMASTER
Definition: guc.h:70
@ LWTRANCHE_COMMITTS_BUFFER
Definition: lwlock.h:180
@ LWTRANCHE_COMMITTS_SLRU
Definition: lwlock.h:210
#define InvalidRepOriginId
Definition: origin.h:33
#define snprintf
Definition: port.h:238
void * ShmemInitStruct(const char *name, Size size, bool *foundPtr)
Definition: shmem.c:382
void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, const char *subdir, int buffer_tranche_id, int bank_tranche_id, SyncRequestHandler sync_handler, bool long_segment_names)
Definition: slru.c:252
#define SlruPagePrecedesUnitTests(ctl, per_page)
Definition: slru.h:202
TimestampTz time
Definition: commit_ts.c:56
RepOriginId nodeid
Definition: commit_ts.c:57
CommitTimestampEntry dataLastCommit
Definition: commit_ts.c:101
TransactionId xidLastCommit
Definition: commit_ts.c:100
@ SYNC_HANDLER_COMMIT_TS
Definition: sync.h:39

References Assert, buf, commit_timestamp_buffers, COMMIT_TS_XACTS_PER_PAGE, CommitTimestampShared::commitTsActive, CommitTsCtl, CommitTsPagePrecedes(), commitTsShared, CommitTsShmemBuffers(), CommitTimestampShared::dataLastCommit, InvalidRepOriginId, InvalidTransactionId, IsUnderPostmaster, LWTRANCHE_COMMITTS_BUFFER, LWTRANCHE_COMMITTS_SLRU, CommitTimestampEntry::nodeid, PGC_POSTMASTER, PGC_S_DYNAMIC_DEFAULT, PGC_S_OVERRIDE, SetConfigOption(), ShmemInitStruct(), SimpleLruInit(), SlruPagePrecedesUnitTests, snprintf, SYNC_HANDLER_COMMIT_TS, CommitTimestampEntry::time, TIMESTAMP_NOBEGIN, and CommitTimestampShared::xidLastCommit.

Referenced by CreateOrAttachShmemStructs().

◆ CommitTsShmemSize()

Size CommitTsShmemSize ( void  )

Definition at line 519 of file commit_ts.c.

520{
522 sizeof(CommitTimestampShared);
523}
struct CommitTimestampShared CommitTimestampShared
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:199

References CommitTsShmemBuffers(), and SimpleLruShmemSize().

Referenced by CalculateShmemSize().

◆ committssyncfiletag()

int committssyncfiletag ( const FileTag ftag,
char *  path 
)

Definition at line 1063 of file commit_ts.c.

1064{
1065 return SlruSyncFileTag(CommitTsCtl, ftag, path);
1066}
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
Definition: slru.c:1831

References CommitTsCtl, and SlruSyncFileTag().

◆ CompleteCommitTsInitialization()

void CompleteCommitTsInitialization ( void  )

Definition at line 642 of file commit_ts.c.

643{
644 /*
645 * If the feature is not enabled, turn it off for good. This also removes
646 * any leftover data.
647 *
648 * Conversely, we activate the module if the feature is enabled. This is
649 * necessary for primary and standby as the activation depends on the
650 * control file contents at the beginning of recovery or when a
651 * XLOG_PARAMETER_CHANGE is replayed.
652 */
655 else
657}
bool track_commit_timestamp
Definition: commit_ts.c:109

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

Referenced by StartupXLOG().

◆ ExtendCommitTs()

void ExtendCommitTs ( TransactionId  newestXact)

Definition at line 842 of file commit_ts.c.

843{
844 int64 pageno;
845 LWLock *lock;
846
847 /*
848 * Nothing to do if module not enabled. Note we do an unlocked read of
849 * the flag here, which is okay because this routine is only called from
850 * GetNewTransactionId, which is never called in a standby.
851 */
854 return;
855
856 /*
857 * No work except at first XID of a page. But beware: just after
858 * wraparound, the first XID of page zero is FirstNormalTransactionId.
859 */
860 if (TransactionIdToCTsEntry(newestXact) != 0 &&
862 return;
863
864 pageno = TransactionIdToCTsPage(newestXact);
865
866 lock = SimpleLruGetBankLock(CommitTsCtl, pageno);
867
869
870 /* Zero the page and make an XLOG entry about it */
872
873 LWLockRelease(lock);
874}
#define TransactionIdToCTsEntry(xid)
Definition: commit_ts.c:77
static int64 TransactionIdToCTsPage(TransactionId xid)
Definition: commit_ts.c:72
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define FirstNormalTransactionId
Definition: transam.h:34
bool InRecovery
Definition: xlogutils.c:50

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

Referenced by GetNewTransactionId().

◆ GetLatestCommitTsData()

TransactionId GetLatestCommitTsData ( TimestampTz ts,
RepOriginId nodeid 
)

Definition at line 360 of file commit_ts.c.

361{
362 TransactionId xid;
363
364 LWLockAcquire(CommitTsLock, LW_SHARED);
365
366 /* Error if module not enabled */
369
371 if (ts)
373 if (nodeid)
375 LWLockRelease(CommitTsLock);
376
377 return xid;
378}
static void error_commit_ts_disabled(void)
Definition: commit_ts.c:381
@ LW_SHARED
Definition: lwlock.h:115

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

910{
911 /*
912 * Be careful not to overwrite values that are either further into the
913 * "future" or signal a disabled committs.
914 */
915 LWLockAcquire(CommitTsLock, LW_EXCLUSIVE);
917 {
922 }
923 else
924 {
928 }
929 LWLockRelease(CommitTsLock);
930}
TransactionId newestCommitTsXid
Definition: transam.h:233

References Assert, InvalidTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransamVariablesData::newestCommitTsXid, TransamVariablesData::oldestCommitTsXid, TransactionIdPrecedes(), and TransamVariables.

Referenced by BootStrapXLOG(), and StartupXLOG().

◆ StartupCommitTs()

void StartupCommitTs ( void  )

Definition at line 632 of file commit_ts.c.

633{
635}

References ActivateCommitTs().

Referenced by StartupXLOG().

◆ TransactionIdGetCommitTsData()

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

Definition at line 274 of file commit_ts.c.

276{
277 int64 pageno = TransactionIdToCTsPage(xid);
278 int entryno = TransactionIdToCTsEntry(xid);
279 int slotno;
281 TransactionId oldestCommitTsXid;
282 TransactionId newestCommitTsXid;
283
284 if (!TransactionIdIsValid(xid))
286 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
287 errmsg("cannot retrieve commit timestamp for transaction %u", xid)));
288 else if (!TransactionIdIsNormal(xid))
289 {
290 /* frozen and bootstrap xids are always committed far in the past */
291 *ts = 0;
292 if (nodeid)
293 *nodeid = 0;
294 return false;
295 }
296
297 LWLockAcquire(CommitTsLock, LW_SHARED);
298
299 /* Error if module not enabled */
302
303 /*
304 * If we're asked for the cached value, return that. Otherwise, fall
305 * through to read from SLRU.
306 */
307 if (commitTsShared->xidLastCommit == xid)
308 {
310 if (nodeid)
312
313 LWLockRelease(CommitTsLock);
314 return *ts != 0;
315 }
316
317 oldestCommitTsXid = TransamVariables->oldestCommitTsXid;
318 newestCommitTsXid = TransamVariables->newestCommitTsXid;
319 /* neither is invalid, or both are */
320 Assert(TransactionIdIsValid(oldestCommitTsXid) == TransactionIdIsValid(newestCommitTsXid));
321 LWLockRelease(CommitTsLock);
322
323 /*
324 * Return empty if the requested value is outside our valid range.
325 */
326 if (!TransactionIdIsValid(oldestCommitTsXid) ||
327 TransactionIdPrecedes(xid, oldestCommitTsXid) ||
328 TransactionIdPrecedes(newestCommitTsXid, xid))
329 {
330 *ts = 0;
331 if (nodeid)
332 *nodeid = InvalidRepOriginId;
333 return false;
334 }
335
336 /* lock is acquired by SimpleLruReadPage_ReadOnly */
337 slotno = SimpleLruReadPage_ReadOnly(CommitTsCtl, pageno, xid);
338 memcpy(&entry,
339 CommitTsCtl->shared->page_buffer[slotno] +
342
343 *ts = entry.time;
344 if (nodeid)
345 *nodeid = entry.nodeid;
346
348 return *ts != 0;
349}
#define SizeOfCommitTimestampEntry
Definition: commit_ts.c:60
int errcode(int sqlerrcode)
Definition: elog.c:853
int errmsg(const char *fmt,...)
Definition: elog.c:1070
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
Definition: slru.c:605
#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(), TransamVariablesData::newestCommitTsXid, CommitTimestampEntry::nodeid, TransamVariablesData::oldestCommitTsXid, SimpleLruGetBankLock(), SimpleLruReadPage_ReadOnly(), SizeOfCommitTimestampEntry, CommitTimestampEntry::time, TransactionIdIsNormal, TransactionIdIsValid, TransactionIdPrecedes(), TransactionIdToCTsEntry, TransactionIdToCTsPage(), TransamVariables, and CommitTimestampShared::xidLastCommit.

Referenced by GetTupleTransactionInfo(), 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 141 of file commit_ts.c.

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

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

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

◆ TruncateCommitTs()

void TruncateCommitTs ( TransactionId  oldestXact)

Definition at line 883 of file commit_ts.c.

884{
885 int64 cutoffPage;
886
887 /*
888 * The cutoff point is the start of the segment containing oldestXact. We
889 * pass the *page* containing oldestXact to SimpleLruTruncate.
890 */
891 cutoffPage = TransactionIdToCTsPage(oldestXact);
892
893 /* Check to see if there's any files that could be removed */
895 &cutoffPage))
896 return; /* nothing to remove */
897
898 /* Write XLOG record */
899 WriteTruncateXlogRec(cutoffPage, oldestXact);
900
901 /* Now we can remove the old CommitTs segment(s) */
902 SimpleLruTruncate(CommitTsCtl, cutoffPage);
903}
static void WriteTruncateXlogRec(int64 pageno, TransactionId oldestXid)
Definition: commit_ts.c:1000
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1791
bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename, int64 segpage, void *data)
Definition: slru.c:1712

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

Referenced by vac_truncate_clog().

Variable Documentation

◆ track_commit_timestamp

PGDLLIMPORT bool track_commit_timestamp
extern