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/relfilelocator.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, uint32 len)
 
void XLogRegisterBuffer (uint8 block_id, Buffer buffer, uint8 flags)
 
void XLogRegisterBlock (uint8 block_id, RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blknum, char *page, uint8 flags)
 
void XLogRegisterBufData (uint8 block_id, char *data, uint32 len)
 
void XLogResetInsertion (void)
 
bool XLogCheckBufferNeedsBackup (Buffer buffer)
 
XLogRecPtr log_newpage (RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blkno, char *page, bool page_std)
 
void log_newpages (RelFileLocator *rlocator, 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 1298 of file xloginsert.c.

1299 {
1300  /* Initialize the working areas */
1301  if (xloginsert_cxt == NULL)
1302  {
1304  "WAL record construction",
1306  }
1307 
1308  if (registered_buffers == NULL)
1309  {
1312  sizeof(registered_buffer) * (XLR_NORMAL_MAX_BLOCK_ID + 1));
1314  }
1315  if (rdatas == NULL)
1316  {
1318  sizeof(XLogRecData) * XLR_NORMAL_RDATAS);
1320  }
1321 
1322  /*
1323  * Allocate a buffer to hold the header information for a WAL record.
1324  */
1325  if (hdr_scratch == NULL)
1328 }
MemoryContext TopMemoryContext
Definition: mcxt.c:130
void * MemoryContextAllocZero(MemoryContext context, Size size)
Definition: mcxt.c:1037
void * MemoryContextAlloc(MemoryContext context, Size size)
Definition: mcxt.c:994
#define AllocSetContextCreate
Definition: memutils.h:129
#define ALLOCSET_DEFAULT_SIZES
Definition: memutils.h:153
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 ( RelFileLocator rlocator,
ForkNumber  forknum,
BlockNumber  blkno,
char *  page,
bool  page_std 
)

Definition at line 1097 of file xloginsert.c.

1099 {
1100  int flags;
1101  XLogRecPtr recptr;
1102 
1103  flags = REGBUF_FORCE_IMAGE;
1104  if (page_std)
1105  flags |= REGBUF_STANDARD;
1106 
1107  XLogBeginInsert();
1108  XLogRegisterBlock(0, rlocator, forknum, blkno, page, flags);
1109  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1110 
1111  /*
1112  * The page may be uninitialized. If so, we can't set the LSN because that
1113  * would corrupt the page.
1114  */
1115  if (!PageIsNew(page))
1116  {
1117  PageSetLSN(page, recptr);
1118  }
1119 
1120  return recptr;
1121 }
static bool PageIsNew(Page page)
Definition: bufpage.h:230
static void PageSetLSN(Page page, XLogRecPtr lsn)
Definition: bufpage.h:388
#define XLOG_FPI
Definition: pg_control.h:78
uint64 XLogRecPtr
Definition: xlogdefs.h:21
void XLogRegisterBlock(uint8 block_id, RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blknum, Page page, uint8 flags)
Definition: xloginsert.c:296
XLogRecPtr XLogInsert(RmgrId rmid, uint8 info)
Definition: xloginsert.c:451
void XLogBeginInsert(void)
Definition: xloginsert.c:150
#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 1191 of file xloginsert.c.

1192 {
1193  Page page = BufferGetPage(buffer);
1194  RelFileLocator rlocator;
1195  ForkNumber forknum;
1196  BlockNumber blkno;
1197 
1198  /* Shared buffers should be modified in a critical section. */
1199  Assert(CritSectionCount > 0);
1200 
1201  BufferGetTag(buffer, &rlocator, &forknum, &blkno);
1202 
1203  return log_newpage(&rlocator, forknum, blkno, page, page_std);
1204 }
uint32 BlockNumber
Definition: block.h:31
void BufferGetTag(Buffer buffer, RelFileLocator *rlocator, ForkNumber *forknum, BlockNumber *blknum)
Definition: bufmgr.c:2784
static Page BufferGetPage(Buffer buffer)
Definition: bufmgr.h:280
Pointer Page
Definition: bufpage.h:78
volatile uint32 CritSectionCount
Definition: globals.c:42
Assert(fmt[strlen(fmt) - 1] !='\n')
ForkNumber
Definition: relpath.h:48
XLogRecPtr log_newpage(RelFileLocator *rlocator, ForkNumber forknum, BlockNumber blkno, Page page, bool page_std)
Definition: xloginsert.c:1097

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 1224 of file xloginsert.c.

1227 {
1228  int flags;
1229  BlockNumber blkno;
1230 
1231  flags = REGBUF_FORCE_IMAGE;
1232  if (page_std)
1233  flags |= REGBUF_STANDARD;
1234 
1235  /*
1236  * Iterate over all the pages in the range. They are collected into
1237  * batches of XLR_MAX_BLOCK_ID pages, and a single WAL-record is written
1238  * for each batch.
1239  */
1241 
1242  blkno = startblk;
1243  while (blkno < endblk)
1244  {
1245  Buffer bufpack[XLR_MAX_BLOCK_ID];
1246  XLogRecPtr recptr;
1247  int nbufs;
1248  int i;
1249 
1251 
1252  /* Collect a batch of blocks. */
1253  nbufs = 0;
1254  while (nbufs < XLR_MAX_BLOCK_ID && blkno < endblk)
1255  {
1256  Buffer buf = ReadBufferExtended(rel, forknum, blkno,
1257  RBM_NORMAL, NULL);
1258 
1260 
1261  /*
1262  * Completely empty pages are not WAL-logged. Writing a WAL record
1263  * would change the LSN, and we don't want that. We want the page
1264  * to stay empty.
1265  */
1266  if (!PageIsNew(BufferGetPage(buf)))
1267  bufpack[nbufs++] = buf;
1268  else
1270  blkno++;
1271  }
1272 
1273  /* Write WAL record for this batch. */
1274  XLogBeginInsert();
1275 
1277  for (i = 0; i < nbufs; i++)
1278  {
1279  XLogRegisterBuffer(i, bufpack[i], flags);
1280  MarkBufferDirty(bufpack[i]);
1281  }
1282 
1283  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1284 
1285  for (i = 0; i < nbufs; i++)
1286  {
1287  PageSetLSN(BufferGetPage(bufpack[i]), recptr);
1288  UnlockReleaseBuffer(bufpack[i]);
1289  }
1290  END_CRIT_SECTION();
1291  }
1292 }
int Buffer
Definition: buf.h:23
void UnlockReleaseBuffer(Buffer buffer)
Definition: bufmgr.c:3954
void MarkBufferDirty(Buffer buffer)
Definition: bufmgr.c:1583
void LockBuffer(Buffer buffer, int mode)
Definition: bufmgr.c:4172
Buffer ReadBufferExtended(Relation reln, ForkNumber forkNum, BlockNumber blockNum, ReadBufferMode mode, BufferAccessStrategy strategy)
Definition: bufmgr.c:759
#define BUFFER_LOCK_EXCLUSIVE
Definition: bufmgr.h:107
@ 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 ( RelFileLocator rlocator,
ForkNumber  forknum,
int  num_pages,
BlockNumber blknos,
char **  pages,
bool  page_std 
)

Definition at line 1129 of file xloginsert.c.

1131 {
1132  int flags;
1133  XLogRecPtr recptr;
1134  int i;
1135  int j;
1136 
1137  flags = REGBUF_FORCE_IMAGE;
1138  if (page_std)
1139  flags |= REGBUF_STANDARD;
1140 
1141  /*
1142  * Iterate over all the pages. They are collected into batches of
1143  * XLR_MAX_BLOCK_ID pages, and a single WAL-record is written for each
1144  * batch.
1145  */
1147 
1148  i = 0;
1149  while (i < num_pages)
1150  {
1151  int batch_start = i;
1152  int nbatch;
1153 
1154  XLogBeginInsert();
1155 
1156  nbatch = 0;
1157  while (nbatch < XLR_MAX_BLOCK_ID && i < num_pages)
1158  {
1159  XLogRegisterBlock(nbatch, rlocator, forknum, blknos[i], pages[i], flags);
1160  i++;
1161  nbatch++;
1162  }
1163 
1164  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI);
1165 
1166  for (j = batch_start; j < i; j++)
1167  {
1168  /*
1169  * The page may be uninitialized. If so, we can't set the LSN
1170  * because that would corrupt the page.
1171  */
1172  if (!PageIsNew(pages[j]))
1173  {
1174  PageSetLSN(pages[j], recptr);
1175  }
1176  }
1177  }
1178 }
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:35
bool XLogInsertAllowed(void)
Definition: xlog.c:5967
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_freeze_execute_prepared(), 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_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(), test_custom_rmgrs_insert_wal_record(), 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 981 of file xloginsert.c.

982 {
984  bool doPageWrites;
985  Page page;
986 
988 
989  page = BufferGetPage(buffer);
990 
991  if (doPageWrites && PageGetLSN(page) <= RedoRecPtr)
992  return true; /* buffer requires backup */
993 
994  return false; /* buffer does not need to be backed up */
995 }
static XLogRecPtr PageGetLSN(Page page)
Definition: bufpage.h:383
void GetFullPageWriteInfo(XLogRecPtr *RedoRecPtr_p, bool *doPageWrites_p)
Definition: xlog.c:6045
static XLogRecPtr RedoRecPtr
Definition: xlog.c:276
static bool doPageWrites
Definition: xlog.c:289

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:953
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1321

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 451 of file xloginsert.c.

452 {
453  XLogRecPtr EndPos;
454 
455  /* XLogBeginInsert() must have been called. */
456  if (!begininsert_called)
457  elog(ERROR, "XLogBeginInsert was not called");
458 
459  /*
460  * The caller can set rmgr bits, XLR_SPECIAL_REL_UPDATE and
461  * XLR_CHECK_CONSISTENCY; the rest are reserved for use by me.
462  */
463  if ((info & ~(XLR_RMGR_INFO_MASK |
465  XLR_CHECK_CONSISTENCY)) != 0)
466  elog(PANIC, "invalid xlog info mask %02X", info);
467 
468  TRACE_POSTGRESQL_WAL_INSERT(rmid, info);
469 
470  /*
471  * In bootstrap mode, we don't actually log anything but XLOG resources;
472  * return a phony record pointer.
473  */
474  if (IsBootstrapProcessingMode() && rmid != RM_XLOG_ID)
475  {
477  EndPos = SizeOfXLogLongPHD; /* start of 1st chkpt record */
478  return EndPos;
479  }
480 
481  do
482  {
484  bool doPageWrites;
485  bool topxid_included = false;
486  XLogRecPtr fpw_lsn;
487  XLogRecData *rdt;
488  int num_fpi = 0;
489 
490  /*
491  * Get values needed to decide whether to do full-page writes. Since
492  * we don't yet have an insertion lock, these could change under us,
493  * but XLogInsertRecord will recheck them once it has a lock.
494  */
496 
497  rdt = XLogRecordAssemble(rmid, info, RedoRecPtr, doPageWrites,
498  &fpw_lsn, &num_fpi, &topxid_included);
499 
500  EndPos = XLogInsertRecord(rdt, fpw_lsn, curinsert_flags, num_fpi,
501  topxid_included);
502  } while (EndPos == InvalidXLogRecPtr);
503 
505 
506  return EndPos;
507 }
#define PANIC
Definition: elog.h:38
#define IsBootstrapProcessingMode()
Definition: miscadmin.h:402
XLogRecPtr XLogInsertRecord(XLogRecData *rdata, XLogRecPtr fpw_lsn, uint8 flags, int num_fpi, bool topxid_included)
Definition: xlog.c:731
#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:525
#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_freeze_execute_prepared(), 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_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(), test_custom_rmgrs_insert_wal_record(), 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,
RelFileLocator rlocator,
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->rlocator = *rlocator;
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(!RelFileLocatorEquals(regbuf_old->rlocator, regbuf->rlocator) ||
335  regbuf_old->forkno != regbuf->forkno ||
336  regbuf_old->block != regbuf->block);
337  }
338  }
339 #endif
340 
341  regbuf->in_use = true;
342 }
#define RelFileLocatorEquals(locator1, locator2)
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
RelFileLocator rlocator
Definition: xloginsert.c:73

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, RelFileLocatorEquals, and registered_buffer::rlocator.

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

◆ XLogRegisterBufData()

void XLogRegisterBufData ( uint8  block_id,
char *  data,
uint32  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  /*
403  * Check against max_rdatas and ensure we do not register more data per
404  * buffer than can be handled by the physical data format; i.e. that
405  * regbuf->rdata_len does not grow beyond what
406  * XLogRecordBlockHeader->data_length can hold.
407  */
408  if (num_rdatas >= max_rdatas ||
409  regbuf->rdata_len + len > UINT16_MAX)
410  elog(ERROR, "too much WAL data");
411 
412  rdata = &rdatas[num_rdatas++];
413 
414  rdata->data = data;
415  rdata->len = len;
416 
417  regbuf->rdata_tail->next = rdata;
418  regbuf->rdata_tail = rdata;
419  regbuf->rdata_len += len;
420 }
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_freeze_execute_prepared(), heap_inplace_update(), heap_insert(), heap_multi_insert(), heap_page_prune(), lazy_vacuum_heap_page(), 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->rlocator, &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(!RelFileLocatorEquals(regbuf_old->rlocator, regbuf->rlocator) ||
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, RelFileLocatorEquals, and registered_buffer::rlocator.

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_freeze_execute_prepared(), 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_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,
uint32  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_freeze_execute_prepared(), 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_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(), test_custom_rmgrs_insert_wal_record(), 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 1019 of file xloginsert.c.

1020 {
1021  XLogRecPtr recptr = InvalidXLogRecPtr;
1022  XLogRecPtr lsn;
1024 
1025  /*
1026  * Ensure no checkpoint can change our view of RedoRecPtr.
1027  */
1029 
1030  /*
1031  * Update RedoRecPtr so that we can make the right decision
1032  */
1034 
1035  /*
1036  * We assume page LSN is first data on *every* page that can be passed to
1037  * XLogInsert, whether it has the standard page layout or not. Since we're
1038  * only holding a share-lock on the page, we must take the buffer header
1039  * lock when we look at the LSN.
1040  */
1041  lsn = BufferGetLSNAtomic(buffer);
1042 
1043  if (lsn <= RedoRecPtr)
1044  {
1045  int flags = 0;
1046  PGAlignedBlock copied_buffer;
1047  char *origdata = (char *) BufferGetBlock(buffer);
1048  RelFileLocator rlocator;
1049  ForkNumber forkno;
1050  BlockNumber blkno;
1051 
1052  /*
1053  * Copy buffer so we don't have to worry about concurrent hint bit or
1054  * lsn updates. We assume pd_lower/upper cannot be changed without an
1055  * exclusive lock, so the contents bkp are not racy.
1056  */
1057  if (buffer_std)
1058  {
1059  /* Assume we can omit data between pd_lower and pd_upper */
1060  Page page = BufferGetPage(buffer);
1061  uint16 lower = ((PageHeader) page)->pd_lower;
1062  uint16 upper = ((PageHeader) page)->pd_upper;
1063 
1064  memcpy(copied_buffer.data, origdata, lower);
1065  memcpy(copied_buffer.data + upper, origdata + upper, BLCKSZ - upper);
1066  }
1067  else
1068  memcpy(copied_buffer.data, origdata, BLCKSZ);
1069 
1070  XLogBeginInsert();
1071 
1072  if (buffer_std)
1073  flags |= REGBUF_STANDARD;
1074 
1075  BufferGetTag(buffer, &rlocator, &forkno, &blkno);
1076  XLogRegisterBlock(0, &rlocator, forkno, blkno, copied_buffer.data, flags);
1077 
1078  recptr = XLogInsert(RM_XLOG_ID, XLOG_FPI_FOR_HINT);
1079  }
1080 
1081  return recptr;
1082 }
XLogRecPtr BufferGetLSNAtomic(Buffer buffer)
Definition: bufmgr.c:3012
static Block BufferGetBlock(Buffer buffer)
Definition: bufmgr.h:244
PageHeaderData * PageHeader
Definition: bufpage.h:170
unsigned short uint16
Definition: c.h:441
Datum lower(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:48
Datum upper(PG_FUNCTION_ARGS)
Definition: oracle_compat.c:79
#define XLOG_FPI_FOR_HINT
Definition: pg_control.h:77
#define DELAY_CHKPT_START
Definition: proc.h:119
PGPROC * MyProc
Definition: proc.c:68
int delayChkptFlags
Definition: proc.h:231
char data[BLCKSZ]
Definition: c.h:1079
XLogRecPtr GetRedoRecPtr(void)
Definition: xlog.c:6015

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