PostgreSQL Source Code git master
Loading...
Searching...
No Matches
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)
 
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 charclog_identify (uint8 info)
 

Macro Definition Documentation

◆ CLOG_TRUNCATE

#define CLOG_TRUNCATE   0x10

Definition at line 54 of file clog.h.

◆ CLOG_ZEROPAGE

#define CLOG_ZEROPAGE   0x00

Definition at line 53 of file clog.h.

◆ TRANSACTION_STATUS_ABORTED

#define TRANSACTION_STATUS_ABORTED   0x02

Definition at line 29 of file clog.h.

◆ TRANSACTION_STATUS_COMMITTED

#define TRANSACTION_STATUS_COMMITTED   0x01

Definition at line 28 of file clog.h.

◆ TRANSACTION_STATUS_IN_PROGRESS

#define TRANSACTION_STATUS_IN_PROGRESS   0x00

Definition at line 27 of file clog.h.

◆ TRANSACTION_STATUS_SUB_COMMITTED

#define TRANSACTION_STATUS_SUB_COMMITTED   0x03

Definition at line 30 of file clog.h.

Typedef Documentation

◆ XidStatus

Definition at line 25 of file clog.h.

◆ xl_clog_truncate

Function Documentation

◆ BootStrapCLOG()

void BootStrapCLOG ( void  )
extern

Definition at line 850 of file clog.c.

851{
852 /* Zero the initial page and flush it to disk */
854}
#define XactCtl
Definition clog.c:122
void SimpleLruZeroAndWritePage(SlruDesc *ctl, int64 pageno)
Definition slru.c:466

References SimpleLruZeroAndWritePage(), and XactCtl.

Referenced by BootStrapXLOG().

◆ CheckPointCLOG()

void CheckPointCLOG ( void  )
extern

Definition at line 921 of file clog.c.

922{
923 /*
924 * Write dirty CLOG pages to disk. This may result in sync requests
925 * queued for later handling by ProcessSyncRequests(), as part of the
926 * checkpoint.
927 */
931}
static int fb(int x)
void SimpleLruWriteAll(SlruDesc *ctl, bool allow_redirtied)
Definition slru.c:1372

References fb(), SimpleLruWriteAll(), and XactCtl.

Referenced by CheckPointGuts().

◆ clog_desc()

void clog_desc ( StringInfo  buf,
XLogReaderState record 
)
extern

Definition at line 21 of file clogdesc.c.

22{
23 char *rec = XLogRecGetData(record);
24 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
25
26 if (info == CLOG_ZEROPAGE)
27 {
28 int64 pageno;
29
30 memcpy(&pageno, rec, sizeof(pageno));
31 appendStringInfo(buf, "page %" PRId64, pageno);
32 }
33 else if (info == CLOG_TRUNCATE)
34 {
36
37 memcpy(&xlrec, rec, sizeof(xl_clog_truncate));
38 appendStringInfo(buf, "page %" PRId64 "; oldestXact %u",
39 xlrec.pageno, xlrec.oldestXact);
40 }
41}
uint8_t uint8
Definition c.h:681
int64_t int64
Definition c.h:680
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
#define CLOG_ZEROPAGE
Definition clog.h:53
#define CLOG_TRUNCATE
Definition clog.h:54
static char buf[DEFAULT_XLOG_SEG_SIZE]
void appendStringInfo(StringInfo str, const char *fmt,...)
Definition stringinfo.c:145
#define XLogRecGetInfo(decoder)
Definition xlogreader.h:410
#define XLogRecGetData(decoder)
Definition xlogreader.h:415

References appendStringInfo(), buf, CLOG_TRUNCATE, CLOG_ZEROPAGE, fb(), memcpy(), XLogRecGetData, and XLogRecGetInfo.

◆ clog_identify()

const char * clog_identify ( uint8  info)
extern

Definition at line 44 of file clogdesc.c.

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 XLR_INFO_MASK
Definition xlogrecord.h:62

References CLOG_TRUNCATE, CLOG_ZEROPAGE, fb(), and XLR_INFO_MASK.

◆ clog_redo()

void clog_redo ( XLogReaderState record)
extern

Definition at line 1089 of file clog.c.

1090{
1091 uint8 info = XLogRecGetInfo(record) & ~XLR_INFO_MASK;
1092
1093 /* Backup blocks are not used in clog records */
1095
1096 if (info == CLOG_ZEROPAGE)
1097 {
1098 int64 pageno;
1099
1100 memcpy(&pageno, XLogRecGetData(record), sizeof(pageno));
1102 }
1103 else if (info == CLOG_TRUNCATE)
1104 {
1106
1107 memcpy(&xlrec, XLogRecGetData(record), sizeof(xl_clog_truncate));
1108
1109 AdvanceOldestClogXid(xlrec.oldestXact);
1110
1112 }
1113 else
1114 elog(PANIC, "clog_redo: unknown op code %u", info);
1115}
#define Assert(condition)
Definition c.h:1002
#define PANIC
Definition elog.h:44
#define elog(elevel,...)
Definition elog.h:228
void SimpleLruTruncate(SlruDesc *ctl, int64 cutoffPage)
Definition slru.c:1458
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
Definition varsup.c:350
#define XLogRecHasAnyBlockRefs(decoder)
Definition xlogreader.h:417

References AdvanceOldestClogXid(), Assert, CLOG_TRUNCATE, CLOG_ZEROPAGE, elog, fb(), memcpy(), PANIC, SimpleLruTruncate(), SimpleLruZeroAndWritePage(), XactCtl, XLogRecGetData, XLogRecGetInfo, and XLogRecHasAnyBlockRefs.

◆ clogsyncfiletag()

int clogsyncfiletag ( const FileTag ftag,
char path 
)
extern

Definition at line 1121 of file clog.c.

1122{
1123 return SlruSyncFileTag(XactCtl, ftag, path);
1124}
int SlruSyncFileTag(SlruDesc *ctl, const FileTag *ftag, char *path)
Definition slru.c:1884

References SlruSyncFileTag(), and XactCtl.

◆ ExtendCLOG()

void ExtendCLOG ( TransactionId  newestXact)
extern

Definition at line 943 of file clog.c.

944{
945 int64 pageno;
946 LWLock *lock;
947
948 /*
949 * No work except at first XID of a page. But beware: just after
950 * wraparound, the first XID of page zero is FirstNormalTransactionId.
951 */
954 return;
955
957 lock = SimpleLruGetBankLock(XactCtl, pageno);
958
960
961 /* Zero the page and make a WAL entry about it */
962 SimpleLruZeroPage(XactCtl, pageno);
964
965 LWLockRelease(lock);
966}
static int64 TransactionIdToPage(TransactionId xid)
Definition clog.c:84
#define TransactionIdToPgIndex(xid)
Definition clog.c:89
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
Definition lwlock.c:1150
void LWLockRelease(LWLock *lock)
Definition lwlock.c:1767
@ LW_EXCLUSIVE
Definition lwlock.h:104
int SimpleLruZeroPage(SlruDesc *ctl, int64 pageno)
Definition slru.c:397
static LWLock * SimpleLruGetBankLock(SlruDesc *ctl, int64 pageno)
Definition slru.h:207
#define TransactionIdEquals(id1, id2)
Definition transam.h:43
#define FirstNormalTransactionId
Definition transam.h:34
XLogRecPtr XLogSimpleInsertInt64(RmgrId rmid, uint8 info, int64 value)
Definition xloginsert.c:547

References CLOG_ZEROPAGE, fb(), FirstNormalTransactionId, LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), SimpleLruGetBankLock(), SimpleLruZeroPage(), TransactionIdEquals, TransactionIdToPage(), TransactionIdToPgIndex, XactCtl, and XLogSimpleInsertInt64().

Referenced by GetNewTransactionId().

◆ StartupCLOG()

void StartupCLOG ( void  )
extern

Definition at line 861 of file clog.c.

862{
864 int64 pageno = TransactionIdToPage(xid);
865
866 /*
867 * Initialize our idea of the latest page number.
868 */
869 pg_atomic_write_u64(&XactCtl->shared->latest_page_number, pageno);
870}
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
Definition atomics.h:480
uint32 TransactionId
Definition c.h:795
FullTransactionId nextXid
Definition transam.h:220
#define XidFromFullTransactionId(x)
Definition transam.h:48
TransamVariablesData * TransamVariables
Definition varsup.c:37

References TransamVariablesData::nextXid, pg_atomic_write_u64(), TransactionIdToPage(), TransamVariables, XactCtl, and XidFromFullTransactionId.

Referenced by StartupXLOG().

◆ TransactionIdGetStatus()

XidStatus TransactionIdGetStatus ( TransactionId  xid,
XLogRecPtr lsn 
)
extern

Definition at line 743 of file clog.c.

744{
745 int64 pageno = TransactionIdToPage(xid);
746 int byteno = TransactionIdToByte(xid);
748 int slotno;
749 int lsnindex;
750 char *byteptr;
751 XidStatus status;
752
753 /* lock is acquired by SimpleLruReadPage_ReadOnly */
754
756 byteptr = XactCtl->shared->page_buffer[slotno] + byteno;
757
758 status = (*byteptr >> bshift) & CLOG_XACT_BITMASK;
759
761 *lsn = XactCtl->shared->group_lsn[lsnindex];
762
764
765 return status;
766}
#define CLOG_XACT_BITMASK
Definition clog.c:67
#define TransactionIdToBIndex(xid)
Definition clog.c:91
#define CLOG_BITS_PER_XACT
Definition clog.c:64
#define TransactionIdToByte(xid)
Definition clog.c:90
#define GetLSNIndex(slotno, xid)
Definition clog.c:97
int XidStatus
Definition clog.h:25
int SimpleLruReadPage_ReadOnly(SlruDesc *ctl, int64 pageno, const void *opaque_data)
Definition slru.c:654

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

Referenced by TransactionIdGetCommitLSN(), and TransactionLogFetch().

◆ TransactionIdSetTreeStatus()

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

Definition at line 192 of file clog.c.

194{
195 int64 pageno = TransactionIdToPage(xid); /* get page of parent */
196 int i;
197
200
201 /*
202 * See how many subxids, if any, are on the same page as the parent, if
203 * any.
204 */
205 for (i = 0; i < nsubxids; i++)
206 {
207 if (TransactionIdToPage(subxids[i]) != pageno)
208 break;
209 }
210
211 /*
212 * Do all items fit on a single page?
213 */
214 if (i == nsubxids)
215 {
216 /*
217 * Set the parent and all subtransactions in a single call
218 */
219 TransactionIdSetPageStatus(xid, nsubxids, subxids, status, lsn,
220 pageno, true);
221 }
222 else
223 {
225
226 /*
227 * If this is a commit then we care about doing this correctly (i.e.
228 * using the subcommitted intermediate status). By here, we know
229 * we're updating more than one page of clog, so we must mark entries
230 * that are *not* on the first page so that they show as subcommitted
231 * before we then return to update the status to fully committed.
232 *
233 * To avoid touching the first page twice, skip marking subcommitted
234 * for the subxids on that first page.
235 */
236 if (status == TRANSACTION_STATUS_COMMITTED)
238 subxids + nsubxids_on_first_page,
240
241 /*
242 * Now set the parent and subtransactions on same page as the parent,
243 * if any
244 */
245 pageno = TransactionIdToPage(xid);
247 lsn, pageno, false);
248
249 /*
250 * Now work through the rest of the subxids one clog page at a time,
251 * starting from the second page onwards, like we did above.
252 */
254 subxids + nsubxids_on_first_page,
255 status, lsn);
256 }
257}
static void TransactionIdSetPageStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn, int64 pageno, bool all_xact_same_page)
Definition clog.c:302
static void set_status_by_pages(int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
Definition clog.c:266
#define TRANSACTION_STATUS_ABORTED
Definition clog.h:29
#define TRANSACTION_STATUS_SUB_COMMITTED
Definition clog.h:30
#define TRANSACTION_STATUS_COMMITTED
Definition clog.h:28
int i
Definition isn.c:77

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

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

◆ TrimCLOG()

void TrimCLOG ( void  )
extern

Definition at line 876 of file clog.c.

877{
879 int64 pageno = TransactionIdToPage(xid);
880 LWLock *lock = SimpleLruGetBankLock(XactCtl, pageno);
881
883
884 /*
885 * Zero out the remainder of the current clog page. Under normal
886 * circumstances it should be zeroes already, but it seems at least
887 * theoretically possible that XLOG replay will have settled on a nextXID
888 * value that is less than the last XID actually used and marked by the
889 * previous database lifecycle (since subtransaction commit writes clog
890 * but makes no WAL entry). Let's just be safe. (We need not worry about
891 * pages beyond the current one, since those will be zeroed when first
892 * used. For the same reason, there is no need to do anything when
893 * nextXid is exactly at a page boundary; and it's likely that the
894 * "current" page doesn't exist yet in that case.)
895 */
896 if (TransactionIdToPgIndex(xid) != 0)
897 {
898 int byteno = TransactionIdToByte(xid);
900 int slotno;
901 char *byteptr;
902
903 slotno = SimpleLruReadPage(XactCtl, pageno, false, &xid);
904 byteptr = XactCtl->shared->page_buffer[slotno] + byteno;
905
906 /* Zero so-far-unused positions in the current byte */
907 *byteptr &= (1 << bshift) - 1;
908 /* Zero the rest of the page */
909 MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
910
911 XactCtl->shared->page_dirty[slotno] = true;
912 }
913
914 LWLockRelease(lock);
915}
#define MemSet(start, val, len)
Definition c.h:1147
int SimpleLruReadPage(SlruDesc *ctl, int64 pageno, bool write_ok, const void *opaque_data)
Definition slru.c:550

References CLOG_BITS_PER_XACT, fb(), LW_EXCLUSIVE, LWLockAcquire(), LWLockRelease(), MemSet, TransamVariablesData::nextXid, SimpleLruGetBankLock(), SimpleLruReadPage(), TransactionIdToBIndex, TransactionIdToByte, TransactionIdToPage(), TransactionIdToPgIndex, TransamVariables, XactCtl, and XidFromFullTransactionId.

Referenced by StartupXLOG().

◆ TruncateCLOG()

void TruncateCLOG ( TransactionId  oldestXact,
Oid  oldestxid_datoid 
)
extern

Definition at line 985 of file clog.c.

986{
988
989 /*
990 * The cutoff point is the start of the segment containing oldestXact. We
991 * pass the *page* containing oldestXact to SimpleLruTruncate.
992 */
993 cutoffPage = TransactionIdToPage(oldestXact);
994
995 /* Check to see if there's any files that could be removed */
997 return; /* nothing to remove */
998
999 /*
1000 * Advance oldestClogXid before truncating clog, so concurrent xact status
1001 * lookups can ensure they don't attempt to access truncated-away clog.
1002 *
1003 * It's only necessary to do this if we will actually truncate away clog
1004 * pages.
1005 */
1006 AdvanceOldestClogXid(oldestXact);
1007
1008 /*
1009 * Write XLOG record and flush XLOG to disk. We record the oldest xid
1010 * we're keeping information about here so we can ensure that it's always
1011 * ahead of clog truncation in case we crash, and so a standby finds out
1012 * the new valid xid before the next checkpoint.
1013 */
1015
1016 /* Now we can remove the old CLOG segment(s) */
1018}
static void WriteTruncateXlogRec(int64 pageno, TransactionId oldestXact, Oid oldestXactDb)
Definition clog.c:1070
bool SlruScanDirectory(SlruDesc *ctl, SlruScanCallback callback, void *data)
Definition slru.c:1844
bool SlruScanDirCbReportPresence(SlruDesc *ctl, char *filename, int64 segpage, void *data)
Definition slru.c:1765

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

Referenced by vac_truncate_clog().