62 #define CLOG_BITS_PER_XACT 2
63 #define CLOG_XACTS_PER_BYTE 4
64 #define CLOG_XACTS_PER_PAGE (BLCKSZ * CLOG_XACTS_PER_BYTE)
65 #define CLOG_XACT_BITMASK ((1 << CLOG_BITS_PER_XACT) - 1)
72 #define CLOG_MAX_ALLOWED_BUFFERS \
73 Min(SLRU_MAX_ALLOWED_BUFFERS, \
74 (((MaxTransactionId / 2) + (CLOG_XACTS_PER_PAGE - 1)) / CLOG_XACTS_PER_PAGE))
87 #define TransactionIdToPgIndex(xid) ((xid) % (TransactionId) CLOG_XACTS_PER_PAGE)
88 #define TransactionIdToByte(xid) (TransactionIdToPgIndex(xid) / CLOG_XACTS_PER_BYTE)
89 #define TransactionIdToBIndex(xid) ((xid) % (TransactionId) CLOG_XACTS_PER_BYTE)
92 #define CLOG_XACTS_PER_LSN_GROUP 32
93 #define CLOG_LSNS_PER_PAGE (CLOG_XACTS_PER_PAGE / CLOG_XACTS_PER_LSN_GROUP)
95 #define GetLSNIndex(slotno, xid) ((slotno) * CLOG_LSNS_PER_PAGE + \
96 ((xid) % (TransactionId) CLOG_XACTS_PER_PAGE) / CLOG_XACTS_PER_LSN_GROUP)
103 #define THRESHOLD_SUBTRANS_CLOG_OPT 5
110 #define XactCtl (&XactCtlData)
121 bool all_xact_same_page);
196 for (
i = 0;
i < nsubxids;
i++)
215 int nsubxids_on_first_page =
i;
229 subxids + nsubxids_on_first_page,
245 subxids + nsubxids_on_first_page,
274 if (nextpageno != pageno)
278 }
while (
i < nsubxids);
281 num_on_page, subxids + offset,
282 status, lsn, pageno,
false);
296 bool all_xact_same_page)
302 "group clog threshold less than PGPROC cached subxids");
321 if (all_xact_same_page && xid ==
MyProc->
xid &&
402 for (
i = 0;
i < nsubxids;
i++)
416 for (
i = 0;
i < nsubxids;
i++)
422 XactCtl->shared->page_dirty[slotno] =
true;
549 while (extraWaits-- > 0)
593 if (thispageno != prevpageno)
597 if (prevlock != lock)
603 prevpageno = thispageno;
624 if (prevlock != NULL)
671 XactCtl->shared->page_number[slotno]),
674 byteptr =
XactCtl->shared->page_buffer[slotno] + byteno;
699 byteval |= (status << bshift);
714 if (
XactCtl->shared->group_lsn[lsnindex] < lsn)
715 XactCtl->shared->group_lsn[lsnindex] = lsn;
748 byteptr =
XactCtl->shared->page_buffer[slotno] + byteno;
753 *lsn =
XactCtl->shared->group_lsn[lsnindex];
920 byteptr =
XactCtl->shared->page_buffer[slotno] + byteno;
923 *byteptr &= (1 << bshift) - 1;
925 MemSet(byteptr + 1, 0, BLCKSZ - byteno - 1);
927 XactCtl->shared->page_dirty[slotno] =
true;
944 TRACE_POSTGRESQL_CLOG_CHECKPOINT_START(
true);
946 TRACE_POSTGRESQL_CLOG_CHECKPOINT_DONE(
true);
1142 elog(
PANIC,
"clog_redo: unknown op code %u", info);
static bool pg_atomic_compare_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 *expected, uint32 newval)
static void pg_atomic_write_u64(volatile pg_atomic_uint64 *ptr, uint64 val)
#define pg_write_barrier()
static void pg_atomic_write_u32(volatile pg_atomic_uint32 *ptr, uint32 val)
static uint32 pg_atomic_read_u32(volatile pg_atomic_uint32 *ptr)
static uint32 pg_atomic_exchange_u32(volatile pg_atomic_uint32 *ptr, uint32 newval)
#define Assert(condition)
#define MemSet(start, val, len)
#define StaticAssertDecl(condition, errmessage)
#define CLOG_MAX_ALLOWED_BUFFERS
static void WriteZeroPageXlogRec(int64 pageno)
static int ZeroCLOGPage(int64 pageno, bool writeXlog)
#define CLOG_XACT_BITMASK
#define CLOG_XACTS_PER_PAGE
#define THRESHOLD_SUBTRANS_CLOG_OPT
static void TransactionIdSetStatusBit(TransactionId xid, XidStatus status, XLogRecPtr lsn, int slotno)
XidStatus TransactionIdGetStatus(TransactionId xid, XLogRecPtr *lsn)
void TransactionIdSetTreeStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
#define TransactionIdToBIndex(xid)
static int CLOGShmemBuffers(void)
void ExtendCLOG(TransactionId newestXact)
void clog_redo(XLogReaderState *record)
static bool CLOGPagePrecedes(int64 page1, int64 page2)
void TruncateCLOG(TransactionId oldestXact, Oid oldestxid_datoid)
bool check_transaction_buffers(int *newval, void **extra, GucSource source)
static void TransactionIdSetPageStatus(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn, int64 pageno, bool all_xact_same_page)
int clogsyncfiletag(const FileTag *ftag, char *path)
#define CLOG_BITS_PER_XACT
#define CLOG_LSNS_PER_PAGE
static int64 TransactionIdToPage(TransactionId xid)
#define TransactionIdToByte(xid)
#define TransactionIdToPgIndex(xid)
static void set_status_by_pages(int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn)
static bool TransactionGroupUpdateXidStatus(TransactionId xid, XidStatus status, XLogRecPtr lsn, int64 pageno)
static void TransactionIdSetPageStatusInternal(TransactionId xid, int nsubxids, TransactionId *subxids, XidStatus status, XLogRecPtr lsn, int64 pageno)
#define GetLSNIndex(slotno, xid)
void CheckPointCLOG(void)
static SlruCtlData XactCtlData
static void WriteTruncateXlogRec(int64 pageno, TransactionId oldestXact, Oid oldestXactDb)
#define TRANSACTION_STATUS_IN_PROGRESS
#define TRANSACTION_STATUS_ABORTED
#define TRANSACTION_STATUS_SUB_COMMITTED
#define TRANSACTION_STATUS_COMMITTED
void SetConfigOption(const char *name, const char *value, GucContext context, GucSource source)
bool LWLockAcquire(LWLock *lock, LWLockMode mode)
bool LWLockHeldByMeInMode(LWLock *lock, LWLockMode mode)
void LWLockRelease(LWLock *lock)
bool LWLockConditionalAcquire(LWLock *lock, LWLockMode mode)
static rewind_source * source
void PGSemaphoreUnlock(PGSemaphore sema)
void PGSemaphoreLock(PGSemaphore sema)
#define GetPGProcByNumber(n)
#define PGPROC_MAX_CACHED_SUBXIDS
#define INVALID_PROC_NUMBER
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)
int SimpleLruReadPage_ReadOnly(SlruCtl ctl, int64 pageno, TransactionId xid)
void SimpleLruWritePage(SlruCtl ctl, int slotno)
void SimpleLruWriteAll(SlruCtl ctl, bool allow_redirtied)
int SimpleLruAutotuneBuffers(int divisor, int max)
bool SlruScanDirectory(SlruCtl ctl, SlruScanCallback callback, void *data)
int SimpleLruReadPage(SlruCtl ctl, int64 pageno, bool write_ok, TransactionId xid)
int SlruSyncFileTag(SlruCtl ctl, const FileTag *ftag, char *path)
int SimpleLruZeroPage(SlruCtl ctl, int64 pageno)
void SimpleLruTruncate(SlruCtl ctl, int64 cutoffPage)
Size SimpleLruShmemSize(int nslots, int nlsns)
bool SlruScanDirCbReportPresence(SlruCtl ctl, char *filename, int64 segpage, void *data)
bool check_slru_buffers(const char *name, int *newval)
static LWLock * SimpleLruGetBankLock(SlruCtl ctl, int64 pageno)
#define SlruPagePrecedesUnitTests(ctl, per_page)
XLogRecPtr clogGroupMemberLsn
TransactionId clogGroupMemberXid
int64 clogGroupMemberPage
pg_atomic_uint32 clogGroupNext
XidStatus clogGroupMemberXidStatus
XidCacheStatus subxidStatus
pg_atomic_uint32 clogGroupFirst
FullTransactionId nextXid
TransactionId xids[PGPROC_MAX_CACHED_SUBXIDS]
bool TransactionIdPrecedes(TransactionId id1, TransactionId id2)
#define InvalidTransactionId
#define TransactionIdEquals(id1, id2)
#define XidFromFullTransactionId(x)
#define FirstNormalTransactionId
#define TransactionIdIsValid(xid)
void AdvanceOldestClogXid(TransactionId oldest_datfrozenxid)
TransamVariablesData * TransamVariables
static void pgstat_report_wait_start(uint32 wait_event_info)
static void pgstat_report_wait_end(void)
void XLogFlush(XLogRecPtr record)
#define XLogRecPtrIsInvalid(r)
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
void XLogRegisterData(const char *data, uint32 len)
void XLogBeginInsert(void)
#define XLogRecGetInfo(decoder)
#define XLogRecGetData(decoder)
#define XLogRecHasAnyBlockRefs(decoder)