PostgreSQL Source Code  git master
clog.h File Reference
#include "access/xlogreader.h"
#include "storage/sync.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 CheckPointCLOG (void)
 
void ExtendCLOG (TransactionId newestXact)
 
void TruncateCLOG (TransactionId oldestXact, Oid oldestxid_datoid)
 
int clogsyncfiletag (const FileTag *ftag, char *path)
 
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 57 of file clog.h.

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

◆ CLOG_ZEROPAGE

#define CLOG_ZEROPAGE   0x00

Definition at line 56 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 27 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 25 of file clog.h.

◆ xl_clog_truncate

Function Documentation

◆ BootStrapCLOG()

void BootStrapCLOG ( void  )

Definition at line 707 of file clog.c.

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

Referenced by BootStrapXLOG().

708 {
709  int slotno;
710 
711  LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
712 
713  /* Create and zero the first page of the commit log */
714  slotno = ZeroCLOGPage(0, false);
715 
716  /* Make sure it's written out */
717  SimpleLruWritePage(XactCtl, slotno);
718  Assert(!XactCtl->shared->page_dirty[slotno]);
719 
720  LWLockRelease(XactSLRULock);
721 }
#define XactCtl
Definition: clog.c:89
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:613
#define Assert(condition)
Definition: c.h:804
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
static int ZeroCLOGPage(int pageno, bool writeXlog)
Definition: clog.c:733

◆ CheckPointCLOG()

void CheckPointCLOG ( void  )

Definition at line 813 of file clog.c.

References SimpleLruWriteAll(), and XactCtl.

Referenced by CheckPointGuts().

814 {
815  /*
816  * Write dirty CLOG pages to disk. This may result in sync requests
817  * queued for later handling by ProcessSyncRequests(), as part of the
818  * checkpoint.
819  */
820  TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(true);
821  SimpleLruWriteAll(XactCtl, true);
822  TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE(true);
823 }
#define XactCtl
Definition: clog.c:89
void SimpleLruWriteAll(SlruCtl ctl, bool allow_redirtied)
Definition: slru.c:1155

◆ 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:439
#define CLOG_ZEROPAGE
Definition: clog.h:56
#define XLogRecGetData(decoder)
Definition: xlogreader.h:382
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition: stringinfo.c:91
int pageno
Definition: clog.h:34
#define CLOG_TRUNCATE
Definition: clog.h:57
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:377
TransactionId oldestXact
Definition: clog.h:35
#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:56
#define CLOG_TRUNCATE
Definition: clog.h:57
#define XLR_INFO_MASK
Definition: xlogrecord.h:62

◆ clog_redo()

void clog_redo ( XLogReaderState record)

Definition at line 981 of file clog.c.

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

982 {
983  uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
984 
985  /* Backup blocks are not used in clog records */
986  Assert(!XLogRecHasAnyBlockRefs(record));
987 
988  if (info == CLOG_ZEROPAGE)
989  {
990  int pageno;
991  int slotno;
992 
993  memcpy(&pageno, XLogRecGetData(record), sizeof(int));
994 
995  LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
996 
997  slotno = ZeroCLOGPage(pageno, false);
998  SimpleLruWritePage(XactCtl, slotno);
999  Assert(!XactCtl->shared->page_dirty[slotno]);
1000 
1001  LWLockRelease(XactSLRULock);
1002  }
1003  else if (info == CLOG_TRUNCATE)
1004  {
1005  xl_clog_truncate xlrec;
1006 
1007  memcpy(&xlrec, XLogRecGetData(record), sizeof(xl_clog_truncate));
1008 
1010 
1012  }
1013  else
1014  elog(PANIC, "clog_redo: unknown op code %u", info);
1015 }
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1225
#define XactCtl
Definition: clog.c:89
unsigned char uint8
Definition: c.h:439
#define PANIC
Definition: elog.h:50
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
#define CLOG_ZEROPAGE
Definition: clog.h:56
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
Definition: varsup.c:328
#define XLogRecGetData(decoder)
Definition: xlogreader.h:382
void SimpleLruWritePage(SlruCtl ctl, int slotno)
Definition: slru.c:613
int pageno
Definition: clog.h:34
#define CLOG_TRUNCATE
Definition: clog.h:57
#define XLogRecGetInfo(decoder)
Definition: xlogreader.h:377
TransactionId oldestXact
Definition: clog.h:35
#define Assert(condition)
Definition: c.h:804
#define XLR_INFO_MASK
Definition: xlogrecord.h:62
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
static int ZeroCLOGPage(int pageno, bool writeXlog)
Definition: clog.c:733
#define elog(elevel,...)
Definition: elog.h:232
#define XLogRecHasAnyBlockRefs(decoder)
Definition: xlogreader.h:384

◆ 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:986
#define Max(x, y)
Definition: c.h:980
int NBuffers
Definition: globals.c:135

◆ CLOGShmemInit()

void CLOGShmemInit ( void  )

Definition at line 691 of file clog.c.

References CLOG_LSNS_PER_PAGE, CLOG_XACTS_PER_PAGE, CLOGPagePrecedes(), CLOGShmemBuffers(), LWTRANCHE_XACT_BUFFER, SimpleLruInit(), SlruPagePrecedesUnitTests, SYNC_HANDLER_CLOG, and XactCtl.

Referenced by CreateSharedMemoryAndSemaphores().

692 {
693  XactCtl->PagePrecedes = CLOGPagePrecedes;
695  XactSLRULock, "pg_xact", LWTRANCHE_XACT_BUFFER,
698 }
#define CLOG_XACTS_PER_PAGE
Definition: clog.c:62
#define XactCtl
Definition: clog.c:89
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:186
#define CLOG_LSNS_PER_PAGE
Definition: clog.c:72
static bool CLOGPagePrecedes(int page1, int page2)
Definition: clog.c:929
Size CLOGShmemBuffers(void)
Definition: clog.c:676
#define SlruPagePrecedesUnitTests(ctl, per_page)
Definition: slru.h:156

◆ 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:155
#define CLOG_LSNS_PER_PAGE
Definition: clog.c:72
Size CLOGShmemBuffers(void)
Definition: clog.c:676

◆ clogsyncfiletag()

int clogsyncfiletag ( const FileTag ftag,
char *  path 
)

Definition at line 1021 of file clog.c.

References SlruSyncFileTag(), and XactCtl.

1022 {
1023  return SlruSyncFileTag(XactCtl, ftag, path);
1024 }
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
Definition: slru.c:1592
#define XactCtl
Definition: clog.c:89

◆ ExtendCLOG()

void ExtendCLOG ( TransactionId  newestXact)

Definition at line 835 of file clog.c.

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

Referenced by GetNewTransactionId().

836 {
837  int pageno;
838 
839  /*
840  * No work except at first XID of a page. But beware: just after
841  * wraparound, the first XID of page zero is FirstNormalTransactionId.
842  */
843  if (TransactionIdToPgIndex(newestXact) != 0 &&
845  return;
846 
847  pageno = TransactionIdToPage(newestXact);
848 
849  LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
850 
851  /* Zero the page and make an XLOG entry about it */
852  ZeroCLOGPage(pageno, true);
853 
854  LWLockRelease(XactSLRULock);
855 }
#define TransactionIdToPage(xid)
Definition: clog.c:65
#define TransactionIdEquals(id1, id2)
Definition: transam.h:43
#define TransactionIdToPgIndex(xid)
Definition: clog.c:66
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
#define FirstNormalTransactionId
Definition: transam.h:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203
static int ZeroCLOGPage(int pageno, bool writeXlog)
Definition: clog.c:733

◆ StartupCLOG()

void StartupCLOG ( void  )

Definition at line 750 of file clog.c.

References LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), VariableCacheData::nextXid, ShmemVariableCache, TransactionIdToPage, XactCtl, and XidFromFullTransactionId.

Referenced by StartupXLOG().

751 {
753  int pageno = TransactionIdToPage(xid);
754 
755  LWLockAcquire(XactSLRULock, LW_EXCLUSIVE);
756 
757  /*
758  * Initialize our idea of the latest page number.
759  */
760  XactCtl->shared->latest_page_number = pageno;
761 
762  LWLockRelease(XactSLRULock);
763 }
#define TransactionIdToPage(xid)
Definition: clog.c:65
uint32 TransactionId
Definition: c.h:587
#define XactCtl
Definition: clog.c:89
FullTransactionId nextXid
Definition: transam.h:213
#define XidFromFullTransactionId(x)
Definition: transam.h:48
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
VariableCache ShmemVariableCache
Definition: varsup.c:34
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition: lwlock.c:1203

◆ TransactionIdGetStatus()

XidStatus TransactionIdGetStatus ( TransactionId  xid,
XLogRecPtr lsn 
)

Definition at line 634 of file clog.c.

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

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(XactCtl, pageno, xid);
647  byteptr = XactCtl->shared->page_buffer[slotno] + byteno;
648 
649  status = (*byteptr >> bshift) & CLOG_XACT_BITMASK;
650 
651  lsnindex = GetLSNIndex(slotno, xid);
652  *lsn = XactCtl->shared->group_lsn[lsnindex];
653 
654  LWLockRelease(XactSLRULock);
655 
656  return status;
657 }
#define TransactionIdToBIndex(xid)
Definition: clog.c:68
#define CLOG_XACT_BITMASK
Definition: clog.c:63
#define TransactionIdToPage(xid)
Definition: clog.c:65
#define GetLSNIndex(slotno, xid)
Definition: clog.c:74
#define XactCtl
Definition: clog.c:89
int XidStatus
Definition: clog.h:25
void LWLockRelease(LWLock *lock)
Definition: lwlock.c:1805
#define CLOG_BITS_PER_XACT
Definition: clog.c:60
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int pageno, TransactionId xid)
Definition: slru.c:494
#define TransactionIdToByte(xid)
Definition: clog.c:67
static void static void status(const char *fmt,...) pg_attribute_printf(1
Definition: pg_regress.c:227

◆ TransactionIdSetTreeStatus()

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

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

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

◆ TrimCLOG()

void TrimCLOG ( void  )

Definition at line 769 of file clog.c.

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

Referenced by StartupXLOG().

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

◆ TruncateCLOG()

void TruncateCLOG ( TransactionId  oldestXact,
Oid  oldestxid_datoid 
)

Definition at line 874 of file clog.c.

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

Referenced by vac_truncate_clog().

875 {
876  int cutoffPage;
877 
878  /*
879  * The cutoff point is the start of the segment containing oldestXact. We
880  * pass the *page* containing oldestXact to SimpleLruTruncate.
881  */
882  cutoffPage = TransactionIdToPage(oldestXact);
883 
884  /* Check to see if there's any files that could be removed */
886  return; /* nothing to remove */
887 
888  /*
889  * Advance oldestClogXid before truncating clog, so concurrent xact status
890  * lookups can ensure they don't attempt to access truncated-away clog.
891  *
892  * It's only necessary to do this if we will actually truncate away clog
893  * pages.
894  */
895  AdvanceOldestClogXid(oldestXact);
896 
897  /*
898  * Write XLOG record and flush XLOG to disk. We record the oldest xid
899  * we're keeping information about here so we can ensure that it's always
900  * ahead of clog truncation in case we crash, and so a standby finds out
901  * the new valid xid before the next checkpoint.
902  */
903  WriteTruncateXlogRec(cutoffPage, oldestXact, oldestxid_datoid);
904 
905  /* Now we can remove the old CLOG segment(s) */
906  SimpleLruTruncate(XactCtl, cutoffPage);
907 }
#define TransactionIdToPage(xid)
Definition: clog.c:65
void SimpleLruTruncate(SlruCtl ctl, int cutoffPage)
Definition: slru.c:1225
#define XactCtl
Definition: clog.c:89
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
Definition: varsup.c:328
static void WriteTruncateXlogRec(int pageno, TransactionId oldestXact, Oid oldestXactDb)
Definition: clog.c:962
bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename, int segpage, void *data)
Definition: slru.c:1499
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
Definition: slru.c:1552