PostgreSQL Source Code  git master
clog.h File Reference
#include "access/xlogreader.h"
#include "lib/stringinfo.h"
Include dependency graph for clog.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  xl_clog_truncate
 

Macros

#define TRANSACTION_STATUS_IN_PROGRESS   0x00
 
#define TRANSACTION_STATUS_COMMITTED   0x01
 
#define TRANSACTION_STATUS_ABORTED   0x02
 
#define TRANSACTION_STATUS_SUB_COMMITTED   0x03
 
#define CLOG_ZEROPAGE   0x00
 
#define CLOG_TRUNCATE   0x10
 

Typedefs

typedef int XidStatus
 
typedef struct xl_clog_truncate xl_clog_truncate
 

Functions

void TransactionIdSetTreeStatus (TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
 
XidStatus TransactionIdGetStatus (TransactionId xid, XLogRecPtr *lsn)
 
Size CLOGShmemBuffers (void)
 
Size CLOGShmemSize (void)
 
void CLOGShmemInit (void)
 
void BootStrapCLOG (void)
 
void StartupCLOG (void)
 
void TrimCLOG (void)
 
void ShutdownCLOG (void)
 
void CheckPointCLOG (void)
 
void ExtendCLOG (TransactionId newestXact)
 
void TruncateCLOG (TransactionId oldestXact, Oid oldestxid_datoid)
 
void clog_redo (XLogReaderState *record)
 
void clog_desc (StringInfo buf, XLogReaderState *record)
 
const char * clog_identify (uint8 info)
 

Macro Definition Documentation

◆ CLOG_TRUNCATE

#define CLOG_TRUNCATE   0x10

Definition at line 55 of file clog.h.

Referenced by clog_desc(), clog_identify(), clog_redo(), and WriteTruncateXlogRec().

◆ CLOG_ZEROPAGE

#define CLOG_ZEROPAGE   0x00

Definition at line 54 of file clog.h.

Referenced by clog_desc(), clog_identify(), clog_redo(), and WriteZeroPageXlogRec().

◆ TRANSACTION_STATUS_ABORTED

#define TRANSACTION_STATUS_ABORTED   0x02

◆ TRANSACTION_STATUS_COMMITTED

◆ TRANSACTION_STATUS_IN_PROGRESS

#define TRANSACTION_STATUS_IN_PROGRESS   0x00

Definition at line 26 of file clog.h.

Referenced by InitProcess(), TransactionIdSetStatusBit(), and TransactionLogFetch().

◆ TRANSACTION_STATUS_SUB_COMMITTED

#define TRANSACTION_STATUS_SUB_COMMITTED   0x03

Typedef Documentation

◆ XidStatus

typedef int XidStatus

Definition at line 24 of file clog.h.

◆ xl_clog_truncate

Function Documentation

◆ BootStrapCLOG()

void BootStrapCLOG ( void  )

Definition at line 705 of file clog.c.

References Assert, ClogCtl, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), SimpleLruWritePage(), and ZeroCLOGPage().

Referenced by BootStrapXLOG().

706 {
707  int slotno;
708 
709  LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
710 
711  /* Create and zero the first page of the commit log */
712  slotno = ZeroCLOGPage(0, false);
713 
714  /* Make sure it's written out */
715  SimpleLruWritePage(ClogCtl, slotno);
716  Assert(!ClogCtl->shared->page_dirty[slotno]);
717 
718  LWLockRelease(CLogControlLock);
719 }
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ClogCtl
Definition: clog.c:88
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:577
#define Assert(condition)
Definition: c.h:739
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
static int ZeroCLOGPage(int pageno, bool writeXlog)
Definition: clog.c:731

◆ CheckPointCLOG()

void CheckPointCLOG ( void  )

Definition at line 835 of file clog.c.

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

Referenced by CheckPointGuts().

836 {
837  /* Flush dirty CLOG pages to disk */
838  TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(true);
839  SimpleLruFlush(ClogCtl, true);
840 
841  /*
842  * fsync pg_xact to ensure that any files flushed previously are durably
843  * on disk.
844  */
845  fsync_fname("pg_xact", true);
846 
847  TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE(true);
848 }
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:617
void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1119
#define ClogCtl
Definition: clog.c:88

◆ clog_desc()

void clog_desc ( StringInfo  buf,
XLogReaderState record 
)

Definition at line 21 of file clogdesc.c.

References appendStringInfo(), CLOG_TRUNCATE, CLOG_ZEROPAGE, xl_clog_truncate::oldestXact, xl_clog_truncate::pageno, XLogRecGetData, XLogRecGetInfo, and XLR_INFO_MASK.

22 {
23  char *rec = XLogRecGetData(record);
24  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
25 
26  if (info == CLOG_ZEROPAGE)
27  {
28  int pageno;
29 
30  memcpy(&pageno, rec, sizeof(int));
31  appendStringInfo(buf, "page %d", pageno);
32  }
33  else if (info == CLOG_TRUNCATE)
34  {
35  xl_clog_truncate xlrec;
36 
37  memcpy(&xlrec, rec, sizeof(xl_clog_truncate));
38  appendStringInfo(buf, "page %d; oldestXact %u",
39  xlrec.pageno, xlrec.oldestXact);
40  }
41 }
unsigned char uint8
Definition: c.h:357
#define CLOG_ZEROPAGE
Definition: clog.h:54
#define XLogRecGetData(decoder)
Definition: xlogreader.h:283
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
int pageno
Definition: clog.h:33
#define CLOG_TRUNCATE
Definition: clog.h:55
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:279
TransactionId oldestXact
Definition: clog.h:34
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

◆ clog_identify()

const char* clog_identify ( uint8  info)

Definition at line 44 of file clogdesc.c.

References CLOG_TRUNCATE, CLOG_ZEROPAGE, and XLR_INFO_MASK.

45 {
46  const char *id = NULL;
47 
48  switch (info & ~XLR_INFO_MASK)
49  {
50  case CLOG_ZEROPAGE:
51  id = "ZEROPAGE";
52  break;
53  case CLOG_TRUNCATE:
54  id = "TRUNCATE";
55  break;
56  }
57 
58  return id;
59 }
#define CLOG_ZEROPAGE
Definition: clog.h:54
#define CLOG_TRUNCATE
Definition: clog.h:55
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

◆ clog_redo()

void clog_redo ( XLogReaderState record)

Definition at line 996 of file clog.c.

References AdvanceOldestClogXid(), Assert, CLOG_TRUNCATE, CLOG_ZEROPAGE, ClogCtl, elog, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), xl_clog_truncate::oldestXact, xl_clog_truncate::pageno, PANIC, SimpleLruTruncate(), SimpleLruWritePage(), XLogRecGetData, XLogRecGetInfo, XLogRecHasAnyBlockRefs, XLR_INFO_MASK, and ZeroCLOGPage().

997 {
998  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
999 
1000  /* Backup blocks are not used in clog records */
1001  Assert(!XLogRecHasAnyBlockRefs(record));
1002 
1003  if (info == CLOG_ZEROPAGE)
1004  {
1005  int pageno;
1006  int slotno;
1007 
1008  memcpy(&pageno, XLogRecGetData(record), sizeof(int));
1009 
1010  LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
1011 
1012  slotno = ZeroCLOGPage(pageno, false);
1013  SimpleLruWritePage(ClogCtl, slotno);
1014  Assert(!ClogCtl->shared->page_dirty[slotno]);
1015 
1016  LWLockRelease(CLogControlLock);
1017  }
1018  else if (info == CLOG_TRUNCATE)
1019  {
1020  xl_clog_truncate xlrec;
1021 
1022  memcpy(&xlrec, XLogRecGetData(record), sizeof(xl_clog_truncate));
1023 
1024  /*
1025  * During XLOG replay, latest_page_number isn't set up yet; insert a
1026  * suitable value to bypass the sanity test in SimpleLruTruncate.
1027  */
1028  ClogCtl->shared->latest_page_number = xlrec.pageno;
1029 
1031 
1033  }
1034  else
1035  elog(PANIC, "clog_redo: unknown op code %u", info);
1036 }
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1184
unsigned char uint8
Definition: c.h:357
#define PANIC
Definition: elog.h:53
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ClogCtl
Definition: clog.c:88
#define CLOG_ZEROPAGE
Definition: clog.h:54
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
Definition: varsup.c:313
#define XLogRecGetData(decoder)
Definition: xlogreader.h:283
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:577
int pageno
Definition: clog.h:33
#define CLOG_TRUNCATE
Definition: clog.h:55
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:279
TransactionId oldestXact
Definition: clog.h:34
#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
static int ZeroCLOGPage(int pageno, bool writeXlog)
Definition: clog.c:731
#define elog(elevel,...)
Definition: elog.h:228
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:285

◆ CLOGShmemBuffers()

Size CLOGShmemBuffers ( void  )

Definition at line 676 of file clog.c.

References Max, Min, and NBuffers.

Referenced by CLOGShmemInit(), and CLOGShmemSize().

677 {
678  return Min(128, Max(4, NBuffers / 512));
679 }
#define Min(x, y)
Definition: c.h:911
#define Max(x, y)
Definition: c.h:905
int NBuffers
Definition: globals.c:131

◆ CLOGShmemInit()

void CLOGShmemInit ( void  )

Definition at line 691 of file clog.c.

References CLOG_LSNS_PER_PAGE, ClogCtl, CLOGPagePrecedes(), CLOGShmemBuffers(), LWTRANCHE_CLOG_BUFFERS, and SimpleLruInit().

Referenced by CreateSharedMemoryAndSemaphores().

692 {
693  ClogCtl->PagePrecedes = CLOGPagePrecedes;
695  CLogControlLock, "pg_xact", LWTRANCHE_CLOG_BUFFERS);
696 }
#define ClogCtl
Definition: clog.c:88
#define CLOG_LSNS_PER_PAGE
Definition: clog.c:71
static bool CLOGPagePrecedes(int page1, int page2)
Definition: clog.c:945
Size CLOGShmemBuffers(void)
Definition: clog.c:676
void SimpleLruInit(SlruCtl ctl, const char *name, int nslots, int nlsns, LWLock *ctllock, const char *subdir, int tranche_id)
Definition: slru.c:164

◆ CLOGShmemSize()

Size CLOGShmemSize ( void  )

Definition at line 685 of file clog.c.

References CLOG_LSNS_PER_PAGE, CLOGShmemBuffers(), and SimpleLruShmemSize().

Referenced by CreateSharedMemoryAndSemaphores().

686 {
688 }
Size SimpleLruShmemSize(int nslots, int nlsns)
Definition: slru.c:144
#define CLOG_LSNS_PER_PAGE
Definition: clog.c:71
Size CLOGShmemBuffers(void)
Definition: clog.c:676

◆ ExtendCLOG()

void ExtendCLOG ( TransactionId  newestXact)

Definition at line 860 of file clog.c.

References FirstNormalTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), TransactionIdEquals, TransactionIdToPage, TransactionIdToPgIndex, and ZeroCLOGPage().

Referenced by GetNewTransactionId().

861 {
862  int pageno;
863 
864  /*
865  * No work except at first XID of a page. But beware: just after
866  * wraparound, the first XID of page zero is FirstNormalTransactionId.
867  */
868  if (TransactionIdToPgIndex(newestXact) != 0 &&
870  return;
871 
872  pageno = TransactionIdToPage(newestXact);
873 
874  LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
875 
876  /* Zero the page and make an XLOG entry about it */
877  ZeroCLOGPage(pageno, true);
878 
879  LWLockRelease(CLogControlLock);
880 }
#define TransactionIdToPage(xid)
Definition: clog.c:64
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define TransactionIdToPgIndex(xid)
Definition: clog.c:65
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define FirstNormalTransactionId
Definition: transam.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
static int ZeroCLOGPage(int pageno, bool writeXlog)
Definition: clog.c:731

◆ ShutdownCLOG()

void ShutdownCLOG ( void  )

Definition at line 816 of file clog.c.

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

Referenced by ShutdownXLOG().

817 {
818  /* Flush dirty CLOG pages to disk */
819  TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(false);
820  SimpleLruFlush(ClogCtl, false);
821 
822  /*
823  * fsync pg_xact to ensure that any files flushed previously are durably
824  * on disk.
825  */
826  fsync_fname("pg_xact", true);
827 
828  TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE(false);
829 }
void fsync_fname(const char *fname, bool isdir)
Definition: fd.c:617
void SimpleLruFlush(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1119
#define ClogCtl
Definition: clog.c:88

◆ StartupCLOG()

void StartupCLOG ( void  )

Definition at line 748 of file clog.c.

References ClogCtl, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::nextFullXid, ShmemVariableCache, TransactionIdToPage, and XidFromFullTransactionId.

Referenced by StartupXLOG().

749 {
751  int pageno = TransactionIdToPage(xid);
752 
753  LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
754 
755  /*
756  * Initialize our idea of the latest page number.
757  */
758  ClogCtl->shared->latest_page_number = pageno;
759 
760  LWLockRelease(CLogControlLock);
761 }
#define TransactionIdToPage(xid)
Definition: clog.c:64
uint32 TransactionId
Definition: c.h:514
FullTransactionId nextFullXid
Definition: transam.h:164
#define XidFromFullTransactionId(x)
Definition: transam.h:48
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ClogCtl
Definition: clog.c:88
VariableCache ShmemVariableCache
Definition: varsup.c:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122

◆ TransactionIdGetStatus()

XidStatus TransactionIdGetStatus ( TransactionId  xid,
XLogRecPtr lsn 
)

Definition at line 634 of file clog.c.

References CLOG_BITS_PER_XACT, CLOG_XACT_BITMASK, ClogCtl, GetLSNIndex, LWLockRelease(), SimpleLruReadPage_ReadOnly(), status(), TransactionIdToBIndex, TransactionIdToByte, and TransactionIdToPage.

Referenced by TransactionIdGetCommitLSN(), and TransactionLogFetch().

635 {
636  int pageno = TransactionIdToPage(xid);
637  int byteno = TransactionIdToByte(xid);
638  int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT;
639  int slotno;
640  int lsnindex;
641  char *byteptr;
643 
644  /* lock is acquired by SimpleLruReadPage_ReadOnly */
645 
646  slotno = SimpleLruReadPage_ReadOnly(ClogCtl, pageno, xid);
647  byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
648 
649  status = (*byteptr >> bshift) & CLOG_XACT_BITMASK;
650 
651  lsnindex = GetLSNIndex(slotno, xid);
652  *lsn = ClogCtl->shared->group_lsn[lsnindex];
653 
654  LWLockRelease(CLogControlLock);
655 
656  return status;
657 }
#define TransactionIdToBIndex(xid)
Definition: clog.c:67
#define CLOG_XACT_BITMASK
Definition: clog.c:62
#define TransactionIdToPage(xid)
Definition: clog.c:64
#define GetLSNIndex(slotno, xid)
Definition: clog.c:73
int XidStatus
Definition: clog.h:24
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ClogCtl
Definition: clog.c:88
#define CLOG_BITS_PER_XACT
Definition: clog.c:59
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
Definition: slru.c:466
#define TransactionIdToByte(xid)
Definition: clog.c:66
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:226

◆ TransactionIdSetTreeStatus()

void TransactionIdSetTreeStatus ( TransactionId  xid,
int  nsubxids,
TransactionId subxids,
XidStatus  status,
XLogRecPtr  lsn 
)

Definition at line 163 of file clog.c.

References Assert, i, set_status_by_pages(), TRANSACTION_STATUS_ABORTED, TRANSACTION_STATUS_COMMITTED, TRANSACTION_STATUS_SUB_COMMITTED, TransactionIdSetPageStatus(), and TransactionIdToPage.

Referenced by TransactionIdAbortTree(), TransactionIdAsyncCommitTree(), and TransactionIdCommitTree().

165 {
166  int pageno = TransactionIdToPage(xid); /* get page of parent */
167  int i;
168 
171 
172  /*
173  * See how many subxids, if any, are on the same page as the parent, if
174  * any.
175  */
176  for (i = 0; i < nsubxids; i++)
177  {
178  if (TransactionIdToPage(subxids[i]) != pageno)
179  break;
180  }
181 
182  /*
183  * Do all items fit on a single page?
184  */
185  if (i == nsubxids)
186  {
187  /*
188  * Set the parent and all subtransactions in a single call
189  */
190  TransactionIdSetPageStatus(xid, nsubxids, subxids, status, lsn,
191  pageno, true);
192  }
193  else
194  {
195  int nsubxids_on_first_page = i;
196 
197  /*
198  * If this is a commit then we care about doing this correctly (i.e.
199  * using the subcommitted intermediate status). By here, we know
200  * we're updating more than one page of clog, so we must mark entries
201  * that are *not* on the first page so that they show as subcommitted
202  * before we then return to update the status to fully committed.
203  *
204  * To avoid touching the first page twice, skip marking subcommitted
205  * for the subxids on that first page.
206  */
208  set_status_by_pages(nsubxids - nsubxids_on_first_page,
209  subxids + nsubxids_on_first_page,
211 
212  /*
213  * Now set the parent and subtransactions on same page as the parent,
214  * if any
215  */
216  pageno = TransactionIdToPage(xid);
217  TransactionIdSetPageStatus(xid, nsubxids_on_first_page, subxids, status,
218  lsn, pageno, false);
219 
220  /*
221  * Now work through the rest of the subxids one clog page at a time,
222  * starting from the second page onwards, like we did above.
223  */
224  set_status_by_pages(nsubxids - nsubxids_on_first_page,
225  subxids + nsubxids_on_first_page,
226  status, lsn);
227  }
228 }
#define TransactionIdToPage(xid)
Definition: clog.c:64
#define TRANSACTION_STATUS_COMMITTED
Definition: clog.h:27
#define TRANSACTION_STATUS_ABORTED
Definition: clog.h:28
#define TRANSACTION_STATUS_SUB_COMMITTED
Definition: clog.h:29
static void set_status_by_pages(int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
Definition: clog.c:237
#define Assert(condition)
Definition: c.h:739
static void TransactionIdSetPageStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn, int pageno, bool all_xact_same_page)
Definition: clog.c:273
int i
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:226

◆ TrimCLOG()

void TrimCLOG ( void  )

Definition at line 767 of file clog.c.

References CLOG_BITS_PER_XACT, ClogCtl, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MemSet, VariableCacheData::nextFullXid, ShmemVariableCache, SimpleLruReadPage(), TransactionIdToBIndex, TransactionIdToByte, TransactionIdToPage, TransactionIdToPgIndex, and XidFromFullTransactionId.

Referenced by StartupXLOG().

768 {
770  int pageno = TransactionIdToPage(xid);
771 
772  LWLockAcquire(CLogControlLock, LW_EXCLUSIVE);
773 
774  /*
775  * Re-Initialize our idea of the latest page number.
776  */
777  ClogCtl->shared->latest_page_number = pageno;
778 
779  /*
780  * Zero out the remainder of the current clog page. Under normal
781  * circumstances it should be zeroes already, but it seems at least
782  * theoretically possible that XLOG replay will have settled on a nextXID
783  * value that is less than the last XID actually used and marked by the
784  * previous database lifecycle (since subtransaction commit writes clog
785  * but makes no WAL entry). Let's just be safe. (We need not worry about
786  * pages beyond the current one, since those will be zeroed when first
787  * used. For the same reason, there is no need to do anything when
788  * nextFullXid is exactly at a page boundary; and it's likely that the
789  * "current" page doesn't exist yet in that case.)
790  */
791  if (TransactionIdToPgIndex(xid) != 0)
792  {
793  int byteno = TransactionIdToByte(xid);
794  int bshift = TransactionIdToBIndex(xid) * CLOG_BITS_PER_XACT;
795  int slotno;
796  char *byteptr;
797 
798  slotno = SimpleLruReadPage(ClogCtl, pageno, false, xid);
799  byteptr = ClogCtl->shared->page_buffer[slotno] + byteno;
800 
801  /* Zero so-far-unused positions in the current byte */
802  *byteptr &= (1 << bshift) - 1;
803  /* Zero the rest of the page */
804  MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
805 
806  ClogCtl->shared->page_dirty[slotno] = true;
807  }
808 
809  LWLockRelease(CLogControlLock);
810 }
#define TransactionIdToBIndex(xid)
Definition: clog.c:67
#define TransactionIdToPage(xid)
Definition: clog.c:64
uint32 TransactionId
Definition: c.h:514
#define TransactionIdToPgIndex(xid)
Definition: clog.c:65
#define MemSet(start, val, len)
Definition: c.h:962
FullTransactionId nextFullXid
Definition: transam.h:164
#define XidFromFullTransactionId(x)
Definition: transam.h:48
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1726
#define ClogCtl
Definition: clog.c:88
int SimpleLruReadPage(SlruCtl ctl, int pageno, bool write_ok, TransactionId xid)
Definition: slru.c:374
VariableCache ShmemVariableCache
Definition: varsup.c:34
#define CLOG_BITS_PER_XACT
Definition: clog.c:59
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1122
#define TransactionIdToByte(xid)
Definition: clog.c:66

◆ TruncateCLOG()

void TruncateCLOG ( TransactionId  oldestXact,
Oid  oldestxid_datoid 
)

Definition at line 899 of file clog.c.

References AdvanceOldestClogXid(), ClogCtl, SimpleLruTruncate(), SlruScanDirCbReportPresence(), SlruScanDirectory(), TransactionIdToPage, and WriteTruncateXlogRec().

Referenced by vac_truncate_clog().

900 {
901  int cutoffPage;
902 
903  /*
904  * The cutoff point is the start of the segment containing oldestXact. We
905  * pass the *page* containing oldestXact to SimpleLruTruncate.
906  */
907  cutoffPage = TransactionIdToPage(oldestXact);
908 
909  /* Check to see if there's any files that could be removed */
911  return; /* nothing to remove */
912 
913  /*
914  * Advance oldestClogXid before truncating clog, so concurrent xact status
915  * lookups can ensure they don't attempt to access truncated-away clog.
916  *
917  * It's only necessary to do this if we will actually truncate away clog
918  * pages.
919  */
920  AdvanceOldestClogXid(oldestXact);
921 
922  /*
923  * Write XLOG record and flush XLOG to disk. We record the oldest xid
924  * we're keeping information about here so we can ensure that it's always
925  * ahead of clog truncation in case we crash, and so a standby finds out
926  * the new valid xid before the next checkpoint.
927  */
928  WriteTruncateXlogRec(cutoffPage, oldestXact, oldestxid_datoid);
929 
930  /* Now we can remove the old CLOG segment(s) */
931  SimpleLruTruncate(ClogCtl, cutoffPage);
932 }
#define TransactionIdToPage(xid)
Definition: clog.c:64
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1184
#define ClogCtl
Definition: clog.c:88
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
Definition: varsup.c:313
static void WriteTruncateXlogRec(int pageno, TransactionId oldestXact, Oid oldestXactDb)
Definition: clog.c:977
bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename, int segpage, void *data)
Definition: slru.c:1337
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1392