48 #define LZ4_MAX_BLCKSZ LZ4_COMPRESSBOUND(BLCKSZ)
50 #define LZ4_MAX_BLCKSZ 0
54 #define ZSTD_MAX_BLCKSZ ZSTD_COMPRESSBOUND(BLCKSZ)
56 #define ZSTD_MAX_BLCKSZ 0
59 #define PGLZ_MAX_BLCKSZ PGLZ_MAX_OUTPUT(BLCKSZ)
62 #define COMPRESS_BUFSIZE Max(Max(PGLZ_MAX_BLCKSZ, LZ4_MAX_BLCKSZ), ZSTD_MAX_BLCKSZ)
116 #define SizeOfXlogOrigin (sizeof(RepOriginId) + sizeof(char))
117 #define SizeOfXLogTransactionId (sizeof(TransactionId) + sizeof(char))
119 #define HEADER_SCRATCH_SIZE \
120 (SizeOfXLogRecord + \
121 MaxSizeOfXLogRecordBlockHeader * (XLR_MAX_BLOCK_ID + 1) + \
122 SizeOfXLogRecordDataHeaderLong + SizeOfXlogOrigin + \
123 SizeOfXLogTransactionId)
140 bool *topxid_included);
157 elog(
ERROR,
"cannot make new WAL entries during recovery");
160 elog(
ERROR,
"XLogBeginInsert was already called");
194 elog(
ERROR,
"maximum number of WAL record block references exceeded");
195 nbuffers = max_block_id + 1;
259 #ifdef USE_ASSERT_CHECKING
267 elog(
ERROR,
"too many registered buffers");
275 regbuf->
flags = flags;
283 #ifdef USE_ASSERT_CHECKING
291 if (
i == block_id || !regbuf_old->
in_use)
301 regbuf->in_use =
true;
320 elog(
ERROR,
"too many registered buffers");
326 regbuf->
block = blknum;
328 regbuf->
flags = flags;
336 #ifdef USE_ASSERT_CHECKING
344 if (
i == block_id || !regbuf_old->
in_use)
354 regbuf->in_use =
true;
415 elog(
ERROR,
"no block with id %d registered with WAL insertion",
432 errdetail_internal(
"Registering more than maximum %u bytes allowed to block %u: current %u bytes, adding %u bytes.",
480 elog(
ERROR,
"XLogBeginInsert was not called");
489 elog(
PANIC,
"invalid xlog info mask %02X", info);
491 TRACE_POSTGRESQL_WAL_INSERT(rmid, info);
508 bool topxid_included =
false;
521 &fpw_lsn, &num_fpi, &topxid_included);
550 XLogRecPtr *fpw_lsn,
int *num_fpi,
bool *topxid_included)
553 uint64 total_len = 0;
598 bool is_compressed =
false;
608 needs_backup =
false;
610 needs_backup =
false;
634 needs_data = !needs_backup;
651 const char *page = regbuf->
page;
652 uint16 compressed_len = 0;
710 rdt_datas_last = rdt_datas_last->
next;
726 bimg.
length = compressed_len;
739 elog(
ERROR,
"LZ4 is not supported by this build");
747 elog(
ERROR,
"zstd is not supported by this build");
758 rdt_datas_last->
len = compressed_len;
766 rdt_datas_last->
data = page;
767 rdt_datas_last->
len = BLCKSZ;
772 rdt_datas_last->
data = page;
776 rdt_datas_last = rdt_datas_last->
next;
778 rdt_datas_last->
data =
780 rdt_datas_last->
len =
815 prev_regbuf = regbuf;
826 memcpy(scratch, &cbimg,
855 *topxid_included =
true;
878 memcpy(scratch, &mainrdata_len_4b,
sizeof(
uint32));
879 scratch +=
sizeof(
uint32);
890 rdt_datas_last->
next = NULL;
918 errdetail_internal(
"WAL record would be %llu bytes (of maximum %u bytes); rmid %u flags %u.",
931 rechdr->
xl_crc = rdata_crc;
947 int32 orig_len = BLCKSZ - hole_length;
949 int32 extra_bytes = 0;
953 if (hole_length != 0)
956 memcpy(tmp.
data, page, hole_offset);
957 memcpy(tmp.
data + hole_offset,
958 page + (hole_offset + hole_length),
959 BLCKSZ - (hole_length + hole_offset));
984 elog(
ERROR,
"LZ4 is not supported by this build");
991 ZSTD_CLEVEL_DEFAULT);
992 if (ZSTD_isError(
len))
995 elog(
ERROR,
"zstd is not supported by this build");
1011 len + extra_bytes < orig_len)
1110 memcpy(copied_buffer.
data, origdata,
lower);
1114 memcpy(copied_buffer.
data, origdata, BLCKSZ);
1144 Page page,
bool page_std)
1195 while (
i < num_pages)
1197 int batch_start =
i;
1212 for (
j = batch_start;
j <
i;
j++)
1249 return log_newpage(&rlocator, forknum, blkno, page, page_std);
1289 while (blkno < endblk)
1313 bufpack[nbufs++] =
buf;
1327 for (
i = 0;
i < nbufs;
i++)
1335 for (
i = 0;
i < nbufs;
i++)
1350 #ifdef USE_ASSERT_CHECKING
1358 size_t max_required =
1368 "WAL record construction",
bool BufferIsExclusiveLocked(Buffer buffer)
void BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum)
bool BufferIsDirty(Buffer buffer)
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
void UnlockReleaseBuffer(Buffer buffer)
void MarkBufferDirty(Buffer buffer)
void LockBuffer(Buffer buffer, int mode)
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
static Page BufferGetPage(Buffer buffer)
static Block BufferGetBlock(Buffer buffer)
#define BUFFER_LOCK_EXCLUSIVE
PageHeaderData * PageHeader
#define SizeOfPageHeaderData
static bool PageIsNew(Page page)
static void PageSetLSN(Page page, XLogRecPtr lsn)
static XLogRecPtr PageGetLSN(const char *page)
#define Assert(condition)
#define MemSet(start, val, len)
int errmsg_internal(const char *fmt,...)
int errdetail_internal(const char *fmt,...)
#define ereport(elevel,...)
volatile uint32 CritSectionCount
MemoryContext TopMemoryContext
void * MemoryContextAllocZero(MemoryContext context, Size size)
void * repalloc(void *pointer, Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define AllocSetContextCreate
#define ALLOCSET_DEFAULT_SIZES
#define AllocSizeIsValid(size)
#define IsBootstrapProcessingMode()
#define START_CRIT_SECTION()
#define CHECK_FOR_INTERRUPTS()
#define END_CRIT_SECTION()
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
RepOriginId replorigin_session_origin
#define InvalidRepOriginId
#define XLOG_FPI_FOR_HINT
#define COMP_CRC32C(crc, data, len)
const PGLZ_Strategy *const PGLZ_strategy_default
int32 pglz_compress(const char *source, int32 slen, char *dest, const PGLZ_Strategy *strategy)
static rewind_source * source
#define DELAY_CHKPT_START
struct RelFileLocator RelFileLocator
#define RelFileLocatorEquals(locator1, locator2)
struct XLogRecData * next
XLogRecData bkp_rdatas[2]
char compressed_page[COMPRESS_BUFSIZE]
TransactionId GetTopTransactionIdIfAny(void)
TransactionId GetCurrentTransactionIdIfAny(void)
bool IsSubxactTopXidLogPending(void)
void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p)
XLogRecPtr GetRedoRecPtr(void)
static XLogRecPtr RedoRecPtr
XLogRecPtr XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn, uint8 flags, int num_fpi, bool topxid_included)
bool XLogInsertAllowed(void)
bool * wal_consistency_checking
#define XLOG_INCLUDE_ORIGIN
#define SizeOfXLogLongPHD
#define InvalidXLogRecPtr
static XLogRecData * mainrdata_head
void XLogRegisterBufData(uint8 block_id, const char *data, uint32 len)
static int max_registered_buffers
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
static uint8 curinsert_flags
bool XLogCheckBufferNeedsBackup(Buffer buffer)
static uint64 mainrdata_len
XLogRecPtr XLogSaveBufferForHint(Buffer buffer, bool buffer_std)
static bool begininsert_called
static int max_registered_block_id
XLogRecPtr log_newpage(RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blkno, Page page, bool page_std)
void InitXLogInsert(void)
void XLogSetRecordFlags(uint8 flags)
void XLogRegisterBlock(uint8 block_id, RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blknum, const char *page, uint8 flags)
void XLogRegisterData(const char *data, uint32 len)
void log_newpages(RelFileLocator *rlocator, ForkNumber forknum, int num_pages, BlockNumber *blknos, Page *pages, bool page_std)
static XLogRecData * mainrdata_last
static MemoryContext xloginsert_cxt
void log_newpage_range(Relation rel, ForkNumber forknum, BlockNumber startblk, BlockNumber endblk, bool page_std)
void XLogResetInsertion(void)
XLogRecPtr log_newpage_buffer(Buffer buffer, bool page_std)
static bool XLogCompressBackupBlock(const char *page, uint16 hole_offset, uint16 hole_length, char *dest, uint16 *dlen)
static XLogRecData hdr_rdt
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
static XLogRecData * XLogRecordAssemble(RmgrId rmid, uint8 info, XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr *fpw_lsn, int *num_fpi, bool *topxid_included)
static char * hdr_scratch
static XLogRecData * rdatas
void XLogBeginInsert(void)
void XLogEnsureRecordSpace(int max_block_id, int ndatas)
static registered_buffer * registered_buffers
#define HEADER_SCRATCH_SIZE
#define XLR_NORMAL_MAX_BLOCK_ID
#define REGBUF_FORCE_IMAGE
#define XLR_NORMAL_RDATAS
size_t DecodeXLogRecordRequiredSpace(size_t xl_tot_len)
#define SizeOfXLogRecordBlockImageHeader
#define XLogRecordMaxSize
#define BKPIMAGE_COMPRESS_ZSTD
#define BKPBLOCK_HAS_DATA
#define BKPIMAGE_HAS_HOLE
#define XLR_BLOCK_ID_DATA_LONG
#define BKPBLOCK_WILL_INIT
#define XLR_RMGR_INFO_MASK
#define BKPIMAGE_COMPRESS_LZ4
#define XLR_BLOCK_ID_TOPLEVEL_XID
#define XLR_BLOCK_ID_DATA_SHORT
#define SizeOfXLogRecordBlockCompressHeader
#define BKPBLOCK_SAME_REL
#define XLR_SPECIAL_REL_UPDATE
#define SizeOfXLogRecordBlockHeader
#define BKPIMAGE_COMPRESS_PGLZ
#define XLR_BLOCK_ID_ORIGIN
#define BKPBLOCK_HAS_IMAGE
#define XLR_CHECK_CONSISTENCY