PostgreSQL Source Code  git master
xloginsert.c File Reference
#include "postgres.h"
#include "access/xact.h"
#include "access/xlog.h"
#include "access/xlog_internal.h"
#include "access/xloginsert.h"
#include "catalog/pg_control.h"
#include "common/pg_lzcompress.h"
#include "executor/instrument.h"
#include "miscadmin.h"
#include "pg_trace.h"
#include "replication/origin.h"
#include "storage/bufmgr.h"
#include "storage/proc.h"
#include "utils/memutils.h"
Include dependency graph for xloginsert.c:

Go to the source code of this file.

Data Structures

struct  registered_buffer
 

Macros

#define LZ4_MAX_BLCKSZ   0
 
#define PGLZ_MAX_BLCKSZ   PGLZ_MAX_OUTPUT(BLCKSZ)
 
#define COMPRESS_BUFSIZE   Max(PGLZ_MAX_BLCKSZ, LZ4_MAX_BLCKSZ)
 
#define SizeOfXlogOrigin   (sizeof(RepOriginId) + sizeof(char))
 
#define SizeOfXLogTransactionId   (sizeof(TransactionId) + sizeof(char))
 
#define HEADER_SCRATCH_SIZE
 

Functions

static XLogRecDataXLogRecordAssemble (RmgrId rmid, uint8 info, XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr *fpw_lsn, int *num_fpi)
 
static bool XLogCompressBackupBlock (char *page, uint16 hole_offset, uint16 hole_length, char *dest, uint16 *dlen)
 
void XLogBeginInsert (void)
 
void XLogEnsureRecordSpace (int max_block_id, int ndatas)
 
void XLogResetInsertion (void)
 
void XLogRegisterBuffer (uint8 block_id, Buffer buffer, uint8 flags)
 
void XLogRegisterBlock (uint8 block_id, RelFileNode *rnode, ForkNumber forknum, BlockNumber blknum, Page page, uint8 flags)
 
void XLogRegisterData (char *data, int len)
 
void XLogRegisterBufData (uint8 block_id, char *data, int len)
 
void XLogSetRecordFlags (uint8 flags)
 
XLogRecPtr XLogInsert (RmgrId rmid, uint8 info)
 
bool XLogCheckBufferNeedsBackup (Buffer buffer)
 
XLogRecPtr XLogSaveBufferForHint (Buffer buffer, bool buffer_std)
 
XLogRecPtr log_newpage (RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno, Page page, bool page_std)
 
void log_newpages (RelFileNode *rnode, ForkNumber forkNum, int num_pages, BlockNumber *blknos, Page *pages, bool page_std)
 
XLogRecPtr log_newpage_buffer (Buffer buffer, bool page_std)
 
void log_newpage_range (Relation rel, ForkNumber forkNum, BlockNumber startblk, BlockNumber endblk, bool page_std)
 
void InitXLogInsert (void)
 

Variables

static registered_bufferregistered_buffers
 
static int max_registered_buffers
 
static int max_registered_block_id = 0
 
static XLogRecDatamainrdata_head
 
static XLogRecDatamainrdata_last = (XLogRecData *) &mainrdata_head
 
static uint32 mainrdata_len
 
static uint8 curinsert_flags = 0
 
static XLogRecData hdr_rdt
 
static char * hdr_scratch = NULL
 
static XLogRecDatardatas
 
static int num_rdatas
 
static int max_rdatas
 
static bool begininsert_called = false
 
static MemoryContext xloginsert_cxt
 

Macro Definition Documentation

◆ COMPRESS_BUFSIZE

#define COMPRESS_BUFSIZE   Max(PGLZ_MAX_BLCKSZ, LZ4_MAX_BLCKSZ)

Definition at line 49 of file xloginsert.c.

Referenced by XLogCompressBackupBlock().

◆ HEADER_SCRATCH_SIZE

#define HEADER_SCRATCH_SIZE
Value:
MaxSizeOfXLogRecordBlockHeader * (XLR_MAX_BLOCK_ID + 1) + \
#define SizeOfXlogOrigin
Definition: xloginsert.c:103
#define SizeOfXLogTransactionId
Definition: xloginsert.c:104
#define XLR_MAX_BLOCK_ID
Definition: xlogrecord.h:226
#define SizeOfXLogRecord
Definition: xlogrecord.h:55
#define SizeOfXLogRecordDataHeaderLong
Definition: xlogrecord.h:212

Definition at line 106 of file xloginsert.c.

Referenced by InitXLogInsert().

◆ LZ4_MAX_BLCKSZ

#define LZ4_MAX_BLCKSZ   0

Definition at line 44 of file xloginsert.c.

◆ PGLZ_MAX_BLCKSZ

#define PGLZ_MAX_BLCKSZ   PGLZ_MAX_OUTPUT(BLCKSZ)

Definition at line 47 of file xloginsert.c.

◆ SizeOfXlogOrigin

#define SizeOfXlogOrigin   (sizeof(RepOriginId) + sizeof(char))

Definition at line 103 of file xloginsert.c.

◆ SizeOfXLogTransactionId

#define SizeOfXLogTransactionId   (sizeof(TransactionId) + sizeof(char))

Definition at line 104 of file xloginsert.c.

Function Documentation

◆ InitXLogInsert()

void InitXLogInsert ( void  )

Definition at line 1251 of file xloginsert.c.

References ALLOCSET_DEFAULT_SIZES, AllocSetContextCreate, hdr_scratch, HEADER_SCRATCH_SIZE, max_rdatas, max_registered_buffers, MemoryContextAlloc(), MemoryContextAllocZero(), TopMemoryContext, XLR_NORMAL_MAX_BLOCK_ID, and XLR_NORMAL_RDATAS.

Referenced by CreateCheckPoint(), and InitXLOGAccess().

1252 {
1253  /* Initialize the working areas */
1254  if (xloginsert_cxt == NULL)
1255  {
1257  "WAL record construction",
1259  }
1260 
1261  if (registered_buffers == NULL)
1262  {
1265  sizeof(registered_buffer) * (XLR_NORMAL_MAX_BLOCK_ID + 1));
1267  }
1268  if (rdatas == NULL)
1269  {
1271  sizeof(XLogRecData) * XLR_NORMAL_RDATAS);
1273  }
1274 
1275  /*
1276  * Allocate a buffer to hold the header information for a WAL record.
1277  */
1278  if (hdr_scratch == NULL)
1281 }
#define AllocSetContextCreate
Definition: memutils.h:173
#define HEADER_SCRATCH_SIZE
Definition: xloginsert.c:106
#define XLR_NORMAL_RDATAS
Definition: xloginsert.h:28
static int max_registered_buffers
Definition: xloginsert.c:77
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:195
static int max_rdatas
Definition: xloginsert.c:117
MemoryContext TopMemoryContext
Definition: mcxt.c:48
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
#define XLR_NORMAL_MAX_BLOCK_ID
Definition: xloginsert.h:27
static char * hdr_scratch
Definition: xloginsert.c:101
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
static MemoryContext xloginsert_cxt
Definition: xloginsert.c:122
static XLogRecData * rdatas
Definition: xloginsert.c:115

◆ log_newpage()

XLogRecPtr log_newpage ( RelFileNode rnode,
ForkNumber  forkNum,
BlockNumber  blkno,
Page  page,
bool  page_std 
)

Definition at line 1050 of file xloginsert.c.

References PageIsNew, PageSetLSN, REGBUF_FORCE_IMAGE, REGBUF_STANDARD, XLOG_FPI, XLogBeginInsert(), XLogInsert(), and XLogRegisterBlock().

Referenced by _bt_blwritepage(), _hash_alloc_buckets(), _hash_init(), blbuildempty(), btbuildempty(), end_heap_rewrite(), gist_indexsortbuild(), log_newpage_buffer(), raw_heap_insert(), RelationCopyStorage(), and spgbuildempty().

1052 {
1053  int flags;
1054  XLogRecPtr recptr;
1055 
1056  flags = REGBUF_FORCE_IMAGE;
1057  if (page_std)
1058  flags |= REGBUF_STANDARD;
1059 
1060  XLogBeginInsert();
1061  XLogRegisterBlock(0, rnode, forkNum, blkno, page, flags);
1062  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1063 
1064  /*
1065  * The page may be uninitialized. If so, we can't set the LSN because that
1066  * would corrupt the page.
1067  */
1068  if (!PageIsNew(page))
1069  {
1070  PageSetLSN(page, recptr);
1071  }
1072 
1073  return recptr;
1074 }
void XLogRegisterBlock(uint8 block_id, RelFileNode *rnode, ForkNumber forknum, BlockNumber blknum, Page page, uint8 flags)
Definition: xloginsert.c:285
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define XLOG_FPI
Definition: pg_control.h:78
#define PageIsNew(page)
Definition: bufpage.h:229
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368

◆ log_newpage_buffer()

XLogRecPtr log_newpage_buffer ( Buffer  buffer,
bool  page_std 
)

Definition at line 1144 of file xloginsert.c.

References Assert, BufferGetPage, BufferGetTag(), CritSectionCount, and log_newpage().

Referenced by brin_initialize_empty_new_buffer(), brinbuildempty(), FreeSpaceMapPrepareTruncateRel(), ginbuildempty(), gistbuildempty(), heap_force_common(), lazy_scan_heap(), and visibilitymap_prepare_truncate().

1145 {
1146  Page page = BufferGetPage(buffer);
1147  RelFileNode rnode;
1148  ForkNumber forkNum;
1149  BlockNumber blkno;
1150 
1151  /* Shared buffers should be modified in a critical section. */
1152  Assert(CritSectionCount > 0);
1153 
1154  BufferGetTag(buffer, &rnode, &forkNum, &blkno);
1155 
1156  return log_newpage(&rnode, forkNum, blkno, page, page_std);
1157 }
uint32 BlockNumber
Definition: block.h:31
volatile uint32 CritSectionCount
Definition: globals.c:41
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
ForkNumber
Definition: relpath.h:40
#define Assert(condition)
Definition: c.h:804
XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno, Page page, bool page_std)
Definition: xloginsert.c:1050
void BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum)
Definition: bufmgr.c:2769
Pointer Page
Definition: bufpage.h:78

◆ log_newpage_range()

void log_newpage_range ( Relation  rel,
ForkNumber  forkNum,
BlockNumber  startblk,
BlockNumber  endblk,
bool  page_std 
)

Definition at line 1177 of file xloginsert.c.

References buf, BUFFER_LOCK_EXCLUSIVE, BufferGetPage, CHECK_FOR_INTERRUPTS, END_CRIT_SECTION, i, LockBuffer(), MarkBufferDirty(), PageIsNew, PageSetLSN, RBM_NORMAL, ReadBufferExtended(), REGBUF_FORCE_IMAGE, REGBUF_STANDARD, START_CRIT_SECTION, UnlockReleaseBuffer(), XLOG_FPI, XLogBeginInsert(), XLogEnsureRecordSpace(), XLogInsert(), XLogRegisterBuffer(), and XLR_MAX_BLOCK_ID.

Referenced by ginbuild(), gistbuild(), smgrDoPendingSyncs(), and spgbuild().

1180 {
1181  int flags;
1182  BlockNumber blkno;
1183 
1184  flags = REGBUF_FORCE_IMAGE;
1185  if (page_std)
1186  flags |= REGBUF_STANDARD;
1187 
1188  /*
1189  * Iterate over all the pages in the range. They are collected into
1190  * batches of XLR_MAX_BLOCK_ID pages, and a single WAL-record is written
1191  * for each batch.
1192  */
1194 
1195  blkno = startblk;
1196  while (blkno < endblk)
1197  {
1198  Buffer bufpack[XLR_MAX_BLOCK_ID];
1199  XLogRecPtr recptr;
1200  int nbufs;
1201  int i;
1202 
1204 
1205  /* Collect a batch of blocks. */
1206  nbufs = 0;
1207  while (nbufs < XLR_MAX_BLOCK_ID && blkno < endblk)
1208  {
1209  Buffer buf = ReadBufferExtended(rel, forkNum, blkno,
1210  RBM_NORMAL, NULL);
1211 
1213 
1214  /*
1215  * Completely empty pages are not WAL-logged. Writing a WAL record
1216  * would change the LSN, and we don't want that. We want the page
1217  * to stay empty.
1218  */
1219  if (!PageIsNew(BufferGetPage(buf)))
1220  bufpack[nbufs++] = buf;
1221  else
1222  UnlockReleaseBuffer(buf);
1223  blkno++;
1224  }
1225 
1226  /* Write WAL record for this batch. */
1227  XLogBeginInsert();
1228 
1230  for (i = 0; i < nbufs; i++)
1231  {
1232  XLogRegisterBuffer(i, bufpack[i], flags);
1233  MarkBufferDirty(bufpack[i]);
1234  }
1235 
1236  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1237 
1238  for (i = 0; i < nbufs; i++)
1239  {
1240  PageSetLSN(BufferGetPage(bufpack[i]), recptr);
1241  UnlockReleaseBuffer(bufpack[i]);
1242  }
1243  END_CRIT_SECTION();
1244  }
1245 }
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1565
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:232
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:741
#define END_CRIT_SECTION()
Definition: miscadmin.h:149
#define START_CRIT_SECTION()
Definition: miscadmin.h:147
uint32 BlockNumber
Definition: block.h:31
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:98
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3791
static char * buf
Definition: pg_test_fsync.c:68
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
#define XLR_MAX_BLOCK_ID
Definition: xlogrecord.h:226
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4007
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void XLogEnsureRecordSpace(int max_block_id, int ndatas)
Definition: xloginsert.c:161
#define XLOG_FPI
Definition: pg_control.h:78
#define PageIsNew(page)
Definition: bufpage.h:229
int i
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:120
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368
int Buffer
Definition: buf.h:23

◆ log_newpages()

void log_newpages ( RelFileNode rnode,
ForkNumber  forkNum,
int  num_pages,
BlockNumber blknos,
Page pages,
bool  page_std 
)

Definition at line 1082 of file xloginsert.c.

References i, PageIsNew, PageSetLSN, REGBUF_FORCE_IMAGE, REGBUF_STANDARD, XLOG_FPI, XLogBeginInsert(), XLogEnsureRecordSpace(), XLogInsert(), XLogRegisterBlock(), and XLR_MAX_BLOCK_ID.

Referenced by gist_indexsortbuild_flush_ready_pages().

1084 {
1085  int flags;
1086  XLogRecPtr recptr;
1087  int i;
1088  int j;
1089 
1090  flags = REGBUF_FORCE_IMAGE;
1091  if (page_std)
1092  flags |= REGBUF_STANDARD;
1093 
1094  /*
1095  * Iterate over all the pages. They are collected into batches of
1096  * XLR_MAX_BLOCK_ID pages, and a single WAL-record is written for each
1097  * batch.
1098  */
1100 
1101  i = 0;
1102  while (i < num_pages)
1103  {
1104  int batch_start = i;
1105  int nbatch;
1106 
1107  XLogBeginInsert();
1108 
1109  nbatch = 0;
1110  while (nbatch < XLR_MAX_BLOCK_ID && i < num_pages)
1111  {
1112  XLogRegisterBlock(nbatch, rnode, forkNum, blknos[i], pages[i], flags);
1113  i++;
1114  nbatch++;
1115  }
1116 
1117  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1118 
1119  for (j = batch_start; j < i; j++)
1120  {
1121  /*
1122  * The page may be uninitialized. If so, we can't set the LSN
1123  * because that would corrupt the page.
1124  */
1125  if (!PageIsNew(pages[j]))
1126  {
1127  PageSetLSN(pages[j], recptr);
1128  }
1129  }
1130  }
1131 }
void XLogRegisterBlock(uint8 block_id, RelFileNode *rnode, ForkNumber forknum, BlockNumber blknum, Page page, uint8 flags)
Definition: xloginsert.c:285
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define XLR_MAX_BLOCK_ID
Definition: xlogrecord.h:226
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void XLogEnsureRecordSpace(int max_block_id, int ndatas)
Definition: xloginsert.c:161
#define XLOG_FPI
Definition: pg_control.h:78
#define PageIsNew(page)
Definition: bufpage.h:229
int i
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define PageSetLSN(page, lsn)
Definition: bufpage.h:368

◆ XLogBeginInsert()

void XLogBeginInsert ( void  )

Definition at line 135 of file xloginsert.c.

References Assert, begininsert_called, elog, ERROR, mainrdata_len, max_registered_block_id, and XLogInsertAllowed().

Referenced by _bt_dedup_pass(), _bt_delitems_delete(), _bt_delitems_vacuum(), _bt_getroot(), _bt_insertonpg(), _bt_log_reuse_page(), _bt_mark_page_halfdead(), _bt_newroot(), _bt_set_cleanup_info(), _bt_split(), _bt_unlink_halfdead_page(), _hash_addovflpage(), _hash_doinsert(), _hash_expandtable(), _hash_freeovflpage(), _hash_init(), _hash_splitbucket(), _hash_squeezebucket(), _hash_vacuum_one_page(), addLeafTuple(), AssignTransactionId(), brin_doinsert(), brin_doupdate(), brinbuild(), brinRevmapDesummarizeRange(), CreateCheckPoint(), createdb(), CreateEndOfRecoveryRecord(), CreateOverwriteContrecordRecord(), createPostingTree(), CreateTableSpace(), do_pg_stop_backup(), do_setval(), doPickSplit(), DropTableSpace(), EndPrepare(), ExecuteTruncateGuts(), fill_seq_with_data(), GenericXLogFinish(), ginDeletePage(), ginHeapTupleFastInsert(), ginPlaceToPage(), ginUpdateStats(), ginVacuumPostingTreeLeaf(), gistXLogAssignLSN(), gistXLogDelete(), gistXLogPageDelete(), gistXLogPageReuse(), gistXLogSplit(), gistXLogUpdate(), hashbucketcleanup(), hashbulkdelete(), heap_abort_speculative(), heap_delete(), heap_finish_speculative(), heap_inplace_update(), heap_insert(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_multi_insert(), heap_page_prune(), heap_update(), lazy_vacuum_heap_page(), log_heap_freeze(), log_heap_new_cid(), log_heap_update(), log_heap_visible(), log_newpage(), log_newpage_range(), log_newpages(), log_smgrcreate(), log_split_page(), LogAccessExclusiveLocks(), LogCurrentRunningXacts(), logical_heap_rewrite_flush_mappings(), LogLogicalInvalidations(), LogLogicalMessage(), LogStandbyInvalidations(), movedb(), moveLeafs(), MultiXactIdCreateFromMembers(), nextval_internal(), pg_truncate_visibility_map(), RelationTruncate(), remove_dbtablespaces(), replorigin_advance(), replorigin_drop_guts(), RequestXLogSwitch(), revmap_physical_extend(), shiftList(), spgAddNodeAction(), spgSplitNodeAction(), UpdateFullPageWrites(), vacuumLeafPage(), vacuumLeafRoot(), vacuumRedirectAndPlaceholder(), write_relmap_file(), writeListPage(), WriteMTruncateXlogRec(), WriteMZeroPageXlogRec(), WriteTruncateXlogRec(), WriteZeroPageXlogRec(), XactLogAbortRecord(), XactLogCommitRecord(), XLogPutNextOid(), XLogReportParameters(), XLogRestorePoint(), XLogSaveBufferForHint(), and xlogVacuumPage().

136 {
139  Assert(mainrdata_len == 0);
140 
141  /* cross-check on whether we should be here or not */
142  if (!XLogInsertAllowed())
143  elog(ERROR, "cannot make new WAL entries during recovery");
144 
145  if (begininsert_called)
146  elog(ERROR, "XLogBeginInsert was already called");
147 
148  begininsert_called = true;
149 }
static uint32 mainrdata_len
Definition: xloginsert.c:87
static bool begininsert_called
Definition: xloginsert.c:119
#define ERROR
Definition: elog.h:46
static XLogRecData * mainrdata_head
Definition: xloginsert.c:85
bool XLogInsertAllowed(void)
Definition: xlog.c:8454
static XLogRecData * mainrdata_last
Definition: xloginsert.c:86
#define Assert(condition)
Definition: c.h:804
static int max_registered_block_id
Definition: xloginsert.c:78
#define elog(elevel,...)
Definition: elog.h:232

◆ XLogCheckBufferNeedsBackup()

bool XLogCheckBufferNeedsBackup ( Buffer  buffer)

Definition at line 934 of file xloginsert.c.

References BufferGetPage, doPageWrites, GetFullPageWriteInfo(), PageGetLSN, and RedoRecPtr.

Referenced by log_heap_update().

935 {
937  bool doPageWrites;
938  Page page;
939 
940  GetFullPageWriteInfo(&RedoRecPtr, &doPageWrites);
941 
942  page = BufferGetPage(buffer);
943 
944  if (doPageWrites && PageGetLSN(page) <= RedoRecPtr)
945  return true; /* buffer requires backup */
946 
947  return false; /* buffer does not need to be backed up */
948 }
static bool doPageWrites
Definition: xlog.c:374
static XLogRecPtr RedoRecPtr
Definition: xlog.c:367
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define PageGetLSN(page)
Definition: bufpage.h:366
void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p)
Definition: xlog.c:8667
Pointer Page
Definition: bufpage.h:78

◆ XLogCompressBackupBlock()

static bool XLogCompressBackupBlock ( char *  page,
uint16  hole_offset,
uint16  hole_length,
char *  dest,
uint16 dlen 
)
static

Definition at line 862 of file xloginsert.c.

References Assert, COMPRESS_BUFSIZE, PGAlignedBlock::data, elog, ERROR, pglz_compress(), PGLZ_strategy_default, SizeOfXLogRecordBlockCompressHeader, source, wal_compression, WAL_COMPRESSION_LZ4, WAL_COMPRESSION_NONE, and WAL_COMPRESSION_PGLZ.

Referenced by XLogRecordAssemble().

864 {
865  int32 orig_len = BLCKSZ - hole_length;
866  int32 len = -1;
867  int32 extra_bytes = 0;
868  char *source;
869  PGAlignedBlock tmp;
870 
871  if (hole_length != 0)
872  {
873  /* must skip the hole */
874  source = tmp.data;
875  memcpy(source, page, hole_offset);
876  memcpy(source + hole_offset,
877  page + (hole_offset + hole_length),
878  BLCKSZ - (hole_length + hole_offset));
879 
880  /*
881  * Extra data needs to be stored in WAL record for the compressed
882  * version of block image if the hole exists.
883  */
885  }
886  else
887  source = page;
888 
890  {
892  len = pglz_compress(source, orig_len, dest, PGLZ_strategy_default);
893  break;
894 
895  case WAL_COMPRESSION_LZ4:
896 #ifdef USE_LZ4
897  len = LZ4_compress_default(source, dest, orig_len,
899  if (len <= 0)
900  len = -1; /* failure */
901 #else
902  elog(ERROR, "LZ4 is not supported by this build");
903 #endif
904  break;
905 
907  Assert(false); /* cannot happen */
908  break;
909  /* no default case, so that compiler will warn */
910  }
911 
912  /*
913  * We recheck the actual size even if compression reports success and see
914  * if the number of bytes saved by compression is larger than the length
915  * of extra data needed for the compressed version of block image.
916  */
917  if (len >= 0 &&
918  len + extra_bytes < orig_len)
919  {
920  *dlen = (uint16) len; /* successful compression */
921  return true;
922  }
923  return false;
924 }
#define COMPRESS_BUFSIZE
Definition: xloginsert.c:49
signed int int32
Definition: c.h:429
char data[BLCKSZ]
Definition: c.h:1141
unsigned short uint16
Definition: c.h:440
#define ERROR
Definition: elog.h:46
int32 pglz_compress(const char *source, int32 slen, char *dest, const PGLZ_Strategy *strategy)
int wal_compression
Definition: xlog.c:102
WalCompression
Definition: xlog.h:129
#define Assert(condition)
Definition: c.h:804
static rewind_source * source
Definition: pg_rewind.c:79
#define elog(elevel,...)
Definition: elog.h:232
const PGLZ_Strategy *const PGLZ_strategy_default
#define SizeOfXLogRecordBlockCompressHeader
Definition: xlogrecord.h:164

◆ XLogEnsureRecordSpace()

void XLogEnsureRecordSpace ( int  max_block_id,
int  ndatas 
)

Definition at line 161 of file xloginsert.c.

References Assert, CritSectionCount, elog, ERROR, max_rdatas, max_registered_buffers, MemSet, repalloc(), XLR_MAX_BLOCK_ID, XLR_NORMAL_MAX_BLOCK_ID, and XLR_NORMAL_RDATAS.

Referenced by _hash_freeovflpage(), _hash_squeezebucket(), EndPrepare(), gistplacetopage(), log_newpage_range(), log_newpages(), and shiftList().

162 {
163  int nbuffers;
164 
165  /*
166  * This must be called before entering a critical section, because
167  * allocating memory inside a critical section can fail. repalloc() will
168  * check the same, but better to check it here too so that we fail
169  * consistently even if the arrays happen to be large enough already.
170  */
171  Assert(CritSectionCount == 0);
172 
173  /* the minimum values can't be decreased */
174  if (max_block_id < XLR_NORMAL_MAX_BLOCK_ID)
175  max_block_id = XLR_NORMAL_MAX_BLOCK_ID;
176  if (ndatas < XLR_NORMAL_RDATAS)
177  ndatas = XLR_NORMAL_RDATAS;
178 
179  if (max_block_id > XLR_MAX_BLOCK_ID)
180  elog(ERROR, "maximum number of WAL record block references exceeded");
181  nbuffers = max_block_id + 1;
182 
183  if (nbuffers > max_registered_buffers)
184  {
186  repalloc(registered_buffers, sizeof(registered_buffer) * nbuffers);
187 
188  /*
189  * At least the padding bytes in the structs must be zeroed, because
190  * they are included in WAL data, but initialize it all for tidiness.
191  */
193  (nbuffers - max_registered_buffers) * sizeof(registered_buffer));
194  max_registered_buffers = nbuffers;
195  }
196 
197  if (ndatas > max_rdatas)
198  {
199  rdatas = (XLogRecData *) repalloc(rdatas, sizeof(XLogRecData) * ndatas);
200  max_rdatas = ndatas;
201  }
202 }
#define XLR_NORMAL_RDATAS
Definition: xloginsert.h:28
#define MemSet(start, val, len)
Definition: c.h:1008
#define ERROR
Definition: elog.h:46
static int max_registered_buffers
Definition: xloginsert.c:77
volatile uint32 CritSectionCount
Definition: globals.c:41
static int max_rdatas
Definition: xloginsert.c:117
#define XLR_MAX_BLOCK_ID
Definition: xlogrecord.h:226
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
#define XLR_NORMAL_MAX_BLOCK_ID
Definition: xloginsert.h:27
#define Assert(condition)
Definition: c.h:804
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1182
#define elog(elevel,...)
Definition: elog.h:232
static XLogRecData * rdatas
Definition: xloginsert.c:115

◆ XLogInsert()

XLogRecPtr XLogInsert ( RmgrId  rmid,
uint8  info 
)

Definition at line 434 of file xloginsert.c.

References begininsert_called, curinsert_flags, doPageWrites, elog, ERROR, GetFullPageWriteInfo(), InvalidXLogRecPtr, IsBootstrapProcessingMode, PANIC, RedoRecPtr, SizeOfXLogLongPHD, XLogInsertRecord(), XLogRecordAssemble(), XLogResetInsertion(), XLR_CHECK_CONSISTENCY, XLR_RMGR_INFO_MASK, and XLR_SPECIAL_REL_UPDATE.

Referenced by _bt_dedup_pass(), _bt_delitems_delete(), _bt_delitems_vacuum(), _bt_getroot(), _bt_insertonpg(), _bt_log_reuse_page(), _bt_mark_page_halfdead(), _bt_newroot(), _bt_set_cleanup_info(), _bt_split(), _bt_unlink_halfdead_page(), _hash_addovflpage(), _hash_doinsert(), _hash_expandtable(), _hash_freeovflpage(), _hash_init(), _hash_splitbucket(), _hash_squeezebucket(), _hash_vacuum_one_page(), addLeafTuple(), AssignTransactionId(), brin_doinsert(), brin_doupdate(), brinbuild(), brinRevmapDesummarizeRange(), CreateCheckPoint(), createdb(), CreateEndOfRecoveryRecord(), CreateOverwriteContrecordRecord(), createPostingTree(), CreateTableSpace(), do_pg_stop_backup(), do_setval(), doPickSplit(), DropTableSpace(), EndPrepare(), ExecuteTruncateGuts(), fill_seq_with_data(), GenericXLogFinish(), ginDeletePage(), ginHeapTupleFastInsert(), ginPlaceToPage(), ginUpdateStats(), ginVacuumPostingTreeLeaf(), gistXLogAssignLSN(), gistXLogDelete(), gistXLogPageDelete(), gistXLogPageReuse(), gistXLogSplit(), gistXLogUpdate(), hashbucketcleanup(), hashbulkdelete(), heap_abort_speculative(), heap_delete(), heap_finish_speculative(), heap_inplace_update(), heap_insert(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_multi_insert(), heap_page_prune(), heap_update(), lazy_vacuum_heap_page(), log_heap_freeze(), log_heap_new_cid(), log_heap_update(), log_heap_visible(), log_newpage(), log_newpage_range(), log_newpages(), log_smgrcreate(), log_split_page(), LogAccessExclusiveLocks(), LogCurrentRunningXacts(), logical_heap_rewrite_flush_mappings(), LogLogicalInvalidations(), LogLogicalMessage(), LogStandbyInvalidations(), movedb(), moveLeafs(), MultiXactIdCreateFromMembers(), nextval_internal(), pg_truncate_visibility_map(), RelationTruncate(), remove_dbtablespaces(), replorigin_advance(), replorigin_drop_guts(), RequestXLogSwitch(), revmap_physical_extend(), shiftList(), spgAddNodeAction(), spgSplitNodeAction(), UpdateFullPageWrites(), vacuumLeafPage(), vacuumLeafRoot(), vacuumRedirectAndPlaceholder(), write_relmap_file(), writeListPage(), WriteMTruncateXlogRec(), WriteMZeroPageXlogRec(), WriteTruncateXlogRec(), WriteZeroPageXlogRec(), XactLogAbortRecord(), XactLogCommitRecord(), XLogPutNextOid(), XLogReportParameters(), XLogRestorePoint(), XLogSaveBufferForHint(), and xlogVacuumPage().

435 {
436  XLogRecPtr EndPos;
437 
438  /* XLogBeginInsert() must have been called. */
439  if (!begininsert_called)
440  elog(ERROR, "XLogBeginInsert was not called");
441 
442  /*
443  * The caller can set rmgr bits, XLR_SPECIAL_REL_UPDATE and
444  * XLR_CHECK_CONSISTENCY; the rest are reserved for use by me.
445  */
446  if ((info & ~(XLR_RMGR_INFO_MASK |
448  XLR_CHECK_CONSISTENCY)) != 0)
449  elog(PANIC, "invalid xlog info mask %02X", info);
450 
451  TRACE_POSTGRESQL_WAL_INSERT(rmid, info);
452 
453  /*
454  * In bootstrap mode, we don't actually log anything but XLOG resources;
455  * return a phony record pointer.
456  */
457  if (IsBootstrapProcessingMode() && rmid != RM_XLOG_ID)
458  {
460  EndPos = SizeOfXLogLongPHD; /* start of 1st chkpt record */
461  return EndPos;
462  }
463 
464  do
465  {
467  bool doPageWrites;
468  XLogRecPtr fpw_lsn;
469  XLogRecData *rdt;
470  int num_fpi = 0;
471 
472  /*
473  * Get values needed to decide whether to do full-page writes. Since
474  * we don't yet have an insertion lock, these could change under us,
475  * but XLogInsertRecord will recheck them once it has a lock.
476  */
477  GetFullPageWriteInfo(&RedoRecPtr, &doPageWrites);
478 
479  rdt = XLogRecordAssemble(rmid, info, RedoRecPtr, doPageWrites,
480  &fpw_lsn, &num_fpi);
481 
482  EndPos = XLogInsertRecord(rdt, fpw_lsn, curinsert_flags, num_fpi);
483  } while (EndPos == InvalidXLogRecPtr);
484 
486 
487  return EndPos;
488 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:71
static bool begininsert_called
Definition: xloginsert.c:119
#define PANIC
Definition: elog.h:50
#define XLR_CHECK_CONSISTENCY
Definition: xlogrecord.h:80
static bool doPageWrites
Definition: xlog.c:374
#define ERROR
Definition: elog.h:46
void XLogResetInsertion(void)
Definition: xloginsert.c:208
static XLogRecData * XLogRecordAssemble(RmgrId rmid, uint8 info, XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr *fpw_lsn, int *num_fpi)
Definition: xloginsert.c:503
static XLogRecPtr RedoRecPtr
Definition: xlog.c:367
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p)
Definition: xlog.c:8667
#define elog(elevel,...)
Definition: elog.h:232
XLogRecPtr XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn, uint8 flags, int num_fpi)
Definition: xlog.c:1014
static uint8 curinsert_flags
Definition: xloginsert.c:90
#define SizeOfXLogLongPHD
Definition: xlog_internal.h:69
#define XLR_RMGR_INFO_MASK
Definition: xlogrecord.h:63

◆ XLogRecordAssemble()

static XLogRecData * XLogRecordAssemble ( RmgrId  rmid,
uint8  info,
XLogRecPtr  RedoRecPtr,
bool  doPageWrites,
XLogRecPtr fpw_lsn,
int *  num_fpi 
)
static

Definition at line 503 of file xloginsert.c.

References Assert, XLogRecordBlockImageHeader::bimg_info, registered_buffer::bkp_rdatas, BKPBLOCK_HAS_DATA, BKPBLOCK_HAS_IMAGE, BKPBLOCK_SAME_REL, BKPBLOCK_WILL_INIT, BKPIMAGE_APPLY, BKPIMAGE_COMPRESS_LZ4, BKPIMAGE_COMPRESS_PGLZ, BKPIMAGE_HAS_HOLE, registered_buffer::block, COMP_CRC32C, registered_buffer::compressed_page, curinsert_flags, XLogRecData::data, XLogRecordBlockHeader::data_length, elog, ERROR, registered_buffer::flags, XLogRecordBlockHeader::fork_flags, registered_buffer::forkno, GetCurrentTransactionIdIfAny(), GetTopTransactionIdIfAny(), hdr_rdt, hdr_scratch, XLogRecordBlockCompressHeader::hole_length, XLogRecordBlockImageHeader::hole_offset, XLogRecordBlockHeader::id, registered_buffer::in_use, INIT_CRC32C, InvalidRepOriginId, InvalidXLogRecPtr, IsSubTransactionAssignmentPending(), XLogRecData::len, XLogRecordBlockImageHeader::length, lower(), mainrdata_head, mainrdata_last, mainrdata_len, max_registered_block_id, XLogRecData::next, registered_buffer::page, PageGetLSN, registered_buffer::rdata_head, registered_buffer::rdata_len, registered_buffer::rdata_tail, RedoRecPtr, REGBUF_FORCE_IMAGE, REGBUF_KEEP_DATA, REGBUF_NO_IMAGE, REGBUF_STANDARD, REGBUF_WILL_INIT, RelFileNodeEquals, replorigin_session_origin, registered_buffer::rnode, SizeOfPageHeaderData, SizeOfXLogRecord, SizeOfXLogRecordBlockCompressHeader, SizeOfXLogRecordBlockHeader, SizeOfXLogRecordBlockImageHeader, upper(), wal_compression, WAL_COMPRESSION_LZ4, WAL_COMPRESSION_NONE, WAL_COMPRESSION_PGLZ, wal_consistency_checking, XLogRecord::xl_crc, XLogRecord::xl_info, XLogRecord::xl_prev, XLogRecord::xl_rmid, XLogRecord::xl_tot_len, XLogRecord::xl_xid, XLOG_INCLUDE_ORIGIN, XLOG_INCLUDE_XID, XLogCompressBackupBlock(), XLogSetRecordFlags(), XLR_BLOCK_ID_DATA_LONG, XLR_BLOCK_ID_DATA_SHORT, XLR_BLOCK_ID_ORIGIN, XLR_BLOCK_ID_TOPLEVEL_XID, and XLR_CHECK_CONSISTENCY.

Referenced by XLogInsert().

506 {
507  XLogRecData *rdt;
508  uint32 total_len = 0;
509  int block_id;
510  pg_crc32c rdata_crc;
511  registered_buffer *prev_regbuf = NULL;
512  XLogRecData *rdt_datas_last;
513  XLogRecord *rechdr;
514  char *scratch = hdr_scratch;
515 
516  /*
517  * Note: this function can be called multiple times for the same record.
518  * All the modifications we do to the rdata chains below must handle that.
519  */
520 
521  /* The record begins with the fixed-size header */
522  rechdr = (XLogRecord *) scratch;
523  scratch += SizeOfXLogRecord;
524 
525  hdr_rdt.next = NULL;
526  rdt_datas_last = &hdr_rdt;
528 
529  /*
530  * Enforce consistency checks for this record if user is looking for it.
531  * Do this before at the beginning of this routine to give the possibility
532  * for callers of XLogInsert() to pass XLR_CHECK_CONSISTENCY directly for
533  * a record.
534  */
535  if (wal_consistency_checking[rmid])
536  info |= XLR_CHECK_CONSISTENCY;
537 
538  /*
539  * Make an rdata chain containing all the data portions of all block
540  * references. This includes the data for full-page images. Also append
541  * the headers for the block references in the scratch buffer.
542  */
543  *fpw_lsn = InvalidXLogRecPtr;
544  for (block_id = 0; block_id < max_registered_block_id; block_id++)
545  {
546  registered_buffer *regbuf = &registered_buffers[block_id];
547  bool needs_backup;
548  bool needs_data;
551  XLogRecordBlockCompressHeader cbimg = {0};
552  bool samerel;
553  bool is_compressed = false;
554  bool include_image;
555 
556  if (!regbuf->in_use)
557  continue;
558 
559  /* Determine if this block needs to be backed up */
560  if (regbuf->flags & REGBUF_FORCE_IMAGE)
561  needs_backup = true;
562  else if (regbuf->flags & REGBUF_NO_IMAGE)
563  needs_backup = false;
564  else if (!doPageWrites)
565  needs_backup = false;
566  else
567  {
568  /*
569  * We assume page LSN is first data on *every* page that can be
570  * passed to XLogInsert, whether it has the standard page layout
571  * or not.
572  */
573  XLogRecPtr page_lsn = PageGetLSN(regbuf->page);
574 
575  needs_backup = (page_lsn <= RedoRecPtr);
576  if (!needs_backup)
577  {
578  if (*fpw_lsn == InvalidXLogRecPtr || page_lsn < *fpw_lsn)
579  *fpw_lsn = page_lsn;
580  }
581  }
582 
583  /* Determine if the buffer data needs to included */
584  if (regbuf->rdata_len == 0)
585  needs_data = false;
586  else if ((regbuf->flags & REGBUF_KEEP_DATA) != 0)
587  needs_data = true;
588  else
589  needs_data = !needs_backup;
590 
591  bkpb.id = block_id;
592  bkpb.fork_flags = regbuf->forkno;
593  bkpb.data_length = 0;
594 
595  if ((regbuf->flags & REGBUF_WILL_INIT) == REGBUF_WILL_INIT)
597 
598  /*
599  * If needs_backup is true or WAL checking is enabled for current
600  * resource manager, log a full-page write for the current block.
601  */
602  include_image = needs_backup || (info & XLR_CHECK_CONSISTENCY) != 0;
603 
604  if (include_image)
605  {
606  Page page = regbuf->page;
607  uint16 compressed_len = 0;
608 
609  /*
610  * The page needs to be backed up, so calculate its hole length
611  * and offset.
612  */
613  if (regbuf->flags & REGBUF_STANDARD)
614  {
615  /* Assume we can omit data between pd_lower and pd_upper */
616  uint16 lower = ((PageHeader) page)->pd_lower;
617  uint16 upper = ((PageHeader) page)->pd_upper;
618 
619  if (lower >= SizeOfPageHeaderData &&
620  upper > lower &&
621  upper <= BLCKSZ)
622  {
623  bimg.hole_offset = lower;
624  cbimg.hole_length = upper - lower;
625  }
626  else
627  {
628  /* No "hole" to remove */
629  bimg.hole_offset = 0;
630  cbimg.hole_length = 0;
631  }
632  }
633  else
634  {
635  /* Not a standard page header, don't try to eliminate "hole" */
636  bimg.hole_offset = 0;
637  cbimg.hole_length = 0;
638  }
639 
640  /*
641  * Try to compress a block image if wal_compression is enabled
642  */
644  {
645  is_compressed =
647  cbimg.hole_length,
648  regbuf->compressed_page,
649  &compressed_len);
650  }
651 
652  /*
653  * Fill in the remaining fields in the XLogRecordBlockHeader
654  * struct
655  */
657 
658  /* Report a full page image constructed for the WAL record */
659  *num_fpi += 1;
660 
661  /*
662  * Construct XLogRecData entries for the page content.
663  */
664  rdt_datas_last->next = &regbuf->bkp_rdatas[0];
665  rdt_datas_last = rdt_datas_last->next;
666 
667  bimg.bimg_info = (cbimg.hole_length == 0) ? 0 : BKPIMAGE_HAS_HOLE;
668 
669  /*
670  * If WAL consistency checking is enabled for the resource manager
671  * of this WAL record, a full-page image is included in the record
672  * for the block modified. During redo, the full-page is replayed
673  * only if BKPIMAGE_APPLY is set.
674  */
675  if (needs_backup)
676  bimg.bimg_info |= BKPIMAGE_APPLY;
677 
678  if (is_compressed)
679  {
680  /* The current compression is stored in the WAL record */
681  bimg.length = compressed_len;
682 
683  /* Set the compression method used for this block */
685  {
688  break;
689 
690  case WAL_COMPRESSION_LZ4:
691 #ifdef USE_LZ4
693 #else
694  elog(ERROR, "LZ4 is not supported by this build");
695 #endif
696  break;
697 
699  Assert(false); /* cannot happen */
700  break;
701  /* no default case, so that compiler will warn */
702  }
703 
704  rdt_datas_last->data = regbuf->compressed_page;
705  rdt_datas_last->len = compressed_len;
706  }
707  else
708  {
709  bimg.length = BLCKSZ - cbimg.hole_length;
710 
711  if (cbimg.hole_length == 0)
712  {
713  rdt_datas_last->data = page;
714  rdt_datas_last->len = BLCKSZ;
715  }
716  else
717  {
718  /* must skip the hole */
719  rdt_datas_last->data = page;
720  rdt_datas_last->len = bimg.hole_offset;
721 
722  rdt_datas_last->next = &regbuf->bkp_rdatas[1];
723  rdt_datas_last = rdt_datas_last->next;
724 
725  rdt_datas_last->data =
726  page + (bimg.hole_offset + cbimg.hole_length);
727  rdt_datas_last->len =
728  BLCKSZ - (bimg.hole_offset + cbimg.hole_length);
729  }
730  }
731 
732  total_len += bimg.length;
733  }
734 
735  if (needs_data)
736  {
737  /*
738  * Link the caller-supplied rdata chain for this buffer to the
739  * overall list.
740  */
742  bkpb.data_length = regbuf->rdata_len;
743  total_len += regbuf->rdata_len;
744 
745  rdt_datas_last->next = regbuf->rdata_head;
746  rdt_datas_last = regbuf->rdata_tail;
747  }
748 
749  if (prev_regbuf && RelFileNodeEquals(regbuf->rnode, prev_regbuf->rnode))
750  {
751  samerel = true;
753  }
754  else
755  samerel = false;
756  prev_regbuf = regbuf;
757 
758  /* Ok, copy the header to the scratch buffer */
759  memcpy(scratch, &bkpb, SizeOfXLogRecordBlockHeader);
760  scratch += SizeOfXLogRecordBlockHeader;
761  if (include_image)
762  {
763  memcpy(scratch, &bimg, SizeOfXLogRecordBlockImageHeader);
765  if (cbimg.hole_length != 0 && is_compressed)
766  {
767  memcpy(scratch, &cbimg,
770  }
771  }
772  if (!samerel)
773  {
774  memcpy(scratch, &regbuf->rnode, sizeof(RelFileNode));
775  scratch += sizeof(RelFileNode);
776  }
777  memcpy(scratch, &regbuf->block, sizeof(BlockNumber));
778  scratch += sizeof(BlockNumber);
779  }
780 
781  /* followed by the record's origin, if any */
784  {
785  *(scratch++) = (char) XLR_BLOCK_ID_ORIGIN;
786  memcpy(scratch, &replorigin_session_origin, sizeof(replorigin_session_origin));
787  scratch += sizeof(replorigin_session_origin);
788  }
789 
790  /* followed by toplevel XID, if not already included in previous record */
792  {
794 
795  /* update the flag (later used by XLogResetInsertion) */
797 
798  *(scratch++) = (char) XLR_BLOCK_ID_TOPLEVEL_XID;
799  memcpy(scratch, &xid, sizeof(TransactionId));
800  scratch += sizeof(TransactionId);
801  }
802 
803  /* followed by main data, if any */
804  if (mainrdata_len > 0)
805  {
806  if (mainrdata_len > 255)
807  {
808  *(scratch++) = (char) XLR_BLOCK_ID_DATA_LONG;
809  memcpy(scratch, &mainrdata_len, sizeof(uint32));
810  scratch += sizeof(uint32);
811  }
812  else
813  {
814  *(scratch++) = (char) XLR_BLOCK_ID_DATA_SHORT;
815  *(scratch++) = (uint8) mainrdata_len;
816  }
817  rdt_datas_last->next = mainrdata_head;
818  rdt_datas_last = mainrdata_last;
819  total_len += mainrdata_len;
820  }
821  rdt_datas_last->next = NULL;
822 
823  hdr_rdt.len = (scratch - hdr_scratch);
824  total_len += hdr_rdt.len;
825 
826  /*
827  * Calculate CRC of the data
828  *
829  * Note that the record header isn't added into the CRC initially since we
830  * don't know the prev-link yet. Thus, the CRC will represent the CRC of
831  * the whole record in the order: rdata, then backup blocks, then record
832  * header.
833  */
834  INIT_CRC32C(rdata_crc);
836  for (rdt = hdr_rdt.next; rdt != NULL; rdt = rdt->next)
837  COMP_CRC32C(rdata_crc, rdt->data, rdt->len);
838 
839  /*
840  * Fill in the fields in the record header. Prev-link is filled in later,
841  * once we know where in the WAL the record will be inserted. The CRC does
842  * not include the record header yet.
843  */
845  rechdr->xl_tot_len = total_len;
846  rechdr->xl_info = info;
847  rechdr->xl_rmid = rmid;
848  rechdr->xl_prev = InvalidXLogRecPtr;
849  rechdr->xl_crc = rdata_crc;
850 
851  return &hdr_rdt;
852 }
static XLogRecData hdr_rdt
Definition: xloginsert.c:100
#define INIT_CRC32C(crc)
Definition: pg_crc32c.h:41
XLogRecPtr xl_prev
Definition: xlogrecord.h:45
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
#define BKPIMAGE_HAS_HOLE
Definition: xlogrecord.h:146
static uint32 mainrdata_len
Definition: xloginsert.c:87
uint32 TransactionId
Definition: c.h:587
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:46
#define XLR_BLOCK_ID_DATA_LONG
Definition: xlogrecord.h:229
uint32 pg_crc32c
Definition: pg_crc32c.h:38
BlockNumber block
Definition: xloginsert.c:61
unsigned char uint8
Definition: c.h:439
#define REGBUF_WILL_INIT
Definition: xloginsert.h:33
RmgrId xl_rmid
Definition: xlogrecord.h:47
#define XLOG_INCLUDE_ORIGIN
Definition: xlog.h:213
uint32 BlockNumber
Definition: block.h:31
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:77
XLogRecData * rdata_head
Definition: xloginsert.c:64
#define SizeOfPageHeaderData
Definition: bufpage.h:216
#define XLR_CHECK_CONSISTENCY
Definition: xlogrecord.h:80
RelFileNode rnode
Definition: xloginsert.c:59
unsigned short uint16
Definition: c.h:440
static bool doPageWrites
Definition: xlog.c:374
#define ERROR
Definition: elog.h:46
#define XLR_BLOCK_ID_TOPLEVEL_XID
Definition: xlogrecord.h:231
uint32 xl_tot_len
Definition: xlogrecord.h:43
#define SizeOfXLogRecordBlockImageHeader
Definition: xlogrecord.h:142
static XLogRecPtr RedoRecPtr
Definition: xlog.c:367
#define BKPIMAGE_APPLY
Definition: xlogrecord.h:147
struct RelFileNode RelFileNode
static XLogRecData * mainrdata_head
Definition: xloginsert.c:85
#define REGBUF_STANDARD
Definition: xloginsert.h:35
TransactionId GetCurrentTransactionIdIfAny(void)
Definition: xact.c:456
unsigned int uint32
Definition: c.h:441
TransactionId GetTopTransactionIdIfAny(void)
Definition: xact.c:426
void XLogSetRecordFlags(uint8 flags)
Definition: xloginsert.c:416
#define BKPBLOCK_WILL_INIT
Definition: xlogrecord.h:186
XLogRecData * rdata_tail
Definition: xloginsert.c:66
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
#define SizeOfXLogRecord
Definition: xlogrecord.h:55
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31
int wal_compression
Definition: xlog.c:102
#define BKPBLOCK_SAME_REL
Definition: xlogrecord.h:187
#define REGBUF_KEEP_DATA
Definition: xloginsert.h:38
#define BKPBLOCK_HAS_IMAGE
Definition: xlogrecord.h:184
bool IsSubTransactionAssignmentPending(void)
Definition: xact.c:6122
#define XLOG_INCLUDE_XID
Definition: xlog.h:215
WalCompression
Definition: xlog.h:129
static XLogRecData * mainrdata_last
Definition: xloginsert.c:86
PageHeaderData * PageHeader
Definition: bufpage.h:166
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
RepOriginId replorigin_session_origin
Definition: origin.c:154
bool * wal_consistency_checking
Definition: xlog.c:104
uint8 xl_info
Definition: xlogrecord.h:46
#define REGBUF_NO_IMAGE
Definition: xloginsert.h:32
#define XLR_BLOCK_ID_ORIGIN
Definition: xlogrecord.h:230
ForkNumber forkno
Definition: xloginsert.c:60
char compressed_page[COMPRESS_BUFSIZE]
Definition: xloginsert.c:73
pg_crc32c xl_crc
Definition: xlogrecord.h:49
struct XLogRecData * next
#define InvalidRepOriginId
Definition: origin.h:33
#define PageGetLSN(page)
Definition: bufpage.h:366
#define XLR_BLOCK_ID_DATA_SHORT
Definition: xlogrecord.h:228
static char * hdr_scratch
Definition: xloginsert.c:101
TransactionId xl_xid
Definition: xlogrecord.h:44
#define BKPIMAGE_COMPRESS_LZ4
Definition: xlogrecord.h:151
static int max_registered_block_id
Definition: xloginsert.c:78
#define BKPIMAGE_COMPRESS_PGLZ
Definition: xlogrecord.h:150
#define elog(elevel,...)
Definition: elog.h:232
static bool XLogCompressBackupBlock(char *page, uint16 hole_offset, uint16 hole_length, char *dest, uint16 *dlen)
Definition: xloginsert.c:862
static uint8 curinsert_flags
Definition: xloginsert.c:90
XLogRecData bkp_rdatas[2]
Definition: xloginsert.c:69
#define COMP_CRC32C(crc, data, len)
Definition: pg_crc32c.h:89
#define SizeOfXLogRecordBlockCompressHeader
Definition: xlogrecord.h:164
Pointer Page
Definition: bufpage.h:78
#define RelFileNodeEquals(node1, node2)
Definition: relfilenode.h:88
#define BKPBLOCK_HAS_DATA
Definition: xlogrecord.h:185
#define SizeOfXLogRecordBlockHeader
Definition: xlogrecord.h:104

◆ XLogRegisterBlock()

void XLogRegisterBlock ( uint8  block_id,
RelFileNode rnode,
ForkNumber  forknum,
BlockNumber  blknum,
Page  page,
uint8  flags 
)

Definition at line 285 of file xloginsert.c.

References Assert, begininsert_called, registered_buffer::block, elog, ERROR, registered_buffer::flags, registered_buffer::forkno, i, registered_buffer::in_use, max_registered_block_id, max_registered_buffers, registered_buffer::page, registered_buffer::rdata_head, registered_buffer::rdata_len, registered_buffer::rdata_tail, RelFileNodeEquals, and registered_buffer::rnode.

Referenced by log_newpage(), log_newpages(), and XLogSaveBufferForHint().

287 {
288  registered_buffer *regbuf;
289 
291 
292  if (block_id >= max_registered_block_id)
293  max_registered_block_id = block_id + 1;
294 
295  if (block_id >= max_registered_buffers)
296  elog(ERROR, "too many registered buffers");
297 
298  regbuf = &registered_buffers[block_id];
299 
300  regbuf->rnode = *rnode;
301  regbuf->forkno = forknum;
302  regbuf->block = blknum;
303  regbuf->page = page;
304  regbuf->flags = flags;
305  regbuf->rdata_tail = (XLogRecData *) &regbuf->rdata_head;
306  regbuf->rdata_len = 0;
307 
308  /*
309  * Check that this page hasn't already been registered with some other
310  * block_id.
311  */
312 #ifdef USE_ASSERT_CHECKING
313  {
314  int i;
315 
316  for (i = 0; i < max_registered_block_id; i++)
317  {
318  registered_buffer *regbuf_old = &registered_buffers[i];
319 
320  if (i == block_id || !regbuf_old->in_use)
321  continue;
322 
323  Assert(!RelFileNodeEquals(regbuf_old->rnode, regbuf->rnode) ||
324  regbuf_old->forkno != regbuf->forkno ||
325  regbuf_old->block != regbuf->block);
326  }
327  }
328 #endif
329 
330  regbuf->in_use = true;
331 }
BlockNumber block
Definition: xloginsert.c:61
static bool begininsert_called
Definition: xloginsert.c:119
XLogRecData * rdata_head
Definition: xloginsert.c:64
RelFileNode rnode
Definition: xloginsert.c:59
#define ERROR
Definition: elog.h:46
static int max_registered_buffers
Definition: xloginsert.c:77
XLogRecData * rdata_tail
Definition: xloginsert.c:66
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
#define Assert(condition)
Definition: c.h:804
ForkNumber forkno
Definition: xloginsert.c:60
static int max_registered_block_id
Definition: xloginsert.c:78
#define elog(elevel,...)
Definition: elog.h:232
int i
#define RelFileNodeEquals(node1, node2)
Definition: relfilenode.h:88

◆ XLogRegisterBufData()

void XLogRegisterBufData ( uint8  block_id,
char *  data,
int  len 
)

Definition at line 378 of file xloginsert.c.

References Assert, begininsert_called, XLogRecData::data, elog, ERROR, registered_buffer::in_use, XLogRecData::len, max_rdatas, XLogRecData::next, num_rdatas, registered_buffer::rdata_len, and registered_buffer::rdata_tail.

Referenced by _bt_dedup_pass(), _bt_delitems_delete(), _bt_delitems_vacuum(), _bt_getroot(), _bt_insertonpg(), _bt_newroot(), _bt_set_cleanup_info(), _bt_split(), _bt_unlink_halfdead_page(), _hash_addovflpage(), _hash_doinsert(), _hash_expandtable(), _hash_freeovflpage(), _hash_squeezebucket(), brin_doinsert(), brin_doupdate(), dataExecPlaceToPageInternal(), dataExecPlaceToPageLeaf(), entryExecPlaceToPage(), GenericXLogFinish(), ginHeapTupleFastInsert(), ginVacuumPostingTreeLeaf(), gistXLogSplit(), gistXLogUpdate(), hashbucketcleanup(), heap_inplace_update(), heap_insert(), heap_multi_insert(), heap_page_prune(), lazy_vacuum_heap_page(), log_heap_freeze(), log_heap_update(), and writeListPage().

379 {
380  registered_buffer *regbuf;
381  XLogRecData *rdata;
382 
384 
385  /* find the registered buffer struct */
386  regbuf = &registered_buffers[block_id];
387  if (!regbuf->in_use)
388  elog(ERROR, "no block with id %d registered with WAL insertion",
389  block_id);
390 
391  if (num_rdatas >= max_rdatas)
392  elog(ERROR, "too much WAL data");
393  rdata = &rdatas[num_rdatas++];
394 
395  rdata->data = data;
396  rdata->len = len;
397 
398  regbuf->rdata_tail->next = rdata;
399  regbuf->rdata_tail = rdata;
400  regbuf->rdata_len += len;
401 }
static bool begininsert_called
Definition: xloginsert.c:119
#define ERROR
Definition: elog.h:46
XLogRecData * rdata_tail
Definition: xloginsert.c:66
static int max_rdatas
Definition: xloginsert.c:117
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
static int num_rdatas
Definition: xloginsert.c:116
#define Assert(condition)
Definition: c.h:804
struct XLogRecData * next
#define elog(elevel,...)
Definition: elog.h:232
static XLogRecData * rdatas
Definition: xloginsert.c:115

◆ XLogRegisterBuffer()

void XLogRegisterBuffer ( uint8  block_id,
Buffer  buffer,
uint8  flags 
)

Definition at line 232 of file xloginsert.c.

References Assert, begininsert_called, registered_buffer::block, BufferGetPage, BufferGetTag(), elog, ERROR, registered_buffer::flags, registered_buffer::forkno, i, registered_buffer::in_use, max_registered_block_id, max_registered_buffers, registered_buffer::page, registered_buffer::rdata_head, registered_buffer::rdata_len, registered_buffer::rdata_tail, REGBUF_FORCE_IMAGE, REGBUF_NO_IMAGE, RelFileNodeEquals, and registered_buffer::rnode.

Referenced by _bt_dedup_pass(), _bt_delitems_delete(), _bt_delitems_vacuum(), _bt_getroot(), _bt_insertonpg(), _bt_mark_page_halfdead(), _bt_newroot(), _bt_set_cleanup_info(), _bt_split(), _bt_unlink_halfdead_page(), _hash_addovflpage(), _hash_doinsert(), _hash_expandtable(), _hash_freeovflpage(), _hash_init(), _hash_splitbucket(), _hash_squeezebucket(), _hash_vacuum_one_page(), addLeafTuple(), brin_doinsert(), brin_doupdate(), brinbuild(), brinRevmapDesummarizeRange(), createPostingTree(), do_setval(), doPickSplit(), fill_seq_with_data(), GenericXLogFinish(), ginDeletePage(), ginHeapTupleFastInsert(), ginPlaceToPage(), ginUpdateStats(), ginVacuumPostingTreeLeaf(), gistXLogDelete(), gistXLogPageDelete(), gistXLogSplit(), gistXLogUpdate(), hashbucketcleanup(), hashbulkdelete(), heap_abort_speculative(), heap_delete(), heap_finish_speculative(), heap_inplace_update(), heap_insert(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_multi_insert(), heap_page_prune(), heap_update(), lazy_vacuum_heap_page(), log_heap_freeze(), log_heap_update(), log_heap_visible(), log_newpage_range(), log_split_page(), moveLeafs(), nextval_internal(), revmap_physical_extend(), shiftList(), spgAddNodeAction(), spgSplitNodeAction(), vacuumLeafPage(), vacuumLeafRoot(), vacuumRedirectAndPlaceholder(), writeListPage(), and xlogVacuumPage().

233 {
234  registered_buffer *regbuf;
235 
236  /* NO_IMAGE doesn't make sense with FORCE_IMAGE */
237  Assert(!((flags & REGBUF_FORCE_IMAGE) && (flags & (REGBUF_NO_IMAGE))));
239 
240  if (block_id >= max_registered_block_id)
241  {
242  if (block_id >= max_registered_buffers)
243  elog(ERROR, "too many registered buffers");
244  max_registered_block_id = block_id + 1;
245  }
246 
247  regbuf = &registered_buffers[block_id];
248 
249  BufferGetTag(buffer, &regbuf->rnode, &regbuf->forkno, &regbuf->block);
250  regbuf->page = BufferGetPage(buffer);
251  regbuf->flags = flags;
252  regbuf->rdata_tail = (XLogRecData *) &regbuf->rdata_head;
253  regbuf->rdata_len = 0;
254 
255  /*
256  * Check that this page hasn't already been registered with some other
257  * block_id.
258  */
259 #ifdef USE_ASSERT_CHECKING
260  {
261  int i;
262 
263  for (i = 0; i < max_registered_block_id; i++)
264  {
265  registered_buffer *regbuf_old = &registered_buffers[i];
266 
267  if (i == block_id || !regbuf_old->in_use)
268  continue;
269 
270  Assert(!RelFileNodeEquals(regbuf_old->rnode, regbuf->rnode) ||
271  regbuf_old->forkno != regbuf->forkno ||
272  regbuf_old->block != regbuf->block);
273  }
274  }
275 #endif
276 
277  regbuf->in_use = true;
278 }
BlockNumber block
Definition: xloginsert.c:61
static bool begininsert_called
Definition: xloginsert.c:119
XLogRecData * rdata_head
Definition: xloginsert.c:64
RelFileNode rnode
Definition: xloginsert.c:59
#define ERROR
Definition: elog.h:46
static int max_registered_buffers
Definition: xloginsert.c:77
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
XLogRecData * rdata_tail
Definition: xloginsert.c:66
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31
#define Assert(condition)
Definition: c.h:804
#define REGBUF_NO_IMAGE
Definition: xloginsert.h:32
ForkNumber forkno
Definition: xloginsert.c:60
static int max_registered_block_id
Definition: xloginsert.c:78
#define elog(elevel,...)
Definition: elog.h:232
int i
void BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum)
Definition: bufmgr.c:2769
#define RelFileNodeEquals(node1, node2)
Definition: relfilenode.h:88

◆ XLogRegisterData()

void XLogRegisterData ( char *  data,
int  len 
)

Definition at line 340 of file xloginsert.c.

References Assert, begininsert_called, XLogRecData::data, elog, ERROR, XLogRecData::len, mainrdata_len, max_rdatas, XLogRecData::next, and num_rdatas.

Referenced by _bt_dedup_pass(), _bt_delitems_delete(), _bt_delitems_vacuum(), _bt_getroot(), _bt_insertonpg(), _bt_log_reuse_page(), _bt_mark_page_halfdead(), _bt_newroot(), _bt_split(), _bt_unlink_halfdead_page(), _hash_addovflpage(), _hash_doinsert(), _hash_expandtable(), _hash_freeovflpage(), _hash_init(), _hash_splitbucket(), _hash_squeezebucket(), _hash_vacuum_one_page(), addLeafTuple(), AssignTransactionId(), brin_doinsert(), brin_doupdate(), brinbuild(), brinRevmapDesummarizeRange(), CreateCheckPoint(), createdb(), CreateEndOfRecoveryRecord(), CreateOverwriteContrecordRecord(), createPostingTree(), CreateTableSpace(), do_pg_stop_backup(), do_setval(), doPickSplit(), DropTableSpace(), EndPrepare(), ExecuteTruncateGuts(), fill_seq_with_data(), ginDeletePage(), ginHeapTupleFastInsert(), ginPlaceToPage(), ginUpdateStats(), gistXLogAssignLSN(), gistXLogDelete(), gistXLogPageDelete(), gistXLogPageReuse(), gistXLogSplit(), gistXLogUpdate(), hashbucketcleanup(), hashbulkdelete(), heap_abort_speculative(), heap_delete(), heap_finish_speculative(), heap_inplace_update(), heap_insert(), heap_lock_tuple(), heap_lock_updated_tuple_rec(), heap_multi_insert(), heap_page_prune(), heap_update(), lazy_vacuum_heap_page(), log_heap_freeze(), log_heap_new_cid(), log_heap_update(), log_heap_visible(), log_smgrcreate(), LogAccessExclusiveLocks(), LogCurrentRunningXacts(), logical_heap_rewrite_flush_mappings(), LogLogicalInvalidations(), LogLogicalMessage(), LogStandbyInvalidations(), movedb(), moveLeafs(), MultiXactIdCreateFromMembers(), nextval_internal(), pg_truncate_visibility_map(), RelationTruncate(), remove_dbtablespaces(), replorigin_advance(), replorigin_drop_guts(), revmap_physical_extend(), shiftList(), spgAddNodeAction(), spgSplitNodeAction(), UpdateFullPageWrites(), vacuumLeafPage(), vacuumLeafRoot(), vacuumRedirectAndPlaceholder(), write_relmap_file(), writeListPage(), WriteMTruncateXlogRec(), WriteMZeroPageXlogRec(), WriteTruncateXlogRec(), WriteZeroPageXlogRec(), XactLogAbortRecord(), XactLogCommitRecord(), XLogPutNextOid(), XLogReportParameters(), and XLogRestorePoint().

341 {
342  XLogRecData *rdata;
343 
345 
346  if (num_rdatas >= max_rdatas)
347  elog(ERROR, "too much WAL data");
348  rdata = &rdatas[num_rdatas++];
349 
350  rdata->data = data;
351  rdata->len = len;
352 
353  /*
354  * we use the mainrdata_last pointer to track the end of the chain, so no
355  * need to clear 'next' here.
356  */
357 
358  mainrdata_last->next = rdata;
359  mainrdata_last = rdata;
360 
361  mainrdata_len += len;
362 }
static uint32 mainrdata_len
Definition: xloginsert.c:87
static bool begininsert_called
Definition: xloginsert.c:119
#define ERROR
Definition: elog.h:46
static int max_rdatas
Definition: xloginsert.c:117
static XLogRecData * mainrdata_last
Definition: xloginsert.c:86
static int num_rdatas
Definition: xloginsert.c:116
#define Assert(condition)
Definition: c.h:804
struct XLogRecData * next
#define elog(elevel,...)
Definition: elog.h:232
static XLogRecData * rdatas
Definition: xloginsert.c:115

◆ XLogResetInsertion()

void XLogResetInsertion ( void  )

Definition at line 208 of file xloginsert.c.

References begininsert_called, curinsert_flags, i, mainrdata_len, MarkSubTransactionAssigned(), max_registered_block_id, num_rdatas, and XLOG_INCLUDE_XID.

Referenced by AbortSubTransaction(), AbortTransaction(), and XLogInsert().

209 {
210  int i;
211 
212  /* reset the subxact assignment flag (if needed) */
215 
216  for (i = 0; i < max_registered_block_id; i++)
217  registered_buffers[i].in_use = false;
218 
219  num_rdatas = 0;
220  max_registered_block_id = 0;
221  mainrdata_len = 0;
223  curinsert_flags = 0;
224  begininsert_called = false;
225 }
void MarkSubTransactionAssigned(void)
Definition: xact.c:6150
static uint32 mainrdata_len
Definition: xloginsert.c:87
static bool begininsert_called
Definition: xloginsert.c:119
static XLogRecData * mainrdata_head
Definition: xloginsert.c:85
static registered_buffer * registered_buffers
Definition: xloginsert.c:76
#define XLOG_INCLUDE_XID
Definition: xlog.h:215
static XLogRecData * mainrdata_last
Definition: xloginsert.c:86
static int num_rdatas
Definition: xloginsert.c:116
static int max_registered_block_id
Definition: xloginsert.c:78
int i
static uint8 curinsert_flags
Definition: xloginsert.c:90

◆ XLogSaveBufferForHint()

XLogRecPtr XLogSaveBufferForHint ( Buffer  buffer,
bool  buffer_std 
)

Definition at line 972 of file xloginsert.c.

References Assert, BufferGetBlock, BufferGetLSNAtomic(), BufferGetPage, BufferGetTag(), PGAlignedBlock::data, PGPROC::delayChkpt, GetRedoRecPtr(), InvalidXLogRecPtr, lower(), MyProc, RedoRecPtr, REGBUF_STANDARD, upper(), XLOG_FPI_FOR_HINT, XLogBeginInsert(), XLogInsert(), and XLogRegisterBlock().

Referenced by MarkBufferDirtyHint().

973 {
974  XLogRecPtr recptr = InvalidXLogRecPtr;
975  XLogRecPtr lsn;
977 
978  /*
979  * Ensure no checkpoint can change our view of RedoRecPtr.
980  */
982 
983  /*
984  * Update RedoRecPtr so that we can make the right decision
985  */
986  RedoRecPtr = GetRedoRecPtr();
987 
988  /*
989  * We assume page LSN is first data on *every* page that can be passed to
990  * XLogInsert, whether it has the standard page layout or not. Since we're
991  * only holding a share-lock on the page, we must take the buffer header
992  * lock when we look at the LSN.
993  */
994  lsn = BufferGetLSNAtomic(buffer);
995 
996  if (lsn <= RedoRecPtr)
997  {
998  int flags = 0;
999  PGAlignedBlock copied_buffer;
1000  char *origdata = (char *) BufferGetBlock(buffer);
1001  RelFileNode rnode;
1002  ForkNumber forkno;
1003  BlockNumber blkno;
1004 
1005  /*
1006  * Copy buffer so we don't have to worry about concurrent hint bit or
1007  * lsn updates. We assume pd_lower/upper cannot be changed without an
1008  * exclusive lock, so the contents bkp are not racy.
1009  */
1010  if (buffer_std)
1011  {
1012  /* Assume we can omit data between pd_lower and pd_upper */
1013  Page page = BufferGetPage(buffer);
1014  uint16 lower = ((PageHeader) page)->pd_lower;
1015  uint16 upper = ((PageHeader) page)->pd_upper;
1016 
1017  memcpy(copied_buffer.data, origdata, lower);
1018  memcpy(copied_buffer.data + upper, origdata + upper, BLCKSZ - upper);
1019  }
1020  else
1021  memcpy(copied_buffer.data, origdata, BLCKSZ);
1022 
1023  XLogBeginInsert();
1024 
1025  if (buffer_std)
1026  flags |= REGBUF_STANDARD;
1027 
1028  BufferGetTag(buffer, &rnode, &forkno, &blkno);
1029  XLogRegisterBlock(0, &rnode, forkno, blkno, copied_buffer.data, flags);
1030 
1031  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI_FOR_HINT);
1032  }
1033 
1034  return recptr;
1035 }
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:46
PGPROC * MyProc
Definition: proc.c:68
uint32 BlockNumber
Definition: block.h:31
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:77
char data[BLCKSZ]
Definition: c.h:1141
void XLogRegisterBlock(uint8 block_id, RelFileNode *rnode, ForkNumber forknum, BlockNumber blknum, Page page, uint8 flags)
Definition: xloginsert.c:285
unsigned short uint16
Definition: c.h:440
bool delayChkpt
Definition: proc.h:187
static XLogRecPtr RedoRecPtr
Definition: xlog.c:367
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition: bufmgr.c:3008
#define REGBUF_STANDARD
Definition: xloginsert.h:35
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
ForkNumber
Definition: relpath.h:40
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:434
PageHeaderData * PageHeader
Definition: bufpage.h:166
uint64 XLogRecPtr
Definition: xlogdefs.h:21
#define Assert(condition)
Definition: c.h:804
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:77
XLogRecPtr GetRedoRecPtr(void)
Definition: xlog.c:8638
void BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum)
Definition: bufmgr.c:2769
void XLogBeginInsert(void)
Definition: xloginsert.c:135
#define BufferGetBlock(buffer)
Definition: bufmgr.h:136
Pointer Page
Definition: bufpage.h:78

◆ XLogSetRecordFlags()

Variable Documentation

◆ begininsert_called

◆ curinsert_flags

uint8 curinsert_flags = 0
static

◆ hdr_rdt

XLogRecData hdr_rdt
static

Definition at line 100 of file xloginsert.c.

Referenced by XLogRecordAssemble().

◆ hdr_scratch

char* hdr_scratch = NULL
static

Definition at line 101 of file xloginsert.c.

Referenced by InitXLogInsert(), and XLogRecordAssemble().

◆ mainrdata_head

XLogRecData* mainrdata_head
static

Definition at line 85 of file xloginsert.c.

Referenced by XLogRecordAssemble().

◆ mainrdata_last

XLogRecData* mainrdata_last = (XLogRecData *) &mainrdata_head
static

Definition at line 86 of file xloginsert.c.

Referenced by XLogRecordAssemble().

◆ mainrdata_len

uint32 mainrdata_len
static

◆ max_rdatas

int max_rdatas
static

◆ max_registered_block_id

int max_registered_block_id = 0
static

◆ max_registered_buffers

int max_registered_buffers
static

◆ num_rdatas

int num_rdatas
static

Definition at line 116 of file xloginsert.c.

Referenced by XLogRegisterBufData(), XLogRegisterData(), and XLogResetInsertion().

◆ rdatas

XLogRecData* rdatas
static

Definition at line 115 of file xloginsert.c.

◆ registered_buffers

registered_buffer* registered_buffers
static

Definition at line 76 of file xloginsert.c.

◆ xloginsert_cxt

MemoryContext xloginsert_cxt
static

Definition at line 122 of file xloginsert.c.