PostgreSQL Source Code  git master
xloginsert.h File Reference
#include "access/rmgr.h"
#include "access/xlogdefs.h"
#include "storage/block.h"
#include "storage/buf.h"
#include "storage/relfilenode.h"
#include "utils/relcache.h"
Include dependency graph for xloginsert.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define XLR_NORMAL_MAX_BLOCK_ID   4
 
#define XLR_NORMAL_RDATAS   20
 
#define REGBUF_FORCE_IMAGE   0x01 /* force a full-page image */
 
#define REGBUF_NO_IMAGE   0x02 /* don't take a full-page image */
 
#define REGBUF_WILL_INIT
 
#define REGBUF_STANDARD
 
#define REGBUF_KEEP_DATA
 

Functions

void XLogBeginInsert (void)
 
void XLogSetRecordFlags (uint8 flags)
 
XLogRecPtr XLogInsert (RmgrId rmid, uint8 info)
 
void XLogEnsureRecordSpace (int max_block_id, int ndatas)
 
void XLogRegisterData (char *data, int len)
 
void XLogRegisterBuffer (uint8 block_id, Buffer buffer, uint8 flags)
 
void XLogRegisterBlock (uint8 block_id, RelFileNode *rnode, ForkNumber forknum, BlockNumber blknum, char *page, uint8 flags)
 
void XLogRegisterBufData (uint8 block_id, char *data, int len)
 
void XLogResetInsertion (void)
 
bool XLogCheckBufferNeedsBackup (Buffer buffer)
 
XLogRecPtr log_newpage (RelFileNode *rnode, ForkNumber forkNum, BlockNumber blk, char *page, bool page_std)
 
void log_newpages (RelFileNode *rnode, ForkNumber forkNum, int num_pages, BlockNumber *blknos, char **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)
 
XLogRecPtr XLogSaveBufferForHint (Buffer buffer, bool buffer_std)
 
void InitXLogInsert (void)
 

Macro Definition Documentation

◆ REGBUF_FORCE_IMAGE

#define REGBUF_FORCE_IMAGE   0x01 /* force a full-page image */

Definition at line 31 of file xloginsert.h.

◆ REGBUF_KEEP_DATA

#define REGBUF_KEEP_DATA
Value:
0x10 /* include data even if a full-page image
* is taken */

Definition at line 35 of file xloginsert.h.

◆ REGBUF_NO_IMAGE

#define REGBUF_NO_IMAGE   0x02 /* don't take a full-page image */

Definition at line 32 of file xloginsert.h.

◆ REGBUF_STANDARD

#define REGBUF_STANDARD
Value:
0x08 /* page follows "standard" page layout,
* (data between pd_lower and pd_upper
* will be skipped) */

Definition at line 34 of file xloginsert.h.

◆ REGBUF_WILL_INIT

#define REGBUF_WILL_INIT
Value:
(0x04 | 0x02) /* page will be re-initialized at
* replay (implies NO_IMAGE) */

Definition at line 33 of file xloginsert.h.

◆ XLR_NORMAL_MAX_BLOCK_ID

#define XLR_NORMAL_MAX_BLOCK_ID   4

Definition at line 27 of file xloginsert.h.

◆ XLR_NORMAL_RDATAS

#define XLR_NORMAL_RDATAS   20

Definition at line 28 of file xloginsert.h.

Function Documentation

◆ InitXLogInsert()

void InitXLogInsert ( void  )

Definition at line 1284 of file xloginsert.c.

1285 {
1286  /* Initialize the working areas */
1287  if (xloginsert_cxt == NULL)
1288  {
1290  "WAL record construction",
1292  }
1293 
1294  if (registered_buffers == NULL)
1295  {
1298  sizeof(registered_buffer) * (XLR_NORMAL_MAX_BLOCK_ID + 1));
1300  }
1301  if (rdatas == NULL)
1302  {
1304  sizeof(XLogRecData) * XLR_NORMAL_RDATAS);
1306  }
1307 
1308  /*
1309  * Allocate a buffer to hold the header information for a WAL record.
1310  */
1311  if (hdr_scratch == NULL)
1314 }
MemoryContext TopMemoryContext
Definition: mcxt.c:48
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:906
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:863
#define AllocSetContextCreate
Definition: memutils.h:173
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:197
static int max_registered_buffers
Definition: xloginsert.c:91
static MemoryContext xloginsert_cxt
Definition: xloginsert.c:136
static char * hdr_scratch
Definition: xloginsert.c:115
static XLogRecData * rdatas
Definition: xloginsert.c:129
static registered_buffer * registered_buffers
Definition: xloginsert.c:90
static int max_rdatas
Definition: xloginsert.c:131
#define HEADER_SCRATCH_SIZE
Definition: xloginsert.c:120
#define XLR_NORMAL_MAX_BLOCK_ID
Definition: xloginsert.h:27
#define XLR_NORMAL_RDATAS
Definition: xloginsert.h:28

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

Referenced by BaseInit().

◆ log_newpage()

XLogRecPtr log_newpage ( RelFileNode rnode,
ForkNumber  forkNum,
BlockNumber  blk,
char *  page,
bool  page_std 
)

Definition at line 1083 of file xloginsert.c.

1085 {
1086  int flags;
1087  XLogRecPtr recptr;
1088 
1089  flags = REGBUF_FORCE_IMAGE;
1090  if (page_std)
1091  flags |= REGBUF_STANDARD;
1092 
1093  XLogBeginInsert();
1094  XLogRegisterBlock(0, rnode, forkNum, blkno, page, flags);
1095  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1096 
1097  /*
1098  * The page may be uninitialized. If so, we can't set the LSN because that
1099  * would corrupt the page.
1100  */
1101  if (!PageIsNew(page))
1102  {
1103  PageSetLSN(page, recptr);
1104  }
1105 
1106  return recptr;
1107 }
#define PageSetLSN(page, lsn)
Definition: bufpage.h:367
#define PageIsNew(page)
Definition: bufpage.h:228
#define XLOG_FPI
Definition: pg_control.h:78
uint64 XLogRecPtr
Definition: xlogdefs.h:21
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:443
void XLogBeginInsert(void)
Definition: xloginsert.c:150
void XLogRegisterBlock(uint8 block_id, RelFileNode *rnode, ForkNumber forknum, BlockNumber blknum, Page page, uint8 flags)
Definition: xloginsert.c:296
#define REGBUF_STANDARD
Definition: xloginsert.h:34
#define REGBUF_FORCE_IMAGE
Definition: xloginsert.h:31

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().

◆ log_newpage_buffer()

XLogRecPtr log_newpage_buffer ( Buffer  buffer,
bool  page_std 
)

Definition at line 1177 of file xloginsert.c.

1178 {
1179  Page page = BufferGetPage(buffer);
1180  RelFileNode rnode;
1181  ForkNumber forkNum;
1182  BlockNumber blkno;
1183 
1184  /* Shared buffers should be modified in a critical section. */
1185  Assert(CritSectionCount > 0);
1186 
1187  BufferGetTag(buffer, &rnode, &forkNum, &blkno);
1188 
1189  return log_newpage(&rnode, forkNum, blkno, page, page_std);
1190 }
uint32 BlockNumber
Definition: block.h:31
void BufferGetTag(Buffer buffer, RelFileNode *rnode, ForkNumber *forknum, BlockNumber *blknum)
Definition: bufmgr.c:2776
#define BufferGetPage(buffer)
Definition: bufmgr.h:169
Pointer Page
Definition: bufpage.h:78
volatile uint32 CritSectionCount
Definition: globals.c:42
Assert(fmt[strlen(fmt) - 1] !='\n')
ForkNumber
Definition: relpath.h:41
XLogRecPtr log_newpage(RelFileNode *rnode, ForkNumber forkNum, BlockNumber blkno, Page page, bool page_std)
Definition: xloginsert.c:1083

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

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

◆ log_newpage_range()

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

Definition at line 1210 of file xloginsert.c.

1213 {
1214  int flags;
1215  BlockNumber blkno;
1216 
1217  flags = REGBUF_FORCE_IMAGE;
1218  if (page_std)
1219  flags |= REGBUF_STANDARD;
1220 
1221  /*
1222  * Iterate over all the pages in the range. They are collected into
1223  * batches of XLR_MAX_BLOCK_ID pages, and a single WAL-record is written
1224  * for each batch.
1225  */
1227 
1228  blkno = startblk;
1229  while (blkno < endblk)
1230  {
1231  Buffer bufpack[XLR_MAX_BLOCK_ID];
1232  XLogRecPtr recptr;
1233  int nbufs;
1234  int i;
1235 
1237 
1238  /* Collect a batch of blocks. */
1239  nbufs = 0;
1240  while (nbufs < XLR_MAX_BLOCK_ID && blkno < endblk)
1241  {
1242  Buffer buf = ReadBufferExtended(rel, forkNum, blkno,
1243  RBM_NORMAL, NULL);
1244 
1246 
1247  /*
1248  * Completely empty pages are not WAL-logged. Writing a WAL record
1249  * would change the LSN, and we don't want that. We want the page
1250  * to stay empty.
1251  */
1252  if (!PageIsNew(BufferGetPage(buf)))
1253  bufpack[nbufs++] = buf;
1254  else
1256  blkno++;
1257  }
1258 
1259  /* Write WAL record for this batch. */
1260  XLogBeginInsert();
1261 
1263  for (i = 0; i < nbufs; i++)
1264  {
1265  XLogRegisterBuffer(i, bufpack[i], flags);
1266  MarkBufferDirty(bufpack[i]);
1267  }
1268 
1269  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1270 
1271  for (i = 0; i < nbufs; i++)
1272  {
1273  PageSetLSN(BufferGetPage(bufpack[i]), recptr);
1274  UnlockReleaseBuffer(bufpack[i]);
1275  }
1276  END_CRIT_SECTION();
1277  }
1278 }
int Buffer
Definition: buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3938
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1573
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4156
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:749
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:98
@ RBM_NORMAL
Definition: bufmgr.h:39
int i
Definition: isn.c:73
#define START_CRIT_SECTION()
Definition: miscadmin.h:148
#define CHECK_FOR_INTERRUPTS()
Definition: miscadmin.h:121
#define END_CRIT_SECTION()
Definition: miscadmin.h:150
static char * buf
Definition: pg_test_fsync.c:67
void XLogRegisterBuffer(uint8 block_id, Buffer buffer, uint8 flags)
Definition: xloginsert.c:243
void XLogEnsureRecordSpace(int max_block_id, int ndatas)
Definition: xloginsert.c:176
#define XLR_MAX_BLOCK_ID
Definition: xlogrecord.h:228

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().

◆ log_newpages()

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

Definition at line 1115 of file xloginsert.c.

1117 {
1118  int flags;
1119  XLogRecPtr recptr;
1120  int i;
1121  int j;
1122 
1123  flags = REGBUF_FORCE_IMAGE;
1124  if (page_std)
1125  flags |= REGBUF_STANDARD;
1126 
1127  /*
1128  * Iterate over all the pages. They are collected into batches of
1129  * XLR_MAX_BLOCK_ID pages, and a single WAL-record is written for each
1130  * batch.
1131  */
1133 
1134  i = 0;
1135  while (i < num_pages)
1136  {
1137  int batch_start = i;
1138  int nbatch;
1139 
1140  XLogBeginInsert();
1141 
1142  nbatch = 0;
1143  while (nbatch < XLR_MAX_BLOCK_ID && i < num_pages)
1144  {
1145  XLogRegisterBlock(nbatch, rnode, forkNum, blknos[i], pages[i], flags);
1146  i++;
1147  nbatch++;
1148  }
1149 
1150  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1151 
1152  for (j = batch_start; j < i; j++)
1153  {
1154  /*
1155  * The page may be uninitialized. If so, we can't set the LSN
1156  * because that would corrupt the page.
1157  */
1158  if (!PageIsNew(pages[j]))
1159  {
1160  PageSetLSN(pages[j], recptr);
1161  }
1162  }
1163  }
1164 }
int j
Definition: isn.c:74

References i, j, 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().

◆ XLogBeginInsert()

void XLogBeginInsert ( void  )

Definition at line 150 of file xloginsert.c.

151 {
154  Assert(mainrdata_len == 0);
155 
156  /* cross-check on whether we should be here or not */
157  if (!XLogInsertAllowed())
158  elog(ERROR, "cannot make new WAL entries during recovery");
159 
160  if (begininsert_called)
161  elog(ERROR, "XLogBeginInsert was already called");
162 
163  begininsert_called = true;
164 }
#define ERROR
Definition: elog.h:33
#define elog(elevel,...)
Definition: elog.h:218
bool XLogInsertAllowed(void)
Definition: xlog.c:5808
static XLogRecData * mainrdata_head
Definition: xloginsert.c:99
static bool begininsert_called
Definition: xloginsert.c:133
static int max_registered_block_id
Definition: xloginsert.c:92
static uint32 mainrdata_len
Definition: xloginsert.c:101
static XLogRecData * mainrdata_last
Definition: xloginsert.c:100

References Assert(), begininsert_called, elog, ERROR, mainrdata_head, mainrdata_last, 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(), CreateDatabaseUsingFileCopy(), CreateDirAndVersionFile(), CreateEndOfRecoveryRecord(), CreateOverwriteContrecordRecord(), createPostingTree(), CreateTableSpace(), do_pg_backup_stop(), do_setval(), doPickSplit(), DropTableSpace(), EndPrepare(), ExecuteTruncateGuts(), fill_seq_fork_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().

◆ XLogCheckBufferNeedsBackup()

bool XLogCheckBufferNeedsBackup ( Buffer  buffer)

Definition at line 967 of file xloginsert.c.

968 {
970  bool doPageWrites;
971  Page page;
972 
974 
975  page = BufferGetPage(buffer);
976 
977  if (doPageWrites && PageGetLSN(page) <= RedoRecPtr)
978  return true; /* buffer requires backup */
979 
980  return false; /* buffer does not need to be backed up */
981 }
#define PageGetLSN(page)
Definition: bufpage.h:365
void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p)
Definition: xlog.c:5886
static XLogRecPtr RedoRecPtr
Definition: xlog.c:270
static bool doPageWrites
Definition: xlog.c:283

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

Referenced by log_heap_update().

◆ XLogEnsureRecordSpace()

void XLogEnsureRecordSpace ( int  max_block_id,
int  ndatas 
)

Definition at line 176 of file xloginsert.c.

177 {
178  int nbuffers;
179 
180  /*
181  * This must be called before entering a critical section, because
182  * allocating memory inside a critical section can fail. repalloc() will
183  * check the same, but better to check it here too so that we fail
184  * consistently even if the arrays happen to be large enough already.
185  */
186  Assert(CritSectionCount == 0);
187 
188  /* the minimum values can't be decreased */
189  if (max_block_id < XLR_NORMAL_MAX_BLOCK_ID)
190  max_block_id = XLR_NORMAL_MAX_BLOCK_ID;
191  if (ndatas < XLR_NORMAL_RDATAS)
192  ndatas = XLR_NORMAL_RDATAS;
193 
194  if (max_block_id > XLR_MAX_BLOCK_ID)
195  elog(ERROR, "maximum number of WAL record block references exceeded");
196  nbuffers = max_block_id + 1;
197 
198  if (nbuffers > max_registered_buffers)
199  {
201  repalloc(registered_buffers, sizeof(registered_buffer) * nbuffers);
202 
203  /*
204  * At least the padding bytes in the structs must be zeroed, because
205  * they are included in WAL data, but initialize it all for tidiness.
206  */
208  (nbuffers - max_registered_buffers) * sizeof(registered_buffer));
209  max_registered_buffers = nbuffers;
210  }
211 
212  if (ndatas > max_rdatas)
213  {
214  rdatas = (XLogRecData *) repalloc(rdatas, sizeof(XLogRecData) * ndatas);
215  max_rdatas = ndatas;
216  }
217 }
#define MemSet(start, val, len)
Definition: c.h:1008
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1188

References Assert(), CritSectionCount, elog, ERROR, max_rdatas, max_registered_buffers, MemSet, rdatas, registered_buffers, 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().

◆ XLogInsert()

XLogRecPtr XLogInsert ( RmgrId  rmid,
uint8  info 
)

Definition at line 443 of file xloginsert.c.

444 {
445  XLogRecPtr EndPos;
446 
447  /* XLogBeginInsert() must have been called. */
448  if (!begininsert_called)
449  elog(ERROR, "XLogBeginInsert was not called");
450 
451  /*
452  * The caller can set rmgr bits, XLR_SPECIAL_REL_UPDATE and
453  * XLR_CHECK_CONSISTENCY; the rest are reserved for use by me.
454  */
455  if ((info & ~(XLR_RMGR_INFO_MASK |
457  XLR_CHECK_CONSISTENCY)) != 0)
458  elog(PANIC, "invalid xlog info mask %02X", info);
459 
460  TRACE_POSTGRESQL_WAL_INSERT(rmid, info);
461 
462  /*
463  * In bootstrap mode, we don't actually log anything but XLOG resources;
464  * return a phony record pointer.
465  */
466  if (IsBootstrapProcessingMode() && rmid != RM_XLOG_ID)
467  {
469  EndPos = SizeOfXLogLongPHD; /* start of 1st chkpt record */
470  return EndPos;
471  }
472 
473  do
474  {
476  bool doPageWrites;
477  bool topxid_included = false;
478  XLogRecPtr fpw_lsn;
479  XLogRecData *rdt;
480  int num_fpi = 0;
481 
482  /*
483  * Get values needed to decide whether to do full-page writes. Since
484  * we don't yet have an insertion lock, these could change under us,
485  * but XLogInsertRecord will recheck them once it has a lock.
486  */
488 
489  rdt = XLogRecordAssemble(rmid, info, RedoRecPtr, doPageWrites,
490  &fpw_lsn, &num_fpi, &topxid_included);
491 
492  EndPos = XLogInsertRecord(rdt, fpw_lsn, curinsert_flags, num_fpi,
493  topxid_included);
494  } while (EndPos == InvalidXLogRecPtr);
495 
497 
498  return EndPos;
499 }
#define PANIC
Definition: elog.h:36
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:406
XLogRecPtr XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn, uint8 flags, int num_fpi, bool topxid_included)
Definition: xlog.c:728
#define SizeOfXLogLongPHD
Definition: xlog_internal.h:69
#define InvalidXLogRecPtr
Definition: xlogdefs.h:28
static uint8 curinsert_flags
Definition: xloginsert.c:104
void XLogResetInsertion(void)
Definition: xloginsert.c:223
static XLogRecData * XLogRecordAssemble(RmgrId rmid, uint8 info, XLogRecPtr RedoRecPtr, bool doPageWrites, XLogRecPtr *fpw_lsn, int *num_fpi, bool *topxid_included)
Definition: xloginsert.c:517
#define XLR_RMGR_INFO_MASK
Definition: xlogrecord.h:63
#define XLR_SPECIAL_REL_UPDATE
Definition: xlogrecord.h:71
#define XLR_CHECK_CONSISTENCY
Definition: xlogrecord.h:80

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(), CreateDatabaseUsingFileCopy(), CreateDirAndVersionFile(), CreateEndOfRecoveryRecord(), CreateOverwriteContrecordRecord(), createPostingTree(), CreateTableSpace(), do_pg_backup_stop(), do_setval(), doPickSplit(), DropTableSpace(), EndPrepare(), ExecuteTruncateGuts(), fill_seq_fork_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().

◆ XLogRegisterBlock()

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

Definition at line 296 of file xloginsert.c.

298 {
299  registered_buffer *regbuf;
300 
302 
303  if (block_id >= max_registered_block_id)
304  max_registered_block_id = block_id + 1;
305 
306  if (block_id >= max_registered_buffers)
307  elog(ERROR, "too many registered buffers");
308 
309  regbuf = &registered_buffers[block_id];
310 
311  regbuf->rnode = *rnode;
312  regbuf->forkno = forknum;
313  regbuf->block = blknum;
314  regbuf->page = page;
315  regbuf->flags = flags;
316  regbuf->rdata_tail = (XLogRecData *) &regbuf->rdata_head;
317  regbuf->rdata_len = 0;
318 
319  /*
320  * Check that this page hasn't already been registered with some other
321  * block_id.
322  */
323 #ifdef USE_ASSERT_CHECKING
324  {
325  int i;
326 
327  for (i = 0; i < max_registered_block_id; i++)
328  {
329  registered_buffer *regbuf_old = &registered_buffers[i];
330 
331  if (i == block_id || !regbuf_old->in_use)
332  continue;
333 
334  Assert(!RelFileNodeEquals(regbuf_old->rnode, regbuf->rnode) ||
335  regbuf_old->forkno != regbuf->forkno ||
336  regbuf_old->block != regbuf->block);
337  }
338  }
339 #endif
340 
341  regbuf->in_use = true;
342 }
#define RelFileNodeEquals(node1, node2)
Definition: relfilenode.h:88
RelFileNode rnode
Definition: xloginsert.c:73
XLogRecData * rdata_tail
Definition: xloginsert.c:80
BlockNumber block
Definition: xloginsert.c:75
XLogRecData * rdata_head
Definition: xloginsert.c:78
ForkNumber forkno
Definition: xloginsert.c:74

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, registered_buffers, RelFileNodeEquals, and registered_buffer::rnode.

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

◆ XLogRegisterBufData()

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

Definition at line 389 of file xloginsert.c.

390 {
391  registered_buffer *regbuf;
392  XLogRecData *rdata;
393 
395 
396  /* find the registered buffer struct */
397  regbuf = &registered_buffers[block_id];
398  if (!regbuf->in_use)
399  elog(ERROR, "no block with id %d registered with WAL insertion",
400  block_id);
401 
402  if (num_rdatas >= max_rdatas)
403  elog(ERROR, "too much WAL data");
404  rdata = &rdatas[num_rdatas++];
405 
406  rdata->data = data;
407  rdata->len = len;
408 
409  regbuf->rdata_tail->next = rdata;
410  regbuf->rdata_tail = rdata;
411  regbuf->rdata_len += len;
412 }
const void size_t len
const void * data
struct XLogRecData * next
static int num_rdatas
Definition: xloginsert.c:130

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

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().

◆ XLogRegisterBuffer()

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

Definition at line 243 of file xloginsert.c.

244 {
245  registered_buffer *regbuf;
246 
247  /* NO_IMAGE doesn't make sense with FORCE_IMAGE */
248  Assert(!((flags & REGBUF_FORCE_IMAGE) && (flags & (REGBUF_NO_IMAGE))));
250 
251  if (block_id >= max_registered_block_id)
252  {
253  if (block_id >= max_registered_buffers)
254  elog(ERROR, "too many registered buffers");
255  max_registered_block_id = block_id + 1;
256  }
257 
258  regbuf = &registered_buffers[block_id];
259 
260  BufferGetTag(buffer, &regbuf->rnode, &regbuf->forkno, &regbuf->block);
261  regbuf->page = BufferGetPage(buffer);
262  regbuf->flags = flags;
263  regbuf->rdata_tail = (XLogRecData *) &regbuf->rdata_head;
264  regbuf->rdata_len = 0;
265 
266  /*
267  * Check that this page hasn't already been registered with some other
268  * block_id.
269  */
270 #ifdef USE_ASSERT_CHECKING
271  {
272  int i;
273 
274  for (i = 0; i < max_registered_block_id; i++)
275  {
276  registered_buffer *regbuf_old = &registered_buffers[i];
277 
278  if (i == block_id || !regbuf_old->in_use)
279  continue;
280 
281  Assert(!RelFileNodeEquals(regbuf_old->rnode, regbuf->rnode) ||
282  regbuf_old->forkno != regbuf->forkno ||
283  regbuf_old->block != regbuf->block);
284  }
285  }
286 #endif
287 
288  regbuf->in_use = true;
289 }
#define REGBUF_NO_IMAGE
Definition: xloginsert.h:32

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, registered_buffers, 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_fork_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().

◆ XLogRegisterData()

void XLogRegisterData ( char *  data,
int  len 
)

Definition at line 351 of file xloginsert.c.

352 {
353  XLogRecData *rdata;
354 
356 
357  if (num_rdatas >= max_rdatas)
358  elog(ERROR, "too much WAL data");
359  rdata = &rdatas[num_rdatas++];
360 
361  rdata->data = data;
362  rdata->len = len;
363 
364  /*
365  * we use the mainrdata_last pointer to track the end of the chain, so no
366  * need to clear 'next' here.
367  */
368 
369  mainrdata_last->next = rdata;
370  mainrdata_last = rdata;
371 
372  mainrdata_len += len;
373 }

References Assert(), begininsert_called, XLogRecData::data, data, elog, ERROR, XLogRecData::len, len, mainrdata_last, mainrdata_len, max_rdatas, XLogRecData::next, num_rdatas, and 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(), CreateDatabaseUsingFileCopy(), CreateDirAndVersionFile(), CreateEndOfRecoveryRecord(), CreateOverwriteContrecordRecord(), createPostingTree(), CreateTableSpace(), do_pg_backup_stop(), do_setval(), doPickSplit(), DropTableSpace(), EndPrepare(), ExecuteTruncateGuts(), fill_seq_fork_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().

◆ XLogResetInsertion()

void XLogResetInsertion ( void  )

Definition at line 223 of file xloginsert.c.

224 {
225  int i;
226 
227  for (i = 0; i < max_registered_block_id; i++)
228  registered_buffers[i].in_use = false;
229 
230  num_rdatas = 0;
232  mainrdata_len = 0;
234  curinsert_flags = 0;
235  begininsert_called = false;
236 }

References begininsert_called, curinsert_flags, i, mainrdata_head, mainrdata_last, mainrdata_len, max_registered_block_id, num_rdatas, and registered_buffers.

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

◆ XLogSaveBufferForHint()

XLogRecPtr XLogSaveBufferForHint ( Buffer  buffer,
bool  buffer_std 
)

Definition at line 1005 of file xloginsert.c.

1006 {
1007  XLogRecPtr recptr = InvalidXLogRecPtr;
1008  XLogRecPtr lsn;
1010 
1011  /*
1012  * Ensure no checkpoint can change our view of RedoRecPtr.
1013  */
1015 
1016  /*
1017  * Update RedoRecPtr so that we can make the right decision
1018  */
1020 
1021  /*
1022  * We assume page LSN is first data on *every* page that can be passed to
1023  * XLogInsert, whether it has the standard page layout or not. Since we're
1024  * only holding a share-lock on the page, we must take the buffer header
1025  * lock when we look at the LSN.
1026  */
1027  lsn = BufferGetLSNAtomic(buffer);
1028 
1029  if (lsn <= RedoRecPtr)
1030  {
1031  int flags = 0;
1032  PGAlignedBlock copied_buffer;
1033  char *origdata = (char *) BufferGetBlock(buffer);
1034  RelFileNode rnode;
1035  ForkNumber forkno;
1036  BlockNumber blkno;
1037 
1038  /*
1039  * Copy buffer so we don't have to worry about concurrent hint bit or
1040  * lsn updates. We assume pd_lower/upper cannot be changed without an
1041  * exclusive lock, so the contents bkp are not racy.
1042  */
1043  if (buffer_std)
1044  {
1045  /* Assume we can omit data between pd_lower and pd_upper */
1046  Page page = BufferGetPage(buffer);
1047  uint16 lower = ((PageHeader) page)->pd_lower;
1048  uint16 upper = ((PageHeader) page)->pd_upper;
1049 
1050  memcpy(copied_buffer.data, origdata, lower);
1051  memcpy(copied_buffer.data + upper, origdata + upper, BLCKSZ - upper);
1052  }
1053  else
1054  memcpy(copied_buffer.data, origdata, BLCKSZ);
1055 
1056  XLogBeginInsert();
1057 
1058  if (buffer_std)
1059  flags |= REGBUF_STANDARD;
1060 
1061  BufferGetTag(buffer, &rnode, &forkno, &blkno);
1062  XLogRegisterBlock(0, &rnode, forkno, blkno, copied_buffer.data, flags);
1063 
1064  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI_FOR_HINT);
1065  }
1066 
1067  return recptr;
1068 }
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition: bufmgr.c:3004
#define BufferGetBlock(buffer)
Definition: bufmgr.h:136
PageHeaderData * PageHeader
Definition: bufpage.h:166
unsigned short uint16
Definition: c.h:440
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:46
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:77
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:77
#define DELAY_CHKPT_START
Definition: proc.h:117
PGPROC * MyProc
Definition: proc.c:68
int delayChkptFlags
Definition: proc.h:225
char data[BLCKSZ]
Definition: c.h:1138
XLogRecPtr GetRedoRecPtr(void)
Definition: xlog.c:5856

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

Referenced by MarkBufferDirtyHint().

◆ XLogSetRecordFlags()